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 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..