System.Data.OleDb Namespace OleDbConnection Class
Indicates that the OleDbConnection object pooling can be cleared when the last underlying OLE DB Provider is released.
[ VB ]
Public Shared Sub ReleaseObjectPool ( )
[ C# ]
public static void ReleaseObjectPool ( );
[ C++ ]
public: static void ReleaseObjectPool ( );
[ C++ ]
public static function ReleaseObjectPool ( );
The object pool is cached whenever one of the underlying OLE DB providers is created. ReleaseObjectPool can be called to free resources that would otherwise be reserved for pooled OleDbConnection objects.
You might want to call this method when the user is done using any OleDbConnection object, or if, for example, the connection object will not be used again for a period of time longer than OLE DB services would normally keep pooled connections alive.
The following must occur before the pool is finally disposed:
- Call Close to return the connection object to the pool.
- Allow each connection object to time out of the pool.
- Call ReleaseObjectPool.
- Invoke garbage collection.
Note that calling the method alone does not actually release the active connections that exist in the pool. Conversely, if you call Close on all active connections, and invoke garbage collection but do not call ReleaseObjectPool, the resources reserved for the pooled objects will remain available.
The following example initializes an OleDbConnection, opens it, displays some of its properties, closes the connection and releases the object pool to conserve resources.
protected void Page_Load ( Object Src, EventArgs e ) {
// specify the data source
OleDbConnection myConn = new OleDbConnection (
"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" +
Server.MapPath ( "~/app_data/pubs.mdb" ) );
// open the data connection
myConn.Open ( );
// retrieve properties of the connection object
...
// close the data connection
myConn.Close ( );
OleDbConnection.ReleaseObjectPool ( );
}
OleDbConnection Members