dotConnect Universal Documentation
Devart.Common Namespace / DbConnectionBase Class / EnlistTransaction Method
A reference to an existing System.Transactions.Transaction in which to enlist.
Example

In This Topic
    EnlistTransaction Method (DbConnectionBase)
    In This Topic
    Enlists in the specified transaction.
    Syntax
    'Declaration
     
    Public Overrides Sub EnlistTransaction( _
       ByVal transaction As Transaction _
    ) 
    public override void EnlistTransaction( 
       Transaction transaction
    )

    Parameters

    transaction
    A reference to an existing System.Transactions.Transaction in which to enlist.
    Remarks

    Once a connection is explicitly enlisted in a distributed transaction, it cannot be unenlisted or enlisted in another transaction until the first transaction finishes.

    Example
    These samples demonstrate usage of EnlistTransaction.
    UniversalCommand1.Connection=UniversalConnection1;
    using (TransactionScope transScope = new TransactionScope()) {
     UniversalConnection1.Open();
     UniversalCommand1.ExecuteNonQuery();
     transScope.Complete();
    }
    UniversalConnection1.Close();
    
    - or -
    
    UniversalCommand1.Connection=UniversalConnection1;
    UniversalConnection1.Open();
    using (TransactionScope transScope = new TransactionScope()) {
     UniversalConnection1.EnlistTransaction(Transaction.Current);
     UniversalCommand1.ExecuteNonQuery();
     transScope.Complete();
    }
    UniversalConnection1.Close();
    
    - or -
    
    CommittableTransaction cmtTx = new CommittableTransaction();
    UniversalConnection1.Open();
    UniversalConnection1.EnlistTransaction(cmtTx);
    UniversalCommand1.ExecuteNonQuery();
    UniversalConnection1.Close();
    Me.UniversalCommand1.Connection = Me.UniversalConnection1
    Using transScope = New Transactions.TransactionScope
      Me.UniversalConnection1.Open()
      Me.UniversalCommand1.ExecuteNonQuery()
      transScope.Complete()
    End Using
    Me.UniversalConnection1.Close()
    
    - or -
    
    Me.UniversalCommand1.Connection = Me.UniversalConnection1
    Me.UniversalConnection1.Open()
    Using transScope = New Transactions.TransactionScope
      Me.UniversalConnection1.EnlistTransaction(Transactions.Transaction.Current)
      Me.UniversalCommand1.ExecuteNonQuery()
      transScope.Complete()
    End Using
    Me.UniversalConnection1.Close()
    
    - or -
    
    Dim cmtTx As New Transactions.CommittableTransaction
    Me.UniversalConnection1.Open()
    Me.UniversalConnection1.EnlistTransaction(cmtTx)
    Me.UniversalCommand1.ExecuteNonQuery()
    Me.UniversalConnection1.Close()
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also