Troubleshooting SQL Locks

SQL Locking is one of the most frustrating and misunderstood issues you will encounter when dealing with SQL Server.  One good tool for getting a handle on this is SQL Profiler.  There is a blocked process event that it can monitor but it must first be enabled.  To enable SQL blocked process monitoring, use the sp_reconfigure command:

sp_configure 'show advanced options', 1  
RECONFIGURE
GO
sp_configure 'blocked process threshold', 10
GO
RECONFIGURE
GO

The blocked process threshold needs to be set because blocking happens quite frequently and it's up to you to determine when it becomes a problem.  This is typically going to be right around the time the application times out and the user gets an error message.  Once this is enabled, you can use the SQL Profiler tool to collect locking events.



I will typically take out the SQL statement and procedure events, since these tend to bloat the file and generate a lot of static during long traces.  If you have a situation where you can re-create a lock and need to find detailed information about that specific instance, you will want the SQL statements and procedures.

After a trace has been running for a few hours, you can start to see where your problems are coming from.  At that point, you can begin to focus on the code that might produce the queries that are causing locks and create indexes or optimize the code.


Comments

Popular posts from this blog

Accessing Dynamics NAV OData with Postman

When you are falsely accused of not having SQL Server Report Builder installed

Error with Zetadocs on Sharepoint Online