SqlException事务在通信缓冲区资源上死锁

时间:2011-07-20 17:50:31

标签: c# .net sql-server timeout

我有一个必须执行大量数据库查询的服务器进程,它使用TPL并行运行东西。它在今年的整个过程中都运行良好,直到今天它在30分钟的时间内坠毁了两次,但有以下例外情况:

  

事务(进程ID 89)在通信缓冲区资源上与另一个进程发生死锁,并被选为死锁牺牲品。重新运行该交易。

数据库配置为记录任何死锁,但它没有记录任何内容,所以好像这个死锁只发生在客户端?

除了一个msdn forum post that doesn't provide any information之外,我找不到任何对此异常的引用。

之前有没有人见过这个例外?或者知道我可以做些什么来找到有关它的更多信息?

---> System.AggregateException: One or more errors occurred. 

---> System.Data.SqlClient.SqlException: Transaction (Process ID 89) was deadlocked on communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
   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 App.CoreEngine.V5.DataAccess.SqlReader.Read(String readerDescription) in C:\SourceCode\AppV1\Releases\Libraries\CoreEngine\CoreEngine.V5\DataAccess\SqlReader.cs:line 121
   at App.CoreEngine.V5.DataAccess.DataContext.ExecuteQuery(PtQuery query, ValueStore`1 store, String readerDescription) in C:\SourceCode\AppV1\Releases\Libraries\CoreEngine\CoreEngine.V5\DataAccess\DataContext.cs:line 328
   at App.CoreEngine.V5.DataAccess.DataContext.<>c__DisplayClass12.<GetCalculatedDataForCompare>b__f(Object _) in C:\SourceCode\AppV1\Releases\Libraries\CoreEngine\CoreEngine.V5\DataAccess\DataContext.cs:line 267
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at App.CoreEngine.V5.DataAccess.DataContext.GetCalculatedDataForCompare() in C:\SourceCode\AppV1\Releases\Libraries\CoreEngine\CoreEngine.V5\DataAccess\DataContext.cs:line 276
   at System.Threading.Tasks.Task`1.InvokeFuture(Object futureAsObj)
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task`1.get_Result()
   at App.CoreEngine.V5.DataAccess.DataContext.get_CalcCompareData() in C:\SourceCode\AppV1\Releases\Libraries\CoreEngine\CoreEngine.V5\DataAccess\DataContext.cs:line 389
   at App.CoreEngine.V5.Calculation.CalculationEngine.Run() in C:\SourceCode\AppV1\Releases\Libraries\CoreEngine\CoreEngine.V5\Calculation\CalculationEngine.cs:line 243
   at App.CoreEngine.V5.Processor.Milestone.BatchRunner.Run() in C:\SourceCode\AppV1\Releases\Libraries\CoreEngine\CoreEngine.V5\Processor\Milestone\BatchRunner.cs:line 171

---> (Inner Exception #0) System.AggregateException: One or more errors occurred. 
---> System.Data.SqlClient.SqlException: Transaction (Process ID 89) was deadlocked on communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
   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 App.CoreEngine.V5.DataAccess.SqlReader.Read(String readerDescription) in C:\SourceCode\Releases\Libraries\CoreEngine\CoreEngine.V5\DataAccess\SqlReader.cs:line 121
   at App.CoreEngine.V5.DataAccess.DataContext.ExecuteQuery(PtQuery query, ValueStore`1 store, String readerDescription) in C:\SourceCode\AppV1\Releases\Libraries\CoreEngine\CoreEngine.V5\DataAccess\DataContext.cs:line 328
   at App.CoreEngine.V5.DataAccess.DataContext.<>c__DisplayClass12.<GetCalculatedDataForCompare>b__f(Object _) in C:\SourceCode\AppV1\Releases\Libraries\CoreEngine\CoreEngine.V5\DataAccess\DataContext.cs:line 267
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at CoreEngine.V5.DataAccess.DataContext.GetCalculatedDataForCompare() in C:\SourceCode\AppV1\Releases\Libraries\CoreEngine\CoreEngine.V5\DataAccess\DataContext.cs:line 276
   at System.Threading.Tasks.Task`1.InvokeFuture(Object futureAsObj)
   at System.Threading.Tasks.Task.Execute()

编辑 - 我只是仔细检查了发生了这个事件的服务器的dbcc 1222,我跑了dbcc tracestatus并得到了:

TraceFlag   Status  Global  Session
1222    1   1   0
3605    1   1   0

报告死锁的日志中没有任何内容

2 个答案:

答案 0 :(得分:9)

我的猜测是执行计划现在使用并行性,而在它没有达到成本阈值之前。

在查询中尝试MAXDOP 1

评论后编辑

您还需要跟踪标志1204.

TF 1222给出了死锁图,但是这个“通信缓冲资源”死锁可能没有涉及2个对象(我猜这里不是索引/表冲突)。见http://msdn.microsoft.com/en-us/library/ms178104.aspx

还有未记录的TF 1205,它为错误日志提供了更多信息

答案 1 :(得分:1)

您是否可以尝试以下任何一项: