问题描述
Hello Everyone,
Hello Everyone,
我遇到了死锁异常。返回此异常的查询对于运行很重要。我怎么能处理这个例外。我有一个方法来重新运行查询。像这样重新运行是好的吗?
I am stuck with deadlock exceptions. The query that is returning this exception is important to run. How i can handle this exception. I got a method to re-run query. is it good to re-run like this ?
int retry= 5;
bool ok = false;
while (retry > 0 && !ok)
{
try
{
Thread.Sleep(100);
sqlDataReader = sqlCommand.ExecuteReader();
ok= true;
}
catch (SqlException exp)
{
if (exp.Number != 1205)
{
MessageBox.Show(exp.Message.ToString() ,"Exc Code1");
}
Thread.Sleep(500);
retry--;
if (retry== 0)
MessageBox.Show(exp.Message.ToString() ,"Exc Code2");
}
}
如果有其他方法可以更好地处理它。请为我推荐
If some other method to handle it better. Please suggest for me
推荐答案
https://www.mssqltips.com/sqlservertip/2470/understanding-the-sql-server-nolock-提示/
https://www.mssqltips.com/sqlservertip/2470/understanding-the-sql-server-nolock-hint/
但是,如果有其他应用程序使用不使用该提示的同一个表,则无效。
However, it does no good if there are other applications that are using the same table that doesn't use the hint.
这篇关于事务(进程ID 61)在锁资源上与另一个进程发生死锁,并被选为死锁牺牲品。重新运行该交易。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!