我正在使用.Net窗口工具
运行类似 -SELECT * FROM Table1 WHERE ID = id
的查询
如果它包含任何记录,我正在执行包含以下行的存储过程[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作业是.Net窗口工具的多线程,用于不同的ID。