如何自动重新运行僵持交易? (ASP.NET MVC / SQL服务器) [英] How to automatically re-run deadlocked transaction? (ASP.NET MVC/SQL Server)

查看:100
本文介绍了如何自动重新运行僵持交易? (ASP.NET MVC / SQL服务器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET MVC / SQL Server的一个非常受欢迎的网站,可惜很多死锁发生。虽然我想,为什么他们通过SQL事件探查器发生弄清楚,我不知道这样做的死锁时,我如何更改SQL Server的默认行为。

I have a very popular site in ASP.NET MVC/SQL Server, and unfortunately a lot of deadlocks occur. While I'm trying to figure out why they occur via the SQL profiler, I wonder how I can change the default behavior of SQL Server when doing the deadlocks.

是否有可能重新运行导致交易(S)问题,而不是显示错误屏?

Is it possible to re-run the transaction(s) that caused problems instead of showing the error screen?

推荐答案

您正在找错了树。你将永远不会成功通过SQL引擎做自动化的死锁重试,这样的观念是根本错误的。僵局的定义本身就是国家您基于你的决定具有的修改的,因此你需要再次读取状态并作出新的决定。如果你的进程已经陷入僵局,顾名思义另一进程的荣获的死锁,它MEAS它的改成的东西你读过。

You are barking up the wrong tree. You will never succeed in doing automated deadlock retries by the SQL engine, such concept is fundamentally wrong. The very definition of deadlock is that the state you base your decision on has changed therefore you need to read again the state and make a new decision. If your process has deadlocked, by definition another process has won the deadlocks, and it meas it has changed something you've read.

您的重点应该是在为什么死锁发生,消除病因搞清楚。不变的是,事业就会变成是扫描更多的数据,他们应该查询。虽然是事实,其他类型的僵局可能发生,我的选择是不是你的情况。许多问题将通过部署适当的索引来解决。有些问题会送你回到绘图板,你将不得不重新考虑你的要求。

Your only focus should be at figuring out why the deadlocks occur and eliminate the cause. Invariably, the cause will turn out to be queries that scan more data that they should. While is true that other types of deadlock can occur, I bet is not your case. Many problems will be solved by deploying appropriate indexes. Some problems will send you back to the drawing board and you will have to rethink your requirements.

有很多很多的资源在那里就如何识别和解决死锁:

There are many, many resources out there on how to identify and solve deadlocks:

  • Detecting and Ending Deadlocks
  • Minimizing Deadlocks

您也可以考虑使用快照隔离,因为无锁读取参与快照减少可能发生死锁表面(即只写 - 写死锁可能发生)。请参见使用基于行版本控制的隔离级别的。

You may also consider using snapshot isolation, since the lock-free reads involved in snapshot reduce the surface on which deadlocks can occur (ie. only write-write deadlocks can occur). See Using Row Versioning-based Isolation Levels.

这篇关于如何自动重新运行僵持交易? (ASP.NET MVC / SQL服务器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆