Export (0) Print
Expand All

OleDbConnection.Dispose Method

.NET Framework 1.1

Releases the resources used by the OleDbConnection.

Overload List

Releases the unmanaged resources used by the OleDbConnection and optionally releases the managed resources.

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

Inherited from Component.

[Visual Basic] Overloads Public Overridable Sub Dispose() Implements IDisposable.Dispose
[C#] public virtual void Dispose();
[C++] public: virtual void Dispose();
[JScript] public function Dispose();

Example

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

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Dispose. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Public Sub OleDbConnectionHereAndGone()
    Dim myConnection As New _
       OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;" & _ 
      "Integrated Security=SSPI;")
    myConnection.Open()
    'Calling Dispose also calls OleDbConnection.Close.
    myConnection.Dispose()
End Sub

[C#] 
public void OleDbConnectionHereAndGone() 
{
   OleDbConnection myConnection = new 
        OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;" + 
       "Integrated Security=SSPI;");
   myConnection.Open();
   //Calling Dispose also calls OleDbConnection.Close.
   myConnection.Dispose();
}

[C++] 
public:
void OleDbConnectionHereAndGone() 
{
   OleDbConnection* myConnection = new 
       OleDbConnection(S"Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;"  
       S"Integrated Security=SSPI;");
   myConnection->Open();
   //Calling Dispose also calls OleDbConnection.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.

See Also

OleDbConnection Class | OleDbConnection Members | System.Data.OleDb Namespace

Show:
© 2015 Microsoft