DB2Connection.Dispose (Boolean) Method

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

Namespace:
IBM.Data.DB2
Assembly:
IBM.Data.DB2 (in IBM.Data.DB2.dll)

Syntax


[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

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 DB2®Command references. It does this by invoking the Dispose() method of each referenced object.

Notes to inheritors: Dispose can be called multiple times by other objects. When overriding Dispose(Boolean), be careful not to reference objects that have been previously disposed of in an earlier call to Dispose. For more information about how to implement Dispose(Boolean), see "Implementing a Dispose Method" in the Microsoft(R) .NET Framework SDK documentation.

Calling Dispose on a DB2Connection object is different from calling Close. For example, Dispose clears the connection string while Close does not. For more information about Dispose and Finalize, see "Cleaning Up Unmanaged Resources," and "Overriding the Finalize Method," in the .NET Framework SDK documentation.

Example

[Visual Basic, C#] The following example creates a DB2Connection and then disposes of it.

[Visual Basic]
Public Sub DB2ConnectionHereAndGone()
    Dim myConnection As New DB2Connection()
    myConnection.Open()
    'Calling Dispose also calls DB2Connection.Close.
    myConnection.Dispose()
End Sub

[C#]
public void DB2ConnectionHereAndGone()
{
   DB2Connection myConnection = new DB2Connection();
   myConnection.Open();
   //Calling Dispose also calls DB2Connection.Close.
   myConnection.Dispose();
}