Really nice solution to deadlocks in sql azure

We were getting random deadlocks when accessing the same rows multiple times in a sql azure database using linq2sql.

Matt Hamilton came up with an excellent solution here – our TransactionScope was causing the problem.

http://madprops.org/blog/linq-to-sql-and-nolock-hints/

using (var txn = new TransactionScope(    TransactionScopeOption.Required,     new TransactionOptions
    {
        IsolationLevel = IsolationLevel.ReadUncommitted    })){    // Your LINQ to SQL query goes here}

Update: a TransactionScope has by default a IsolationLevel of Serializable, which was our problem. Try defining the IsolationLevel of ReadCommitted or RepeatableRead instead!

  1. #1 by pjsparksy on April 28, 2011 - 7:38 pm

    long as you understand what readuncommited actually does. but yes it will reduce deadlocking for sure.

    • #2 by bsmithb2 on April 29, 2011 - 4:17 pm

      Unfortunately – I don’t have much choice in our instance. Stupid event driven domain model. grrr..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.