I have facing issue about "transaction was deadlocked" in one of my WCF webserice method, which is used to updated about 8 tables in Server database. I am using LinqToSQL in my WCF service to perform all database related operation.
And my code is something like below...
//Write code to open connection
foreach (var item in _updateList)
{
dataTrans = this.Context.Connection.BeginTransaction(
System.Data.IsolationLevel.ReadUncommitted
);
try{
//Save Changes to database
this.Context.SubmitChanges();
dataTrans.Commit();
}
catch (Exception ex)
{
//RollBack Datatransaction if any Table has invalid argument
if (dataTrans != null)
dataTrans.Rollback();
}
}
and found below error in my Exception log
Transaction (Process ID 71) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
.Net SqlClient Data Provider
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.HasMoreRows()
at System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout)
at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReaderBase`1.Read()
at System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Task.TaskMfssActionDtl.UpdateSqlToDevice(RequestSqlToDevice request)