This documentation is archived and is not being maintained.

OdbcConnection.ReleaseObjectPool Method

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Indicates that the ODBC Driver Manager environment handle can be released when the last underlying connection is released.

[Visual Basic]
Public Shared Sub ReleaseObjectPool()
[C#]
public static void ReleaseObjectPool();
[C++]
public: static void ReleaseObjectPool();
[JScript]
public static function ReleaseObjectPool();

Remarks

ReleaseObjectPool can be called to release the ODBC environment handle. You might want to call this method if, for example, the connection object will not be used again. When all connections in the environment are closed, the environment can be disposed. Note that calling the method alone does not actually release the active connections that exist in the environment.

The following must occur before the environment is finally disposed:

  1. Call Close to release the OdbcConnection object from the environment.
  2. Allow each connection object to time out.
  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 environment will remain available.

After an environment handle is released, a request for a new OdbcConnection creates a new environment.

Example

[Visual Basic, C#, C++] The following example creates an OdbcConnection, opens it, displays some of its properties, closes the connection and releases the object pool to conserve resources.

[Visual Basic] 
Public Sub CreateOdbcConnection(myConnString As String)
    Dim myConnection As New OdbcConnection(myConnString)
    myConnection.Open()
    MessageBox.Show("ServerVersion: " + myConnection.ServerVersion _
       + ControlChars.Cr + "State: " + myConnection.State.ToString())
    myConnection.Close()
    OdbcConnection.ReleaseObjectPool()
End Sub

[C#] 
public void CreateOdbcConnection(string myConnString) 
{
   OdbcConnection myConnection = new OdbcConnection(myConnString);
   myConnection.Open();
   MessageBox.Show("ServerVersion: " + myConnection.ServerVersion
      + "\nState: " + myConnection.State.ToString());
   myConnection.Close();
   OdbcConnection.ReleaseObjectPool();
}

[C++] 
public:
    void CreateOdbcConnection(String* myConnString)
    {
        OdbcConnection* myConnection = new OdbcConnection(myConnString);
        myConnection->Open();
        MessageBox::Show(String::Concat(S"ServerVersion: ", myConnection->ServerVersion,
            S"\nState: ", __box(myConnection->State)));
        myConnection->Close();
        OdbcConnection::ReleaseObjectPool();
    };

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

OdbcConnection Class | OdbcConnection Members | System.Data.Odbc Namespace

Show: