Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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))
    {
        try
        {
            connection.Open();
            Console.WriteLine("Connection.State: {0}", connection.State);

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

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.