IDbTransaction IDbTransaction IDbTransaction IDbTransaction Interface

정의

데이터 소스에서 수행할 트랜잭션을 나타내며 관계형 데이터베이스에 액세스하는 .NET Framework 데이터 공급자에 의해 구현됩니다.Represents a transaction to be performed at a data source, and is implemented by .NET Framework data providers that access relational databases.

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

예제

다음 예제에서는 파생된 클래스의 인스턴스를 만듭니다 SqlConnectionSqlTransaction입니다.The following example creates instances of the derived classes, SqlConnection and SqlTransaction. 사용 하는 방법을 보여 줍니다 합니다 BeginTransaction, Commit, 및 Rollback 메서드.It also demonstrates how to use the BeginTransaction, Commit, and Rollback methods.

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("SampleTransaction");

        // 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("SampleTransaction")

        ' 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 데이터 원본에서 수행할 트랜잭션을 나타내는 트랜잭션 클래스를 구현 하는 상속 클래스를 사용 하는 인터페이스입니다.The IDbTransaction interface allows an inheriting class to implement a Transaction class, which represents the transaction to be performed at a data source. 트랜잭션 클래스에 대 한 자세한 내용은 참조 하세요. 트랜잭션 및 동시성합니다.For more information about Transaction classes, see Transactions and Concurrency.

애플리케이션의 인스턴스를 만들지 않습니다 합니다 IDbTransaction 인터페이스를 직접 상속 된 클래스의 인스턴스를 만들고 있지만 IDbTransaction합니다.An application does not create an instance of the IDbTransaction interface directly, but creates an instance of a class that inherits IDbTransaction.

상속 된 클래스 IDbTransaction 상속 된 멤버를 구현 해야 하며 일반적으로 공급자 특정 기능을 추가 하기 위한 추가 멤버를 정의 합니다.Classes that inherit IDbTransaction must implement the inherited members, and typically define additional members to add provider-specific functionality. 예를 들어 합니다 IDbTransaction 인터페이스를 정의 합니다 Commit 메서드.For example, the IDbTransaction interface defines the Commit method. 따라서 합니다 OleDbTransaction 클래스는이 속성을 상속 하 고도 정의 Begin 메서드.In turn, the OleDbTransaction class inherits this property, and also defines the Begin method.

구현자 참고

.NET Framework 데이터 공급자 간에 일관성을 유지 하려면 특정 .NET Framework 데이터 공급자 네임 스페이스의 Prv 모든 클래스 Prv 에 지정 된 균일 한 접두사 인 양식 트랜잭션에서 상속 클래스의 이름을 지정 합니다.To promote consistency among .NET Framework data providers, name the inheriting class in the form Prv Transaction where Prv is the uniform prefix given to all classes in a specific .NET Framework data provider namespace. 예를 들어 Sql 접두사입니다 합니다 SqlTransaction 클래스는 System.Data.SqlClient 네임 스페이스입니다.For example, Sql is the prefix of the SqlTransaction class in the System.Data.SqlClient namespace.

속성

Connection Connection Connection Connection

트랜잭션과 연결할 Connection 개체를 지정합니다.Specifies the Connection object to associate with the transaction.

IsolationLevel IsolationLevel IsolationLevel IsolationLevel

이 트랜잭션에 대한 IsolationLevel을 지정합니다.Specifies the IsolationLevel for this transaction.

메서드

Commit() Commit() Commit() Commit()

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

Dispose() Dispose() Dispose() Dispose()

관리되지 않는 리소스의 확보, 해제 또는 다시 설정과 관련된 애플리케이션 정의 작업을 수행합니다.Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

(Inherited from IDisposable)
Rollback() Rollback() Rollback() Rollback()

보류 상태에서 트랜잭션을 롤백합니다.Rolls back a transaction from a pending state.

적용 대상