简体   繁体   中英

How do you combat deadlocks in a SQL Server database instance being accessed by NHibernate?

I'm working on a database that is suffering deadlocks. We are developing against the database using NHibernate. What are some of the common approaches to resolving the deadlocks we are seeing around specific tables?

The best solution, use stored procedures to control data access so that you can write the TSQL code directly. nHibernate can make calls to stored procedures just fine.

However, since that solution almost never flies, you can try treating the symptoms. First, make sure you have good indexes on the tables so that the queries that are being run from nHibernate perform as well as they can. Second, if you're on SQL SErver 2008+ use read committed snapshot isolation. That will make a huge difference in the locking and blocking you see, both of which lead to deadlocks.

On a side note, set the server to be Optimized For Ad Hoc Workload. This will radically help memory and procedure cache management.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM