1. Connection Pooling:
A Connection Pool is a container of open and reusable connections. A Connection Pool is created the first time a request for a connection to the database comes in with a unique connection string. A Connection Pool is released from the memory when the last connection to the database is closed.
A Connection Pool is a container of open and reusable connections. A Connection Pool is released from the memory when the last connection to the database is closed. The basic advantage of using Connection Pooling is an improvement of performance and scalability while the main disadvantage is that one or more database connections, even if they are currently not being used, are kept open. The Data Providers in ADO.NET have Connection Pooling turned on by default; if you need to turn it off, specify Pooling = false in the connection string being used.
Example:
Listing 1 // A new pool is created.
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString =
"Server=localhost;Database=test;User ID=joydip;Password=joydip;Trusted_Connection=False";
sqlConnection.Open();
Listing 2 // A new pool is created as the connection strings differ.
SqlConnection conn = new SqlConnection();
sqlConnection.ConnectionString =
"Server=localhost;Database=test;User ID=test;Password=test;Trusted_Connection=False";
sqlConnection.Open();
Listing 3 // The connection string is the same as in Listing 1 so no new pool is created.
SqlConnection conn = new SqlConnection();
sqlConnection.ConnectionString =
"Server=localhost;Database=test;User ID=joydip;Password=joydip;Trusted_Connection=False";
sqlConnection.Open();
Multiple pools can exist in the same application domain at the same point in time, but Connection Pools cannot be shared across application domains. Note that one pool is created per unique connection string. A Connection Pool is created the first time a request for a connection to the database comes in with a unique connection string. Note that if another request comes in with a different connection string for the database, another Connection Pool would be created. Hence, we have one Connection Pool per connection string and not per database.
Connection Pooling is controlled and the parameters passed to a connection string that basically comprises the following:
· Connect Timeout
· Min Pool Size
· Max Pool Size
· Pooling
2. Why C# for asp.net
It is a purely object oriented language, which makes it better to code in, when you get the hang of it. After having learned C# and especially the philosophy behind its object oriented approach, I have found it much easier and faster to code in, and the software less prone to error.
Advantages:
· C# supports two things which is not supported by VB.NET
1. Operator Overloading
2. Pointer
· XML documentation generated from source code comments.
· Explicit interface implementation, where an interface which is already implemented in a base class can be re implemented separately in a derived class.
3. Dataset and Recordset
Dataset:
Datasets store a copy of data from the database tables. However, Datasets can not directly retrieve data from Databases. DataAdapters are used to link Databases with DataSets.
· Dataset is a data structure which represents the complete table data at same time.
· Dataset is just a data store and manipulation is done through Data Adapters in .NET.
Recordset :
· Recordset provides data one row at a time.
· Recordset has the logic to update and manipulate data.
Dataset vs Recordset
1. Collection of tables VS single table.
2. No need for join to use diff. DB tables VS need join.
3. Dataset is created in the client side so that there is no need of any connection at the time of working on the dataset which makes the accessing faster VS Recordset is created in the server side so that a connection should be established every time we work on recordset.
DataSet is always better than the RecordSet
4. Interface
An interface contains only the signatures of methods, delegates or events. The implementation of the methods is done in the class that implements the interface.
An interface is a group of related methods with empty bodies. A bicycle's behavior, if specified as an interface, might appear as follows: Interface Bicycle {
Void changeCadence(int newValue); // wheel revolutions per minute
Void changeGear(int newValue);
Void speedUp(int increment);
Void applyBrakes(int decrement);
}
To implement this interface, the name of your class would change (to a particular brand of bicycle, for example, such as ACMEBicycle), and you'd use the implements keyword in the class declaration:
class ACMEBicycle implements Bicycle {
// remainder of this class implemented as before
}
Implementing an interface allows a class to become more formal about the behavior it promises to provide. Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler. If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile.
5. Interface VS Inheritance
The difference between inheritance and interfaces is that inheritance is intended to allow you to share an implementation, while an interface specifies that you must implement something, but supply your own logic. Many people liken an interface to a "contract". To use an interface you must expose certain functionality, but the implementation of that functionality is up to you.
Make sense? No? Let's look at the IComparable interface in .NET:
Public Class test
Implements IComparable
Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
End Function
End Class
When you implement IComparable, Visual Studio automatically puts the function signature CompareTo in for you. By implementing IComparable, you have to follow the contract that specifies that you must have a CompareTo function. To do otherwise would cause a compiler error.
Note that there is no code in this function. You've created a custom class test and you want to compare it to another object. The author of IComparable has no idea what criteria needs to be met for the objects to be considered equal, so they leave it to you to fill out.
In contrast, if you were to inherit a class, like in this example:
Public Class test
Inherits Inheritable
Sub New()
Me.DoStuff()
End Sub
End Class
Public Class Inheritable
Public Function DoStuff() As Boolean
'I'm doing stuff
Return True
End Function
End Class
You'll notice that even though DoStuff() does not show up in the test class when inherited, it is still accessible by the test class. The code inside the parent class (inheritable) will execute the same for any class that inherits it.
So basically, if you created a class you intended other developers to inherit, but every single function/sub was marked as "MustOverride", then you've really created an interface!
6. Abstract Class
Abstract class is a class that can not be instantiated, it exists extensively for inheritance and it must be inherited. There are scenarios in which it is useful to define classes that is not intended to instantiate; because such classes normally are used as base-classes in inheritance hierarchies, we call such classes abstract classes.
Abstract classes cannot be used to instantiate objects; because abstract classes are incomplete, it may contain only definition of the properties or methods and derived classes that inherit this implements it's properties or methods.
Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods. Let's look at an example of an abstract class, and an abstract method.
public abstract Animal
{
public void eat(Food food)
{
// do something with food....
}
public void sleep(int hours)
{
try
{
// 1000 milliseconds * 60 seconds * 60 minutes * hours
Thread.sleep ( 1000 * 60 * 60 * hours);
}
catch (InterruptedException ie) { /* ignore */ }
}
public abstract void makeNoise();
}
Note that the abstract keyword is used to denote both an abstract method, and an abstract class. Now, any animal that wants to be instantiated (like a dog or cow) must implement the makeNoise method - otherwise it is impossible to create an instance of that class. Let's look at a Dog and Cow subclass that extends the Animal class. public Dog extends Animal
{
public void makeNoise() { System.out.println ("Bark! Bark!"); }
}
public Cow extends Animal
{
public void makeNoise() { System.out.println ("Moo! Moo!"); }
}
Now you may be wondering why not declare an abstract class as an interface, and have the Dog and Cow implement the interface. Sure you could - but you'd also need to implement the eat and sleep methods. By using abstract classes, you can inherit the implementation of other (non-abstract) methods. You can't do that with interfaces - an interface cannot provide any method implementations.
7. Delegates
A delegate can be defined as a type safe function pointer. You use delegates to call the methods of other objects. They are object-oriented function pointers since they allow a function to be invoked indirectly by using a reference to the function.
It wraps up the memory address of a function in your code. The system makes use of delegate whenever you create or use an event in code. When an event is called, the framework examines the delegate behind the event and then calls the function that the delegate points to.
However, unlike function pointers, the delegates in .NET are reference types, based on the class System.Delegate. In addition, delegates in .net can reference both shared and instance methods.
8. Resource Files
A resource file is a XML file that contains the strings that we want to
a. Translate into different languages.
b. Can be updated dynamically so that user themselves can modify values in resource files once the application is deployed on the server
without re-compiling the entire application itself.
The resource file contains key / value pairs.
Each pair is an individual resource.
Key names are not case sensitive.
There are two types of resources
1. Local Resources
2. Global Resources
9. Global.asax
The global.asax file is used to add application level logic & processing. Note that the global.asax does not handle any UI related processing, nor does it process individual page level requests. It basically controls the following events...
Application_Start
Application_End
Session_Start
Session_End
Note that in Visual Studio 2003 automatically creates this file for every web application, but in Visual Studio 2005, this file has to be added to the web project specifically.
Code in the global.asax is compiled when the web appication is built for the first time. The application level code and variables may be declared in Application_Start. Similarly, session level code & variables may be declared in Session_Start event. Application level events are for the entire application, and may be used for any user, while Session level events are user specific for a length of a session.
10. Response.Redirect VS Server. Transfer
Response. Redirect simply sends a message down to the (HTTP 302) browser.
Server.Transfer happens without the browser knowing anything, the browser request a page, but the server returns the content of another.
Response.Redirect will send you to a new page, update the address bar and add it to the Browser History. On your browser you can click back.
Server.Transfer does not change the address bar, you cannot hit back.
I'll use Server.Transfer when I don't want the user to see where I am going. sometimes on a "loading" type page.
Otherwise I'll always use Response.Redirect
Response.Redirect redirects page to another page after first page arrives to client. So client knows the redirection.
Server.Transfer quits current execution of the page. Client does not know the redirection. It allows you to transfer the query string and form variables.
11. Service-oriented architecture (SOA)
A service-oriented architecture is essentially a collection of services. These services communicate with each other. The communication can involve either simple data passing or it could involve two or more services coordinating some activity. Some means of connecting services to each other is needed.
12. Namespace
Namespaces allow to group entities like classes, objects and functions under a name. System is the basic namespace used by every .NET code. If we can explore the System namespace little bit, we can see it has lot of namespace user the system namespace. For example, System.Io, System.Net, System.Collections, System.Threading, etc.
13. ILDASM
It is very easy to get the source code out of the .NET assemblies. The process is known as De-Compilation. Microsoft is providing a native de-compiler known as ILDASM (IL Disassembler). This ILDASM can convert the entire assembly to the understandable instructions and then it is not a far reach to get the source codes back.
14. CLR (Common Language Runtime)
It forms the heart of the .NET framework. All Languages have runtime and it is the responsibility of the runtime to take care of code execution of the program. JAVA has JVM similarly .NET has CLR.Following are the responsibilities of CLR
· Garbage Collection
· Code Access Security
· Code Verification
· IL-To-Native-Translators and optimizer’s
15. CTS (Common Type System)
In order that two language communicate smoothly CLR has CTS (Common Type System).Example in VB you have “Integer” and in C++ you have “long” these data types are not compatible so the interfacing between them is very complicated. In order that these two different languages communicate Microsoft introduced Common Type System. So “Integer” data type in VB6 and “int” data type in C++ will convert it to System.int32, which is data type of CTS. CLS, which is covered in the coming question, is subset of CTS.
16. Garbage Collection
Garbage collection is a CLR feature, which automatically manages memory. Programmers forget to release the objects while coding ... Laziness (Remember in VB6 where one of the good practices is to set object to nothing). CLR automatically releases objects when they are no longer in use and referenced. CLR runs on non-deterministic to see the unused objects and cleans them. One side effect of this non-deterministic feature is that we cannot assume an object is destroyed when it goes out of the scope of a function. We should avoid using destructors because before GC destroys the object it first executes destructor in that case it will have to wait for code to release the unmanaged resource. This results in additional delays in GC.
17. .NET Assembly
An assembly is the primary building block of a .NET application and can take the form of a dynamic link library (DLL) or executable file (EXE). An assembly is a collection of functionality that is built, versioned, and deployed as a single implementation unit.
What does an assembly contain?
A .NET assembly may contain the following elements:
1. Assembly Manifest – Metadata that describes the assembly and its contents (see below)
2. Source Code – Compiled into Microsoft intermediate language (MSIL)
3. Type Metadata – Defines all types, their properties and methods, and most importantly, public types exported from this assembly
4. Resources – Icons, images, text strings and other resources
The assembly manifest is required; the other elements are optional.
What is an assembly manifest?
An assembly manifest is metadata inside an assembly that describes everything there is to know about the assembly and its contents. The manifest contains:
Strong Name – The assembly's name, version, culture, optional processor architecture, and public key (for shared assemblies)
File Contents – Name and hash of all files in the assembly
Type List - Types defined in the assembly, including public types that are exported from the assembly
Resource List – Icons, images, text strings and other resources contained in the assembly
Dependencies – Compile-time dependencies on other assemblies Security – Permissions required for the assembly to run properly
18. What is the difference between an assembly and a namespace?
Namespaces are logical, whereas assemblies are physical.
A namespace is a logical naming scheme to group related types. Namespaces can contain other namespaces to form a hierarchy. The "fully qualified name" of a type is its namespace followed by its type name, separated by a period (for example, System.Windows.Forms.Button). Type names must be unique within a namespace, but the same type name can be used in different namespaces.
An assembly is a physical deployment scheme to group related types. An assembly can contain one or many namespaces. A namespace can exist in one or many assemblies.
19. ViewState
Viewstate is a built-in structure for automatically retaining values amongst the multiple requests for the same page. The viewstate is internally maintained as a hidden field on the page but is hashed, providing greater security than developer-implemented hidden fields do.
20. Caching
Caching enables you to store the expensive data into Cache object and later retrieve it without doing expensive operations. Caching is a technique of persisting the data
in memory for immediate access to requesting program calls. Many in the developer community consider caching as one of the features available to improve performance of Web applications.
Why Caching?
Consider a page that has list of Employee name, contact numbers and mail-Ids of existing employees of a company on an intranet accessible by all employees. This is very useful information that is available throughout the company and could also be one of the most accessed pages. The functionality of adding, updating or deleting is usually less intensive compared to more transaction-based systems like Purchase ordering, Voucher creation etc. Now in a normal scenario the process of querying database
for each request is not cost-effective in terms of server
resources, hence is lot better to cache or persist the data to avoid this costly loss of resources.
21. Cross Page posting
Cross Page posting or cross page postback is used to submit a form on one page (say default.aspx) and retrieve values of controls of this page on another page (say Default2.aspx).
22. What does virtual keyword mean?
They signify that method and property can be overridden.
23. Private keyword
Keyword used to disallow other classes access the fields and methods within a class. The private keyword is used before a field or method that you want to be available only within the class. In Processing, all fields and methods are public unless otherwise specified by the private keyword.
24. Properties
Properties are like smart fields. A property generally has a private data member accompanied by accessor functions and is accessed syntactically as a field of a class.
25. Web.config
Web.config acts as a central location for storing the information to be accessed by web pages. This information could be a Connection String stored at a centralized location so that it can be accessed in a data-driven page. If the connection string changes its just a matter of changing it at one place.
web.config:
Contains a key-value pair.
web.config
C#
string strConnection;
strConnection = ConfigurationSettings.AppSettings["ConnectionString1"];
Response.Write(strConnection);
26. N-Tier Architecture
In software engineering, multi-tier architecture (often referred to as n-tier architecture) is a client-server architecture in which, the presentation, the application processing and the data management are logically separate processes. For example, an application that uses middleware to service data requests between a user and a database employs multi-tier architecture. The most widespread use of "multi-tier architecture" refers to three-tier architecture.
It's debatable what counts as "tiers," but in my opinion it needs to at least cross the process boundary. Or else it's called layers. But, it does not need to be in physically different machines. Although I don't recommend it, you can host logical tier and database on the same box.

27. What’s the difference between "Layers" and "Tiers"?
Logical layers are merely a way of organizing your code. Typical layers include Presentation, Business and Data – the same as the traditional 3-tier model. But when we’re talking about layers, we’re only talking about logical organization of code. In no way is it implied that these layers might run on different computers or in different processes on a single computer or even in a single process on a single computer. All we are doing is discussing a way of organizing a code into a set of layers defined by specific function.
Physical tiers however, are only about where the code runs. Specifically, tiers are places where layers are deployed and where layers run. In other words, tiers are the physical deployment of layers.
Thursday, March 4, 2010
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment