OleDbConnection.ReleaseObjectPool Method ()


Indicates that the OleDbConnection object pool can be released when the last underlying connection is released.

Namespace:   System.Data.OleDb
Assembly:  System.Data (in System.Data.dll)

public static void ReleaseObjectPool()

ReleaseObjectPool can be called to free resources that would otherwise be reserved for pooled OleDbConnection objects. You might want to call this method if, for example, the connection object will not be used again for the amount of time that OLE DB services ordinarily keeps pooled connections active. Note that calling the method alone does not actually release the active connections that exist in the pool.

The following must occur before the pool is finally disposed:

  1. Call Close to return the connection object to the pool.

  2. Allow each connection object to time out of the pool.

  3. Call ReleaseObjectPool.

  4. Invoke garbage collection.

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 creates an OleDbConnection, opens it, displays some of its properties, closes the connection, and releases the object pool to conserve resources.

static void OpenConnection(string connectionString)
    using (OleDbConnection connection = new OleDbConnection(connectionString))
            Console.WriteLine("Connection.State: {0}", connection.State);

            Console.WriteLine("Connection.State: {0}", connection.State);
        catch (Exception ex)
        // The connection is automatically closed when the
        // code exits the using block.

.NET Framework
Available since 1.1
Return to top