Connection Pooling for the OLE DB .NET Data Provider
This is preliminary documentation and subject to change.
Send feedback on this topic.
The OLE DB .NET Data Provider automatically pools connections using OLE DB session pooling. Connection string arguments can be used to enable or disable OLE DB services including pooling. For example, the following connection string will disable OLE DB session pooling and automatic transaction enlistment.
Provider=SQLOLEDB;OLE DB Services=-4;Data Source=localhost;Integrated Security=SSPI;
For more information about OLE DB session pooling or resource pooling, as well as disabling pooling by overriding OLE DB provider service defaults, see the OLE DB Programmer's Reference in the MSDN library located at http://msdn.microsoft.com/library.
CAUTION You must always close the Connection when you are finished using it. This can be done using either the Close or Dispose methods of the Connection object. Connections that are not explicitly closed are not added or returned to the pool.
Connection Pooling for the SQL Server .NET Data Provider
This is preliminary documentation and subject to change.
Send feedback on this topic.
The SQL Server .NET Data Provider relies on Windows 2000 Component Services to provide connection pooling using an implicit pooling model by default. The SqlConnection object also has several connection string modifiers that you can set to control implicit pooling behavior.
Pool Creation and Assignment
Each connection pool is associated with one distinct connection string, using an exact matching algorithm. If no exact match is found, a new pool is created.
In the following example, three new SqlConnection objects are created, but only two connection pools are required to manage them. Note that the first and second connection strings differ by Initial Catalog.
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Integrated Security=SSPI;Initial Catalog=northwind";
conn.Open();
// Pool A is created.
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Integrated Security=SSPI;Initial Catalog=pubs";
conn.Open();
// Pool B is created because connection strings differ.
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Integrated Security=SSPI;Initial Catalog=northwind";
conn.Open();
// Uses pool A.
Once created, connection pools are not destroyed until the active process ends. Maintenance of inactive or empty pools involves minimal system overhead.
Connection Addition
A connection pool is created for each unique connection string. When a pool is created, multiple connection objects are created and added to the pool so that the minimum pool size requirement is satisfied. Connections are added to the pool as needed, up to the maximum pool size.
When a SqlConnection object is requested, it is obtained from the pool if a usable connection is available. To be usable, the connection must be currently unused, have a matching transaction context or not be associated with any transaction context, and have a valid link to the server.
When the maximum pool size is reached, the request is queued. The object pooler satisfies these requests by reallocating connections as they are released back into the pool. If the time-out period (determined by the Connect Timeout connection string property) elapses before a connection object can be obtained, an error occurs.
CAUTION You must always close the Connection when you are finished using it. This can be done using either the Close or Dispose methods of the Connection object. Connections that are not explicitly