This documentation is archived and is not being maintained.

OracleConnection Class

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

Represents an open connection to a database. This class cannot be inherited.

For a list of all members of this type, see OracleConnection Members.


[Visual Basic]
NotInheritable Public Class OracleConnection
   Inherits Component
   Implements ICloneable, IDbConnection
public sealed class OracleConnection : Component, ICloneable,
public __gc __sealed class OracleConnection : public Component,
   ICloneable, IDbConnection
public class OracleConnection extends Component implements
   ICloneable, IDbConnection

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


An OracleConnection object represents a unique connection to a database created by using a connection string. In the case of a client/server database system, it is equivalent to a network connection to the server.

You should always explicitly close any open OracleConnection objects by calling Close or Dispose before the OracleConnection object goes out of scope. Not doing so leaves the freeing of these native resources to garbage collection, which may not free them immediately. For example, you might encounter Maximum Connections-related errors while a number of connections are waiting to be deleted by the garbage collector. Explicitly closing the connections by calling Close or Dispose allows a more efficient use of native resources, enhancing scalability and improving overall application performance.

Note   To deploy high-performance applications, you often need to use connection pooling. However, when you use the .NET Framework Data Provider for Oracle, you do not need to enable connection pooling because the provider manages this automatically.

An application that creates an instance of the OracleConnection object can require all direct and indirect callers to have adequate permission to the code by setting declarative or imperative security demands. OracleConnection creates security demands by using the OraclePermission object. Users can verify that their code has adequate permissions by using the OraclePermissionAttribute object. Users and administrators can also use the Code Access Security Policy Tool (Caspol.exe) to modify security policy at the machine, user, and enterprise levels. For more information, see Securing Applications.

Note   Unlike the Connection object in the other .NET Framework data providers (SQL Server, OLE DB, and ODBC), OracleConnection does not support a ConnectionTimeout property. Setting a connection timeout using a property or in the connection string has no effect and value returned is always zero. OracleConnection also does not support a Database property or a ChangeDatabase method.


[Visual Basic, C#, C++] The following example creates an OracleCommand and an OracleConnection. The OracleConnection is opened and set as the OracleCommand.Connection property. The example then calls ExecuteNonQuery, and closes the connection. To accomplish this, the ExecuteNonQuery is passed a connection string and a query string that is an SQL INSERT statement.

[Visual Basic] 
Public Sub InsertRow(myConnection As String)
    ' If the connection string is null, use a default.
    If myConnection = "" Then
        myConnection = "Data Source=Oracle8i;Integrated Security=yes"
    End If
    Dim myConn As New OracleConnection(myConnection)
    Dim myInsertQuery As String = "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')"
    Dim myOracleCommand As New OracleCommand(myInsertQuery)
    myOracleCommand.Connection = myConn
End Sub

public void InsertRow(string myConnection) 
   // If the connection string is null, use a default.
   if(myConnection == "") 
      myConnection = "Data Source=Oracle8i;Integrated Security=yes";
   OracleConnection myConn = new OracleConnection(myConnection);
   string myInsertQuery = "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')";
   OracleCommand myOracleCommand = new OracleCommand(myInsertQuery);
   myOracleCommand.Connection = myConn;

 void InsertRow(String* myConnection) 
    // If the connection string is null, use a default.
       myConnection = S"Data Source=Oracle8i;Integrated Security=yes";
    OracleConnection* myConn = new OracleConnection(myConnection);
    String* myInsertQuery = S"INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')";
    OracleCommand* myOracleCommand = new OracleCommand(myInsertQuery);
    myOracleCommand->Connection = myConn;

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


Namespace: System.Data.OracleClient

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

Assembly: System.Data.Oracleclient (in System.Data.Oracleclient.dll)

See Also

OracleConnection Members | System.Data.OracleClient Namespace | OracleDataAdapter | OracleCommand