.NET Framework Class Library  

OdbcConnection.Dispose Method (Boolean)

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

Releases the unmanaged and, optionally, the managed resources used by the OdbcConnection.

[Visual Basic]
Overrides Overloads Protected Sub Dispose( _
   ByVal disposing As Boolean _
)
[C#]
protected override void Dispose(
   bool disposing
);
[C++]
protected: void Dispose(
   bool disposing
);
[JScript]
protected override function Dispose(
   disposing : Boolean
);

Parameters

disposing
true to release both managed and unmanaged resources; false to release only unmanaged resources.

Remarks

This method is called by the public Dispose() method and the Finalize method. Dispose() invokes the protected Dispose(Boolean) method with the disposing parameter set to true. Finalize invokes Dispose with disposing set to false.

When the disposing parameter is true, the method releases all resources held by any managed objects that this OdbcCommand references. It does this by invoking the Dispose() method of each referenced object.

For more information about Dispose and Finalize, see Cleaning Up Unmanaged Resources and Overriding the Finalize Method.

Example

[Visual Basic, C#, C++] The following example creates an OdbcConnection and then disposes of it.

[Visual Basic] 
Public Sub OdbcConnectionHereAndGone()
    Dim myConnection As New _
       OdbcConnection("DRIVER={SQL Server};SERVER=MyServer;" & _
                      "Trusted_connection=yes;DATABASE=northwind;")
    myConnection.Open()
    'Calling Dispose also calls OdbcConnection.Close.
    myConnection.Dispose()
End Sub

[C#] 
public void OdbcConnectionHereAndGone() 
{
   OdbcConnection myConnection = new 
        OdbcConnection("DRIVER={SQL Server};SERVER=MyServer;" + 
                       "Trusted_connection=yes;DATABASE=northwind;");
   myConnection.Open();
   //Calling Dispose also calls OdbcConnection.Close.
   myConnection.Dispose();
}

[C++] 
public:
    void OdbcConnectionHereAndGone()
    {
        OdbcConnection* myConnection = new OdbcConnection(S"DRIVER= {SQL Server};SERVER=MyServer; Trusted_connection=yes;DATABASE=northwind;");
        myConnection->Open();
        //Calling Dispose also calls OdbcConnection::Close.
        myConnection->Dispose();
    };

[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 | OdbcConnection.Dispose Overload List