OracleTransaction 类

定义

表示要在数据库中生成的事务。Represents a transaction to be made in the database.

public ref class OracleTransaction sealed : System::Data::Common::DbTransaction
public sealed class OracleTransaction : System.Data.Common.DbTransaction
type OracleTransaction = class
    inherit DbTransaction
Public NotInheritable Class OracleTransaction
Inherits DbTransaction
继承
OracleTransaction

示例

下面的示例创建一个OracleConnection和一个OracleTransactionThe following example creates an OracleConnection and an OracleTransaction. 它还演示了如何使用BeginTransactionCommitRollback方法。It also demonstrates how to use the BeginTransaction, Commit, and Rollback methods.

public void RunOracleTransaction(string connectionString)
{
    using (OracleConnection connection = new OracleConnection(connectionString))
    {
        connection.Open();

        OracleCommand command = connection.CreateCommand();
        OracleTransaction transaction;

        // Start a local transaction
        transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);
        // Assign transaction object for a pending local transaction
        command.Transaction = transaction;

        try
        {
            command.CommandText = 
                "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')";
            command.ExecuteNonQuery();
            command.CommandText = 
                "INSERT INTO Dept (DeptNo, Dname, Loc) values (60, 'ENGINEERING', 'KANSAS CITY')";
            command.ExecuteNonQuery();
            transaction.Commit();
            Console.WriteLine("Both records are written to database.");
        }
        catch (Exception e)
        {
            transaction.Rollback();
            Console.WriteLine(e.ToString());
            Console.WriteLine("Neither record was written to database.");
        }
    }
}
Public Sub RunOracleTransaction(ByVal connectionString As String)
    Using connection As New OracleConnection(connectionString)
        connection.Open()

        Dim command As OracleCommand = connection.CreateCommand()
        Dim transaction As OracleTransaction

        ' Start a local transaction
        transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted)
        ' Assign transaction object for a pending local transaction
        command.Transaction = transaction

        Try
            command.CommandText = _
                "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')"
            command.ExecuteNonQuery()
            command.CommandText = _
                "INSERT INTO Dept (DeptNo, Dname, Loc) values (60, 'ENGINEERING', 'KANSAS CITY')"
            command.ExecuteNonQuery()
            transaction.Commit()
            Console.WriteLine("Both records are written to database.")
        Catch e As Exception
            transaction.Rollback()
            Console.WriteLine(e.ToString())
            Console.WriteLine("Neither record was written to database.")
        End Try
    End Using
End Sub

注解

应用程序通过对OracleTransaction OracleConnection对象调用BeginTransaction来创建对象。The application creates an OracleTransaction object by calling BeginTransaction on the OracleConnection object. 与事务关联的所有后续操作(例如,提交或中止事务)都在OracleTransaction对象上执行。All subsequent operations associated with the transaction (for example, committing or aborting the transaction), are performed on the OracleTransaction object.

属性

Connection

指定与该事务关联的 OracleConnection 对象。Specifies the OracleConnection object associated with the transaction.

DbConnection

在派生类中重写时,获取与事务关联的 DbConnection 对象。When overridden in a derived class, gets the DbConnection object associated with the transaction.

(继承自 DbTransaction)
IsolationLevel

为该事务指定 IsolationLevelSpecifies the IsolationLevel for this transaction.

方法

Commit()

提交 SQL 数据库事务。Commits the SQL database transaction.

CommitAsync(CancellationToken)

异步提交数据库事务。Asynchronously commits the database transaction.

(继承自 DbTransaction)
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()

释放此对象使用的资源。Releases the resources used by this object.

Dispose(Boolean)

释放 DbTransaction 使用的非托管资源,并选择性地释放托管资源。Releases the unmanaged resources used by the DbTransaction and optionally releases the managed resources.

(继承自 DbTransaction)
DisposeAsync()

异步处置事务对象。Asynchronously diposes the transaction object.

(继承自 DbTransaction)
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)
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)
Rollback()

从挂起状态回滚事务。Rolls back a transaction from a pending state.

RollbackAsync(CancellationToken)

从挂起状态异步回滚事务。Asynchronously rolls back a transaction from a pending state.

(继承自 DbTransaction)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

IDbTransaction.Connection

获取与事务关联的 DbConnection 对象,或空引用(如果该事务不再有效)。Gets the DbConnection object associated with the transaction, or a null reference if the transaction is no longer valid.

(继承自 DbTransaction)

适用于

另请参阅