Sql-server – How else to troubleshoot LCK_M_U from SQL Server

lockingsql server

We have an INSERT statement coming from an Entity Framework application that has been causing pretty large blocking chains. The Wait Time and Wait Type in our monitoring tools for that process is empty, so it doesn't look like it's waiting on anything. This makes me believe that the application is opening a transaction, doing an insert and just not committing it.

This has been an intermittent issue so it's been hard to troubleshoot. Development team is looking into the code but insistent that nothing has changed. What else can I look at on the SQL Server side?

SQL Server 2012 SP2

Best Answer

Do you know exactly what the INSERT statement is and what line of EF code generates it? Just wrap whatever calls that around some logging code and log all the SQL to a text file (preferably using log4net, nlog, ETW etc.

Just wrap the code that calls the insert code with a call to set and unset the delegate described here.

e.g.

 ctx.Database.Log = (dbLog => log.Debug(dbLog));
// Do the insert
ctx.Database.Log = null;

Honestly, if you can deal with a slight slowdown in performance, and have the disk space just log everything. I log all the SQL in my Always Encrypted Sample app.

Assuming your INSERTS are wrapped around transactions, you should be able to see that instantly with this. Make sure your logging has timestamps so you can see how long the transaction remains open for.