"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Saturday, September 10, 2011

connection pool in asp.net


Connecting to the database is resource intensive and a relatively slow operation in an application but the most crucial of them all. 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. Connection Pooling gives you an idle, open, reusable connection instead of opening a new one every time a connection request to the database is made. When the connection is closed or disposed, it is returned to the pool and remains idle until a request for a new connection comes in. If we use Connection Pooling efficiently, opening and closing of connections to the database becomes less resource expensive. This article discusses what Connection Pooling is all about and how Connection Pooling can be used efficiently to boost the performance and scalability of applications.
Connection pooling is enabled for both OleDb and SqlClient connections by default.
To take advantage of connection pooling, you must be careful to do two things in your ASP.NET pages. First, you must be careful to use the same exact connection string whenever you open a database connection. Only those connections opened with the same connection string can be placed in the same connection pool. For this reason you should place your connection string in the web.config file and retrieve it from this file whenever you need to open a connection
To take advantage of connection pooling in your ASP.NET pages, you also must be careful to explicitly close whatever connection you open as quickly as possible. If you do not explicitly close a connection with the Close() method, the connection is never added back to the connection pool.
connection pooling options that you can add to the SQL Server connection string:
  • Connection Lifetime— destroys a connection after a certain number of seconds. The default value is 0, which indicates that connections should never be destroyed.
  • Connection Reset— indicates whether connections should be reset when they are returned to the pool. The default value is true.
  • Enlist— indicates whether a connection should be automatically enlisted in the current transaction context. The default value is true.
  • Max Pool Size— the maximum number of connections allowed in a single connection pool. The default value is 100.
  • Min Pool Size— the minimum number of connections allowed in a single connection pool. The default value is 0.
  • Pooling— determines whether connection pooling is enabled or disabled. The default value is true.
Sample
C#
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string connectionString = @"Min Pool Size=10;•    Connection Lifetime=0;•    Max Pool Size=2000;Pooling=true;Data Source=.\SQLExpress;Integrated Security=True;AttachDbFileName=|DataDirectory|MyDatabase.mdf;User Instance=True";
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("SELECT * FROM master..sysprocesses WHERE hostname<>''", con);
            using (con)
            {
                con.Open();
                grdStats.DataSource = cmd.ExecuteReader();
                grdStats.DataBind();
            }
        }
    }

Html
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Show User Connections</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h1>User Connections</h1>

    <asp:GridView
        id="grdStats"
        Runat="server" />

    </div>
    </form>
</body>
</html>


 Stay Tune...
Have a nice day... 'N happy Coding :)

Monday, September 5, 2011

How to pass value from one form to another [Windows Application]

On form1
  •  
  • namespace WindowsFormsApplication1
  • {
  • public partial class Form1 : Form
  • {
  • Form2 ob;
  • public Form1()
  • {
  • InitializeComponent();
  • }
  •  
  • private void button1_Click(object sender, EventArgs e)
  • {
  • string s;
  • s = comboBox.SelectedIndex;
  • ob = new Form2(s);
  • ob.Show();
  • }
  • }
  • }
On form2
  • namespace WindowsFormsApplication1
  • {
  • public partial class Form2 : Form
  • {
  • string ss;
  • public Form2(string s)
  • {
  • InitializeComponent();
  • ss = s;
  • comboBox.SelectedIndex = ss;
  • }
  • }
  • }
Hope u got that Now !!!

Have a nice day... 'N happy Coding :)

Thursday, September 1, 2011

HTTP Request Lifecycle Events in IIS Pipeline that every ASP.NET Developer Should Know

The life cycle of an ASP.NET application starts with a request sent by a browser to the Web server like IIS. If you are an ASP.NET developer who creates modules and handlers, it’s important to understand the the HTTP Request Lifecycle in IIS. This article will give you an overview of the order of events fired only in the 'Request Life Cycle' in IIS pipeline.
Note: In IIS 6.0, there are two request processing pipelines – one for native-code ISAPI filters and the other for managed applications like ASP.NET. However in IIS 7.0, there is one unified request processing pipeline for all requests. The ASP.NET runtime is integrated with the Web server. Also note that if IIS 7 is configured to work in Classic mode instead of Integrated mode, then it behaves like IIS 6.
When a request is made to IIS, it is queued in the application pool of the application. An application pool is a group of one or more URLs that are served by a worker process. The worker process(w3wp.exe) is responsible to forward the request to the application.
The request is processed by the HttpApplication pipeline and events are fired in the following order:
BeginRequest - The BeginRequest event signals the creation of any given new request. This event is always raised and is always the first event to occur during the processing of a request.
AuthenticateRequest - The AuthenticateRequest event signals that the configured authentication mechanism has authenticated the current request. Subscribing to the AuthenticateRequest event ensures that the request will be authenticated before processing the attached module or event handle.
PostAuthenticateRequest - The PostAuthenticateRequest event is raised after the AuthenticateRequest event has occurred. All the information available is accessible in the HttpContext’s User property.
AuthorizeRequest - The AuthorizeRequest event signals that ASP.NET has authorized the current request. You can subscribe to the AuthorizeRequest event to perform custom authorization.
PostAuthorizeRequest - Occurs when the user for the current request has been authorized.
ResolveRequestCache - Occurs when ASP.NET finishes an authorization event to let the caching modules serve requests from the cache, bypassing execution of the event handler and calling any EndRequest handlers.
PostResolveRequestCache – Reaching this event means the request can’t be served from the cache, and thus a HTTP handler is created here. A Page class gets created if an aspx page is requested.
MapRequestHandler - The MapRequestHandler event is used by the ASP.NET infrastructure to determine the request handler for the current request based on the file-name extension of the requested resource.
PostMapRequestHandler - Occurs when ASP.NET has mapped the current request to the appropriate HTTP handler
AcquireRequestState - Occurs when ASP.NET acquires the current state (for example, session state) that is associated with the current request. A valid session ID must exist.
PostAcquireRequestState - Occurs when the state information (for example, session state or application state) that is associated with the current request has been obtained.
PreRequestHandlerExecute - Occurs just before ASP.NET starts executing an event handler
ExecuteRequestHandler – Occurs when handler generates output. This is the only event not exposed by the HTTPApplication class.
PostRequestHandlerExecute - Occurs when the ASP.NET event handler has finished generating the output
ReleaseRequestState - Occurs after ASP.NET finishes executing all request event handlers. This event signal ASP.NET state modules to save the current request state.
PostReleaseRequestState - Occurs when ASP.NET has completed executing all request event handlers and the request state data has been persisted.
UpdateRequestCache - Occurs when ASP.NET finishes executing an event handler in order to let caching modules store responses that will be reused to serve identical requests from the cache.
PostUpdateRequestCache - When thePostUpdateRequestCache is raised, ASP.NET has completed processing code and the content of the cache is finalized.
LogRequest - Occurs just before ASP.NET performs any logging for the current request. The LogRequest event is raised even if an error occurs. You can provide an event handler for the LogRequest event to provide custom logging for the request.
PostLogRequest - Occurs when request has been logged
EndRequest - Occurs as the last event in the HTTP pipeline chain of execution when ASP.NET responds to a request. In this event, you can compress or encrypt the response.
PreSendRequestHeaders – Fired after EndRequest if buffering is turned on (by default). Occurs just before ASP.NET sends HTTP headers to the client.
PreSendRequestContent - Occurs just before ASP.NET sends content to the client.

 Countresy :http://www.dotnetcurry.com/ShowArticle.aspx?ID=747
Have a nice day... 'N happy Coding :)