1

I'm running into an issue in SQL Server 2005. A stored procedure is run in a PowerBuilder application, which then calls a C# DLL library which runs a different stored procedure.

The first procedure performs some deletes on a table based on the criteria, and the second procedure uses that table as the primary data source in order to insert into a different table. The procedures make use of some of the same joined tables for selecting, but only the one table is being modified.

The problem is this setup sometimes deadlocks, but SQL Server doesn't do anything about it. There are try / catch statements in the DLL library that would log an error if the procedure it calls was killed due to a deadlock, but instead the library just sits waiting for the procedure to finish. I've let it sit for 10 minutes and it's still deadlocked.

I tried using the DEADLOCK_PRIORITY LOW statement in the second procedure, since it needs to wait for the deletes to finish before it selects. I also tried paring that select statement down to only one table just to test it, and it still hits a deadlock. I also tried using a TRY / CATCH block with a BEGIN TRANSACTION in order to catch deadlocks in both procedures, but that didn't help either.

Is there a way to force SQL Server to kill a transaction if it's being blocked? I can handle errors in the DLL, but if SQL Server doesn't return an error and just sits there, I can't do anything with it. Thanks!

4

1 回答 1

2

我会看看这篇文章: http ://www.sql-server-performance.com/2006/reducing-locks/

它谈到了减少 SQL Server 锁,这可能是您的问题的一部分。我建议使用表格/页面上的锁定设置(PageLocks 开/关),看看这是否有助于解决这种情况。

与其尝试解决问题,不如尝试解决根本原因。

于 2012-04-10T16:31:43.937 回答