OracleTransaction.Rollback OracleTransaction.Rollback OracleTransaction.Rollback OracleTransaction.Rollback Method

定義

トランザクションを保留状態からロールバックします。Rolls back a transaction from a pending state.

public:
 override void Rollback();
public override void Rollback ();
override this.Rollback : unit -> unit
Public Overrides Sub Rollback ()

例外

トランザクションをコミットしようとしてエラーが発生しました。An error occurred while trying to commit the transaction.

トランザクションは既にコミットまたはロールバックされています。The transaction has already been committed or rolled back.

または-or-

接続が切れています。The connection is broken.

次の例では、作成、OracleConnectionOracleTransactionします。The following example creates an OracleConnection and an OracleTransaction. 使用する方法も示します、 BeginTransactionCommit、およびRollbackメソッド。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

注釈

トランザクションは保留中の状態からのみロールバックできます (後BeginTransactionが呼び出されると、前にCommitと呼びます)。The transaction can be rolled back only from a pending state (after BeginTransaction has been called, but before Commit is called).

適用対象

こちらもご覧ください