OracleConnection Class
An OracleConnection
object represents a connection to an Oracle database.
Note:
The OracleConnection
class has been extended and modified in the Oracle.ManagedDataAccess.Azure
and Oracle.ManagedDataAccess.Oci
assemblies. They expose methods for ODP.NET to connect through Azure and Oracle Cloud Infrastructure token authentication, respectively.
Class Inheritance
System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Data.Common.DbConnection
Oracle.DataAccess.Client.OracleConnection
Declaration
// C# public sealed class OracleConnection : DbConnection, IDbConnection, ICloneable
Requirements
Provider | ODP.NET, Unmanaged Driver | ODP.NET, Managed Driver | ODP.NET Core |
---|---|---|---|
Assembly |
|
|
|
Namespace |
|
|
|
.NET Framework |
- |
||
.NET (Core) |
- |
- |
Thread Safety
All public static methods are thread-safe, although instance methods do not guarantee thread safety.
Example
// C# using System; using System.Data; using Oracle.DataAccess.Client; class OracleConnectionSample { static void Main() { // Connect string constr = "User Id=scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); // Execute a SQL SELECT OracleCommand cmd = con.CreateCommand(); cmd.CommandText = "select * from emp"; OracleDataReader reader = cmd.ExecuteReader(); // Print all employee numbers while (reader.Read()) Console.WriteLine(reader.GetInt32(0)); // Clean up reader.Dispose(); cmd.Dispose(); con.Dispose(); } }