Patterns for handling a SQL deadlock in C#?

后端 未结 2 1478
没有蜡笔的小新
没有蜡笔的小新 2021-02-19 06:49

I\'m writing an application in C# which accesses a SQL Server 2005 database. The application is quite database intensive, and even if I try to optimize all access, set up proper

2条回答
  •  醉梦人生
    2021-02-19 07:46

    Here is the approach we took in the last application framework I worked on. When we detected a deadlock, we simply reran the transaction. We did this up to 5 times. If after 5 times it failed, we would throw an exception. I don't recall a time that the second attempt ever failed. We would know because we were logging all activity in the backend code. So we knew any time a deadlock occurred, and we knew if it failed more than 5 times. This approach worked well for us.

    Randy

提交回复
热议问题