This documentation is archived and is not being maintained.

OracleConnection.Close Method

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

Closes the connection to the database. This is the preferred method of closing any open connection.

[Visual Basic]
Public Overridable Sub Close() Implements IDbConnection.Close
public virtual void Close();
public: virtual void Close();
public function Close();




The Close method rolls back any pending transactions. It then releases the connection to the connection pool, or closes the connection if connection pooling is disabled.

An application can call Close more than one time without generating an exception.

Note   When you use the .NET Framework Data Provider for Oracle, you do not need to enable connection pooling because the provider manages this automatically.
CAUTION   Do not call Close or Dispose on a Connection, a DataReader, or any other managed object in the Finalize method of your class. In a finalizer, you should only release unmanaged resources that your class owns directly. If your class does not own any unmanaged resources, do not include a Finalize method in your class definition. For more information, see Programming for Garbage Collection.


[Visual Basic, C#, C++] The following example creates an OracleConnection, opens it, displays some of its properties, then closes the connection.

[Visual Basic] 
Public Sub CreateOracleConnection(myConnString As String)
    Dim myConnection As New OracleConnection(myConnString)
    MessageBox.Show("ServerVersion: " + myConnection.ServerVersion _
       + ControlChars.Cr + "State: " + myConnection.State.ToString())
End Sub

public void CreateOracleConnection(string myConnString) 
   OracleConnection myConnection = new OracleConnection(myConnString);
   MessageBox.Show("ServerVersion: " + myConnection.ServerVersion
      + "\nState: " + myConnection.State.ToString());

 void CreateOracleConnection(String* myConnString) 
    OracleConnection* myConnection = new OracleConnection(myConnString);
    MessageBox::Show(String::Format( S"ServerVersion: {0}\nState: {1}",
       myConnection->ServerVersion, __box(myConnection->State)));

[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.


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

.NET Framework Security: 

See Also

OracleConnection Class | OracleConnection Members | System.Data.OracleClient Namespace | Open