Dapper & TransactionScope?

It was totally my fault and not fully understanding transactionscope. A connection is not automatically enlisted in transactionscope unless you open the connection within the transactionscope:

Automatic Enlistment

  using (var scope = new TransactionScope())
  {
      con.Open();                                
      //update/delete/insert commands here
      ...
      scope.Complete();
  }

Manual Enlistment

    con.Open();
    using (var scope = new TransactionScope())
    {
       con.EnlistTransaction(Transaction.Current);  
       //update/delte/insert statements here
       ...
       scope.Complete();
    }

Details can be found here: Details

Leave a Comment