0

One of my co-workers has a stored procedure that does the following
Begin tran
1) Dynamically generate a select statement.
2) Insert into table x
3) Execute the select statement
End tran

If this stored procedure is ran by two septate threads simultaneously, he gets the following error: System.Data.SqlClient.SqlException: Transaction (Process ID 57) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction

Is this stored procedure really the issue? From my naive mind, this looks to be at worse a race condition, not a deadlock.

4

2 に答える 2

0

プロファイラーでトレースを実行し (空白のテンプレートを選択)、デッドロック グラフ イベントを選択し、表示される新しいタブ (イベント抽出設定) で、それぞれを独自のファイルに保存します (デッドロック XML イベントを個別に保存をチェックします)。このファイルを xml ビューアーで開くと、何が起こっているかを簡単に確認できます。各プロセスは、プロシージャ コールのスタックなどで含まれており、すべてのロックもそこにあるため、デッドロックの原因を確認できます。

デッドロックが再び発生するまでこのトレースを実行します。情報はデッドロックが発生したときにのみ記録されるため、オーバーヘッドはあまりありません。

于 2010-03-01T22:28:43.327 に答える