dotConnect for Dynamics 365 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
    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 Devart.Data.Dynamics.DynamicsConnection.EnlistTransaction.
    DynamicsCommand1.Connection=DynamicsConnection1;
    using (TransactionScope transScope = new TransactionScope()) {
     DynamicsConnection1.Open();
     DynamicsCommand1.ExecuteNonQuery();
     transScope.Complete();
    }
    DynamicsConnection1.Close();
    
    - or -
    
    DynamicsCommand1.Connection=DynamicsConnection1;
    DynamicsConnection1.Open();
    using (TransactionScope transScope = new TransactionScope()) {
     DynamicsConnection1.EnlistTransaction(Transaction.Current);
     DynamicsCommand1.ExecuteNonQuery();
     transScope.Complete();
    }
    DynamicsConnection1.Close();
    
    - or -
    
    CommittableTransaction cmtTx = new CommittableTransaction();
    DynamicsConnection1.Open();
    DynamicsConnection1.EnlistTransaction(cmtTx);
    DynamicsCommand1.ExecuteNonQuery();
    DynamicsConnection1.Close();
    Me.DynamicsCommand1.Connection = Me.DynamicsConnection1
    Using transScope = New Transactions.TransactionScope
      Me.DynamicsConnection1.Open()
      Me.DynamicsCommand1.ExecuteNonQuery()
      transScope.Complete()
    End Using
    Me.DynamicsConnection1.Close()
    
    - or -
    
    Me.DynamicsCommand1.Connection = Me.DynamicsConnection1
    Me.DynamicsConnection1.Open()
    Using transScope = New Transactions.TransactionScope
      Me.DynamicsConnection1.EnlistTransaction(Transactions.Transaction.Current)
      Me.DynamicsCommand1.ExecuteNonQuery()
      transScope.Complete()
    End Using
    Me.DynamicsConnection1.Close()
    
    - or -
    
    Dim cmtTx As New Transactions.CommittableTransaction
    Me.DynamicsConnection1.Open()
    Me.DynamicsConnection1.EnlistTransaction(cmtTx)
    Me.DynamicsCommand1.ExecuteNonQuery()
    Me.DynamicsConnection1.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