This documentation is archived and is not being maintained.

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

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.