OleDbConnection.BeginTransaction OleDbConnection.BeginTransaction OleDbConnection.BeginTransaction OleDbConnection.BeginTransaction Method

정의

데이터베이스 트랜잭션을 시작합니다.Starts a database transaction.

오버로드

BeginTransaction() BeginTransaction() BeginTransaction() BeginTransaction()

현재 IsolationLevel 값을 사용하여 데이터베이스 트랜잭션을 시작합니다.Starts a database transaction with the current IsolationLevel value.

BeginTransaction(IsolationLevel) BeginTransaction(IsolationLevel) BeginTransaction(IsolationLevel)

지정된 격리 수준으로 데이터베이스 트랜잭션을 시작합니다.Starts a database transaction with the specified isolation level.

BeginTransaction() BeginTransaction() BeginTransaction() BeginTransaction()

현재 IsolationLevel 값을 사용하여 데이터베이스 트랜잭션을 시작합니다.Starts a database transaction with the current IsolationLevel value.

public:
 System::Data::OleDb::OleDbTransaction ^ BeginTransaction();
public System.Data.OleDb.OleDbTransaction BeginTransaction ();
override this.BeginTransaction : unit -> System.Data.OleDb.OleDbTransaction
Public Function BeginTransaction () As OleDbTransaction

반환

새 트랜잭션을 나타내는 개체입니다.An object representing the new transaction.

예외

병렬 트랜잭션은 지원되지 않습니다.Parallel transactions are not supported.

예제

다음 예제는 OleDbConnectionOleDbTransaction합니다.The following example creates an OleDbConnection and an OleDbTransaction. 사용 하는 방법을 보여 줍니다 합니다 BeginTransaction, Commit, 및 Rollback 메서드.It also demonstrates how to use the BeginTransaction, Commit, and Rollback methods.

public void ExecuteTransaction(string connectionString)
{
    using (OleDbConnection connection =
               new OleDbConnection(connectionString))
    {
        OleDbCommand command = new OleDbCommand();
        OleDbTransaction transaction = null;

        // Set the Connection to the new OleDbConnection.
        command.Connection = connection;

        // Open the connection and execute the transaction.
        try
        {
            connection.Open();

            // Start a local transaction with ReadCommitted isolation level.
            transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);

            // Assign transaction object for a pending local transaction.
            command.Connection = connection;
            command.Transaction = transaction;

            // Execute the commands.
            command.CommandText =
                "Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')";
            command.ExecuteNonQuery();
            command.CommandText =
                "Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')";
            command.ExecuteNonQuery();

            // Commit the transaction.
            transaction.Commit();
            Console.WriteLine("Both records are written to database.");
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            try
            {
                // Attempt to roll back the transaction.
                transaction.Rollback();
            }
            catch
            {
                // Do nothing here; transaction is not active.
            }
        }
        // The connection is automatically closed when the
        // code exits the using block.
    }
}
Public Sub ExecuteTransaction(ByVal connectionString As String)

    Using connection As New OleDbConnection(connectionString)
        Dim command As New OleDbCommand()
        Dim transaction As OleDbTransaction

        ' Set the Connection to the new OleDbConnection.
        command.Connection = connection

        ' Open the connection and execute the transaction.
        Try
            connection.Open()

            ' Start a local transaction with ReadCommitted isolation level.
            transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted)

            ' Assign transaction object for a pending local transaction.
            command.Connection = connection
            command.Transaction = transaction

            ' Execute the commands.
            command.CommandText = _
                "Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')"
            command.ExecuteNonQuery()
            command.CommandText = _
                "Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')"
            command.ExecuteNonQuery()

            ' Commit the transaction.
            transaction.Commit()
            Console.WriteLine("Both records are written to database.")

        Catch ex As Exception
            Console.WriteLine(ex.Message)
            ' Try to rollback the transaction
            Try
                    transaction.Rollback()

            Catch
                ' Do nothing here; transaction is not active.
            End Try
        End Try
        ' The connection is automatically closed when the
        ' code exits the Using block.
    End Using
End Sub

설명

명시적으로 커밋 또는 사용 하 여 트랜잭션을 롤백합니다 해야 합니다 Commit 또는 Rollback 메서드.You must explicitly commit or roll back the transaction using the Commit or Rollback method. .NET Framework Data Provider for OLE DB 트랜잭션 관리 모델을 올바르게 수행 했는지를 데이터 원본에서 제공 하는 다른 트랜잭션 관리 모델을 사용 하지 마십시오.To make sure that the .NET Framework Data Provider for OLE DB transaction management model performs correctly, avoid using other transaction management models, such as those provided by the data source.

추가 정보

BeginTransaction(IsolationLevel) BeginTransaction(IsolationLevel) BeginTransaction(IsolationLevel)

지정된 격리 수준으로 데이터베이스 트랜잭션을 시작합니다.Starts a database transaction with the specified isolation level.

public:
 System::Data::OleDb::OleDbTransaction ^ BeginTransaction(System::Data::IsolationLevel isolationLevel);
public System.Data.OleDb.OleDbTransaction BeginTransaction (System.Data.IsolationLevel isolationLevel);
override this.BeginTransaction : System.Data.IsolationLevel -> System.Data.OleDb.OleDbTransaction

매개 변수

isolationLevel
IsolationLevel IsolationLevel IsolationLevel IsolationLevel

트랜잭션이 실행되어야 하는 격리 수준입니다.The isolation level under which the transaction should run.

반환

새 트랜잭션을 나타내는 개체입니다.An object representing the new transaction.

예외

병렬 트랜잭션은 지원되지 않습니다.Parallel transactions are not supported.

예제

다음 예제는 OleDbConnectionOleDbTransaction합니다.The following example creates an OleDbConnection and an OleDbTransaction. 사용 하는 방법을 보여 줍니다 합니다 BeginTransaction, Commit, 및 Rollback 메서드.It also demonstrates how to use the BeginTransaction, a Commit, and Rollback methods.

public void ExecuteTransaction(string connectionString)
{
    using (OleDbConnection connection =
               new OleDbConnection(connectionString))
    {
        OleDbCommand command = new OleDbCommand();
        OleDbTransaction transaction = null;

        // Set the Connection to the new OleDbConnection.
        command.Connection = connection;

        // Open the connection and execute the transaction.
        try
        {
            connection.Open();

            // Start a local transaction
            transaction = connection.BeginTransaction();

            // Assign transaction object for a pending local transaction.
            command.Connection = connection;
            command.Transaction = transaction;

            // Execute the commands.
            command.CommandText =
                "Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')";
            command.ExecuteNonQuery();
            command.CommandText =
                "Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')";
            command.ExecuteNonQuery();

            // Commit the transaction.
            transaction.Commit();
            Console.WriteLine("Both records are written to database.");
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            try
            {
                // Attempt to roll back the transaction.
                transaction.Rollback();
            }
            catch
            {
                // Do nothing here; transaction is not active.
            }
        }
        // The connection is automatically closed when the
        // code exits the using block.
    }
}
Public Sub ExecuteTransaction(ByVal connectionString As String)

    Using connection As New OleDbConnection(connectionString)
        Dim command As New OleDbCommand()
        Dim transaction As OleDbTransaction

        ' Set the Connection to the new OleDbConnection.
        command.Connection = connection

        ' Open the connection and execute the transaction.
        Try
            connection.Open()

            ' Start a local transaction.
            transaction = connection.BeginTransaction()

            ' Assign transaction object for a pending local transaction.
            command.Connection = connection
            command.Transaction = transaction

            ' Execute the commands.
            command.CommandText = _
                "Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')"
            command.ExecuteNonQuery()
            command.CommandText = _
                "Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')"
            command.ExecuteNonQuery()

            ' Commit the transaction.
            transaction.Commit()
            Console.WriteLine("Both records are written to database.")

        Catch ex As Exception
            Console.WriteLine(ex.Message)
            ' Try to rollback the transaction
            Try
                    transaction.Rollback()

            Catch
                ' Do nothing here; transaction is not active.
            End Try
        End Try
        ' The connection is automatically closed when the
        ' code exits the Using block.
    End Using
End Sub

설명

명시적으로 커밋 또는 사용 하 여 트랜잭션을 롤백합니다 해야 합니다 Commit 또는 Rollback 메서드.You must explicitly commit or roll back the transaction using the Commit or Rollback method. .NET Framework Data Provider for OLE DB 트랜잭션 관리 모델을 올바르게 수행 했는지를 데이터 원본에서 제공 하는 다른 트랜잭션 관리 모델을 사용 하지 마십시오.To make sure that the .NET Framework Data Provider for OLE DB transaction management model performs correctly, avoid using other transaction management models, such as those provided by the data source.

참고

격리 수준을 지정 하지 않으면, 기본 공급자에 대 한 기본 격리 수준이 사용 됩니다.If you do not specify an isolation level, the default isolation level for the underlying provider is used. 사용 하 여 격리 수준을 지정 하는 BeginTransaction 메서드를 오버 로드를 사용 하 여는 isolationLevel 매개 변수입니다.To specify an isolation level with the BeginTransaction method, use the overload that takes the isolationLevel parameter.

추가 정보

적용 대상