OracleConnection 类

定义

警告

此 API 现已过时。

表示一个到数据库的打开的连接。Represents an open connection to a database. 此类不能被继承。This class cannot be inherited.

public ref class OracleConnection sealed : System::Data::Common::DbConnection, ICloneable
[System.Obsolete("OracleConnection has been deprecated. https://go.microsoft.com/fwlink/?LinkID=144260", false)]
public sealed class OracleConnection : System.Data.Common.DbConnection, ICloneable
type OracleConnection = class
    inherit DbConnection
    interface ICloneable
Public NotInheritable Class OracleConnection
Inherits DbConnection
Implements ICloneable
继承
属性
实现

示例

下面的示例创建 OracleCommandOracleConnectionThe following example creates an OracleCommand and an OracleConnection. 将打开 OracleConnection 并将其设置为 OracleCommand.Connection 属性。The OracleConnection is opened and set as the OracleCommand.Connection property. 然后,该示例调用 ExecuteNonQuery,并关闭连接。The example then calls ExecuteNonQuery, and closes the connection. 为实现此目的,将向 ExecuteNonQuery 传递连接字符串和作为 SQL INSERT 语句的查询字符串。To accomplish this, the ExecuteNonQuery is passed a connection string and a query string that is an SQL INSERT statement.

public void InsertRow(string connectionString)
{
    string queryString = 
        "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')";
    using (OracleConnection connection = new OracleConnection(connectionString))
    {
        OracleCommand command = new OracleCommand(queryString);
        command.Connection = connection;
        try
        {
            connection.Open();
            command.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
}
Public Sub InsertRow(ByVal connectionString As String)
    Dim queryString As String = _
      "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')"

    Using connection As New OracleConnection(connectionString)
        Dim command As New OracleCommand(queryString)
        command.Connection = connection
        Try
            connection.Open()
            command.ExecuteNonQuery()
        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End Using
End Sub

注解

此类型已弃用,并将在 .NET Framework 的未来版本中删除。This type is deprecated and will be removed in a future version of the .NET Framework. 有关详细信息,请参阅Oracle 和 ADO.NETFor more information, see Oracle and ADO.NET.

OracleConnection 对象表示到 Oracle 数据库的唯一连接。An OracleConnection object represents a unique connection to an Oracle database. 对于客户端/服务器数据库系统,它等效于到服务器的网络连接。In the case of a client/server database system, it is equivalent to a network connection to the server.

创建 OracleConnection 对象的实例的应用程序可以设置声明性或命令性安全要求,这些要求所有直接和间接调用方都具有足够的代码权限。An application that creates an instance of the OracleConnection object can set declarative or imperative security demands that require all direct and indirect callers to have adequate permission to the code. OracleConnection 使用 OraclePermission 对象创建安全要求。OracleConnection creates security demands by using the OraclePermission object. 用户可以使用 OraclePermissionAttribute 对象验证其代码是否具有足够的权限。Users can verify that their code has adequate permissions by using the OraclePermissionAttribute object. 用户和管理员还可以使用代码访问安全性策略工具(Caspol.exe)来修改计算机、用户和企业级别的安全策略。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 Security.

备注

与另一个 .NET Framework 数据提供程序(SQL Server、OLE DB 和 ODBC)中的连接对象不同,OracleConnection 不支持 ConnectionTimeout 属性。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 time-out either as a property or in the connection string has no effect, and the value returned is always zero. OracleConnection 还不支持 Database 属性或 ChangeDatabase 方法。OracleConnection also does not support a Database property or a ChangeDatabase method.

如果 OracleConnection 对象超出范围,则会保持打开状态。If the OracleConnection object goes out of scope, it remains open. 因此,应始终通过调用 CloseDispose来关闭 OracleConnection 对象,或在 Using 语句中使用 OracleConnection 对象。Therefore, you should always close OracleConnection objects by calling Close or Dispose, or by using the OracleConnection object within a Using statement. 否则,垃圾回收可能不会立即释放它们。Otherwise, the garbage collection might not free them immediately. 如果在多个连接等待垃圾回收器删除的情况下达到了最大连接数,则此类延迟可能导致错误。Such delays can cause errors if the maximum number of connections is reached while a number of connections are waiting to be deleted by the garbage collector. 相反,通过调用 Close 关闭连接将更有效地使用本机资源,从而提高可伸缩性并提高应用程序的总体性能。By contrast, closing the connections by calling Close uses native resources more efficiently, enhancing scalability and improving overall application performance. 若要确保始终关闭连接,请在 Using 块中打开连接。To ensure that connections are always closed, open the connection inside of a Using block.

备注

若要部署高性能应用程序,通常需要使用连接池。To deploy high-performance applications, you often need to use connection pooling. 但是,使用适用于 Oracle 的 .NET Framework 数据提供程序时,不需要启用连接池,因为提供程序会自动管理此。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.

构造函数

OracleConnection()

初始化 OracleConnection 的新实例。Initializes a new instance of the OracleConnection.

OracleConnection(String)

使用指定的连接字符串初始化 OracleConnection 类的新实例。Initializes a new instance of the OracleConnection class with the specified connection string.

属性

CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(继承自 Component)
ConnectionString

获取或设置用于打开 Oracle 数据库的字符串。Gets or sets the string used to open an Oracle database.

ConnectionTimeout

获取在建立连接时终止尝试并生成错误之前所等待的时间。Gets the time to wait to establish a connection before terminating the attempt and generating an error.

Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(继承自 Component)
Database

获取当前数据库的名称或打开连接后要使用的数据库的名称。Gets the name of the current database or the database to be used after a connection is opened.

DataSource

获取要连接的 Oracle 服务器的名称。Gets the name of the Oracle server to which to connect.

DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(继承自 Component)
Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(继承自 Component)
ServerVersion

获取包含客户端所连接到的服务器的版本的字符串。Gets a string containing the version of the server to which the client is connected.

Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(继承自 Component)
State

获取连接的当前状态。Gets the current state of the connection.

方法

BeginTransaction()

在数据库中开始一个事务。Begins a transaction at the database.

BeginTransaction(IsolationLevel)

使用指定的 IsolationLevel 值在数据库中开始一个事务。Begins a transaction at the database with the specified IsolationLevel value.

ChangeDatabase(String)

更改已打开的 OracleConnection 的当前数据库。Changes the current database for an open OracleConnection.

ClearAllPools()

清空连接池。Empties the connection pool.

ClearPool(OracleConnection)

清空与指定连接关联的连接池。Empties the connection pool associated with the specified connection.

Close()

关闭与数据库之间的连接。Closes the connection to the database.

CreateCommand()

创建并返回一个与该 OracleCommand 关联的 OracleConnection 对象。Creates and returns an OracleCommand object associated with the OracleConnection.

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()

释放由 Component 使用的所有资源。Releases all resources used by the Component.

(继承自 Component)
Dispose(Boolean)

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(继承自 Component)
EnlistDistributedTransaction(ITransaction)

在指定的事务中登记为分布式事务。Enlists in the specified transaction as a distributed transaction.

EnlistTransaction(Transaction)

在指定的事务中登记为分布式事务。Enlists in the specified transaction as a distributed transaction.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetSchema()

返回此 OracleConnection 的数据源的架构信息。Returns schema information for the data source of this OracleConnection.

GetSchema(String)

通过使用架构名称的指定字符串,返回此 OracleConnection 的数据源的架构信息。Returns schema information for the data source of this OracleConnection using the specified string for the schema name.

GetSchema(String, String[])

通过使用指定字符串作为架构名称,指定字符串数组作为限制值,返回此 OracleConnection 的数据源的架构信息。Returns schema information for the data source of this OracleConnection using the specified string for the schema name and the specified string array for the restriction values.

GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(继承自 Component)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
Open()

使用 ConnectionString 指定的属性设置打开一个到数据库的连接。Opens a connection to a database with the property settings specified by the ConnectionString.

ToString()

返回包含 Component 的名称的 String(如果有)。Returns a String containing the name of the Component, if any. 不应重写此方法。This method should not be overridden.

(继承自 Component)

事件

Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(继承自 Component)
InfoMessage

当 Oracle 发送警告或信息性消息时发生。Occurs when Oracle sends a warning or an informational message.

StateChange

当连接状态改变时发生。Occurs when the state of the connection changes.

显式界面实现

ICloneable.Clone()

创建作为当前实例副本的新对象。Creates a new object that is a copy of the current instance.

IDbConnection.BeginTransaction()

开始一项数据库事务。Begins a database transaction.

IDbConnection.BeginTransaction(IsolationLevel)

以指定的 IsolationLevel 值开始数据库事务。Begins a database transaction with the specified IsolationLevel value.

IDbConnection.ChangeDatabase(String)

为打开的连接对象更改当前数据库。Changes the current database for an open Connection object.

IDbConnection.CreateCommand()

创建并返回一个与连接关联的命令对象。Creates and returns a Command object that is associated with the connection.

适用于

另请参阅