Search code examples
c#enterprise-librarydeadlocktransactionscope

Transactionscope and deadlocks when using enterprise library


We are using Enterprise Library for data access.

One of our methods has a delete and then an insert, against the same table. This gives a deadlock.

If we put these inside a transaction scope the deadlock no longer occurs.

Intuitively, it feels like it should be the opposite way around. Can anyone explain why it works like this?


Solution

  • Transaction scope combined with TransactionOptions IsolationLevel = IsolationLevel.ReadUncommitted is equivalent to WITH(NOLOCK) in T-SQL so if the table is not locked the deadlocks don't occur...

    using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions(){ IsolationLevel = IsolationLevel.ReadUncommitted }))
    {
    }