0

我正在运行一个查询,例如 - SELECT * FROM Table1 WHERE ID = id从 .Net 窗口工具,

如果它包含任何记录,我正在执行一个[usp_DeleteTableData]包含以下行的存储过程:

DELETE FROM Table1  WHERE ID = @id
DELETE FROM Table2  WHERE ID = @id
DELETE FROM Table3  WHERE ID = @id
DELETE FROM Table4  WHERE ID = @id
DELETE FROM Table5  WHERE ID = @id
DELETE FROM Table6  WHERE ID = @id
DELETE FROM Table7  WHERE ID = @id

我面临死锁问题,例如:

2013-11-13 16:06:12,787 [10] INFO  MigrateInfo.Data Exception while running the sql query :EXEC [usp_DeleteTableData] 'AAAAAAABBBBBBBQWE'

2013-11-13 16:06:12,787 [10] FATAL MigrateInfo.Data System.Data.SqlClient.SqlException (0x80131904): Transaction (Process ID 63) was deadlocked on lock | 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, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at MigrateInfo.Data.Command(String sql) in d:\PROJECTS\Data.cs:line 67
ClientConnectionId:c18a9bf8-19f3-4417-908f-33c48b26df14

我需要一些帮助来将查询和存储过程语句保存在一个带有LOCKING implemented. 这样它将检查“ID”的存在,然后继续删除,而不会出现死锁。

信息 - 我没有使用任何锁定

如果我需要提供更多信息,请告诉我。

编辑

SELECT - DELETE 作业是来自不同 ID 的 .Net 窗口工具的多线程。

4

0 回答 0