다음을 통해 공유


OracleTransaction.Commit 메서드

정의

SQL 데이터베이스 트랜잭션을 커밋합니다.

public:
 virtual void Commit();
public:
 override void Commit();
public void Commit ();
public override void Commit ();
abstract member Commit : unit -> unit
override this.Commit : unit -> unit
override this.Commit : unit -> unit
Public Sub Commit ()
Public Overrides Sub Commit ()

구현

예외

트랜잭션을 커밋하는 동안 오류가 발생한 경우

트랜잭션이 이미 커밋 또는 롤백된 경우

또는

연결이 손상된 경우

예제

다음 예제에서는 및 를 OracleConnectionOracleTransaction만듭니다. 사용 하는 방법을 보여 줍니다 합니다 BeginTransaction, Commit, 및 Rollback 메서드.

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

적용 대상

추가 정보