Achilles
Achilles

Reputation: 11309

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?

Upvotes: 4

Views: 275

Answers (1)

Grant Fritchey
Grant Fritchey

Reputation: 2785

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.

Upvotes: 2

Related Questions