Here are my thoughts on this.
From a ColdFusion server server
I really believe that using <cflock> tags around your ColdFusion code that updates the database can prevent the deadlock problem on the database server. Using a named lock will make every call single-threaded. However, you can use server-side timeouts on ColdFusion, waiting for <cflock> if transactions take some time. Such handling of the ColdFusion server can also slow down the application. You can perform stress testing before and after to see how this method affects your application.
From the server side of the database
First of all, let me say that I do not think that deadlocks on the database server can be completely prevented, just minimized and handled accordingly. I Found This Link For TechNet For You - Minimize Lock . First sentence from this page:
Although deadlocks cannot be completely eliminated, the following coding rules can minimize the likelihood of deadlocks.
Here are the key points of this link. They describe each topic in detail, so please read the source.
Minimizing deadlocks can increase transaction throughput and reduce system overhead because there are fewer transactions:
- Rollback that cancels all the work performed by the transaction.
- It is repeated by applications because they were discarded during blocking.
To minimize deadlocks:
- Access objects in the same order.
- Avoid user interaction in transactions.
- Keep transactions short and in one batch.
- Use lower isolation.
- Use row-based isolation level.
- Set the READ_COMMITTED_SNAPSHOT database parameter to ON to enable fixed transaction transactions to use row versioning.
- Use snapshot isolation.
- Use linked connections.
"Version-based row-based isolation level" may answer your question. Or is there a way to ask SQL Server to lock a row instead of a table ?. This source has some notes mentioned in the original source.
Here are some other links that appeared during my search:
Prevent deadlocks with the NOLOCK hint
How to avoid sql deadlock?
Tips to avoid deadlocks? - In this mention of how careful you are when using the NOLOCK tooltip.
Deadlock Difficulty
Using isolation levels based on version version
Miguel-f
source share