IDbTransaction 인터페이스

정의

데이터 소스에서 수행할 트랜잭션을 나타내며 관계형 데이터베이스에 액세스하는 .NET 데이터 공급자에 의해 구현됩니다.

public interface class IDbTransaction : IDisposable
public interface IDbTransaction : IDisposable
type IDbTransaction = interface
    interface IDisposable
Public Interface IDbTransaction
Implements IDisposable
파생
구현

예제

다음 예제에서는 파생된 클래스의 인스턴스를 만듭니다 SqlConnectionSqlTransaction입니다. 사용 하는 방법을 보여 줍니다 합니다 BeginTransaction, Commit, 및 Rollback 메서드.

private static void ExecuteSqlTransaction(string connectionString)
{
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        connection.Open();

        SqlCommand command = connection.CreateCommand();
        SqlTransaction transaction;

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

        // Must assign both transaction object and connection
        // to Command object for a pending local transaction
        command.Connection = connection;
        command.Transaction = transaction;

        try
        {
            command.CommandText =
                "Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')";
            command.ExecuteNonQuery();
            command.CommandText =
                "Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')";
            command.ExecuteNonQuery();

            // Attempt to commit the transaction.
            transaction.Commit();
            Console.WriteLine("Both records are written to database.");
        }
        catch (Exception ex)
        {
            Console.WriteLine("Commit Exception Type: {0}", ex.GetType());
            Console.WriteLine("  Message: {0}", ex.Message);

            // Attempt to roll back the transaction.
            try
            {
                transaction.Rollback();
            }
            catch (Exception ex2)
            {
                // This catch block will handle any errors that may have occurred
                // on the server that would cause the rollback to fail, such as
                // a closed connection.
                Console.WriteLine("Rollback Exception Type: {0}", ex2.GetType());
                Console.WriteLine("  Message: {0}", ex2.Message);
            }
        }
    }
}
Private Sub ExecuteSqlTransaction(ByVal connectionString As String)
    Using connection As New SqlConnection(connectionString)
        connection.Open()

        Dim command As SqlCommand = connection.CreateCommand()
        Dim transaction As SqlTransaction

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

        ' Must assign both transaction object and connection
        ' to Command object for a pending local transaction.
        command.Connection = connection
        command.Transaction = transaction

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

            command.ExecuteNonQuery()

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

        Catch ex As Exception
            Console.WriteLine("Commit Exception Type: {0}", ex.GetType())
            Console.WriteLine("  Message: {0}", ex.Message)

            ' Attempt to roll back the transaction.
            Try
                transaction.Rollback()

            Catch ex2 As Exception
                ' This catch block will handle any errors that may have occurred
                ' on the server that would cause the rollback to fail, such as
                ' a closed connection.
                Console.WriteLine("Rollback Exception Type: {0}", ex2.GetType())
                Console.WriteLine("  Message: {0}", ex2.Message)
            End Try
        End Try
    End Using
End Sub

설명

IDbTransaction 데이터 원본에서 수행할 트랜잭션을 나타내는 트랜잭션 클래스를 구현 하는 상속 클래스를 사용 하는 인터페이스입니다. 트랜잭션 클래스에 대 한 자세한 내용은 참조 하세요. 트랜잭션 및 동시성합니다.

애플리케이션의 인스턴스를 만들지 않습니다 합니다 IDbTransaction 인터페이스를 직접 상속 된 클래스의 인스턴스를 만들고 있지만 IDbTransaction합니다.

상속 된 클래스 IDbTransaction 상속 된 멤버를 구현 해야 하며 일반적으로 공급자 특정 기능을 추가 하기 위한 추가 멤버를 정의 합니다. 예를 들어 합니다 IDbTransaction 인터페이스를 정의 합니다 Commit 메서드. 따라서 합니다 OleDbTransaction 클래스는이 속성을 상속 하 고도 정의 Begin 메서드.

구현자 참고

.NET Framework 데이터 공급자 간의 일관성을 높이기 위해 Transaction 형식 Prv 에서 상속 클래스의 이름을 지정합니다. 여기서 Prv 는 특정 .NET Framework 데이터 공급자 네임스페이스의 모든 클래스에 지정된 균일한 접두사입니다. 예를 들어 Sql 접두사입니다 합니다 SqlTransaction 클래스는 System.Data.SqlClient 네임 스페이스입니다.

속성

Connection

트랜잭션과 연결할 Connection 개체를 지정합니다.

IsolationLevel

이 트랜잭션에 대한 IsolationLevel을 지정합니다.

메서드

Commit()

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

Dispose()

관리되지 않는 리소스의 확보, 해제 또는 다시 설정과 관련된 애플리케이션 정의 작업을 수행합니다.

(다음에서 상속됨 IDisposable)
Rollback()

보류 상태에서 트랜잭션을 롤백합니다.

적용 대상