Skip to main content

How to Determine Who Has a Table Locked in Microsoft Dynamics NAV

How to Determine Who Has a Table Locked in Microsoft Dynamics NAV

I recently fielded a support call from a frantic customer that went something like this: “Help! Nobody can post anything! All we get is a message that Item Ledger Entry is locked by another user! AAAAAAHHH!!!”
Very useful. The system knows enough to realize there is a block, but won’t bother to tell you which user is causing the problem. The usual fix is to restart the service tier, SQL service, or to reboot the whole SQL server.
Why yes, as a matter of fact, everyone would love to stay an extra 20 minutes late today because of a server reboot. Awesome!
If you’re looking for a better alternative, there are two ways of figuring out who has the lock. You can do so from inside of NAV depending on the version, or you can tell from SQL regardless of the version.

Finding the Guilty Party from Inside NAV

If you are using Version 4.0 through 2009 R2 (it went away in 2013), then you can use Database Sessions. (I did not have a SQL version for 3.x or older handy – it may work in versions older than 4.)
     File Menu, Database, Information; Sessions Tab
Screenshot: View of the Database Sessions Information window
Figure 1 – View of the Database Sessions Information window
Drill down in the Current Sessions field.
Screenshot: Drilldown to the Current Database Sessions field to view all open sessions, including blocking sessions and users
Figure 2 – Drilldown to the Current Database Sessions field to view all open sessions, including blocking sessions and users
The column Blocked will show which user(s) are blocked, and the Blocking User ID will identify the culprit. You can also use the Blocking Connection ID – match that to the Session ID shown in this list, and you can tell which workstation the user is on. This is useful if you have multiple people using shared accounts.

Finding the Guilty Party from SQL Server

Start SQL Server Management Studio (SSMS). Find the database, then right-click and choose New Query.
In the query window, type
     exec sp_who2
Execute that.
Screenshot: Execute the 'exec sp_who2' query from within SQL Server Management Studio (SSMS)
Figure 3 – Execute the “exec sp_who2” query from within SQL Server Management Studio (SSMS)
This gives a dump of all current user activity. There is a column called BlkBy, which stands for Blocked By. That gives you the SPID (SQL Process ID) of the person blocking. Find that entry for the BlkBy SPID in this list, and now you know the user.

Now What?

Try not to go all angry-mob-with-pitchforks-and-torches. I’m sure this was not intentional. Try calling the user first so you can find out what they are currently doing, and ask them to exit NAV. Knowing what the person was trying to do can be very useful if this becomes a chronic problem. There can be lots of causes – flaky network connections, code problems because of poor specifications (NAV developers do not make mistakes!), or a workstation crashed and kept the NAV connection open.
If the user is not able to exit NAV, you have two options.
Inside NAV
Find the Session ID that holds the blocking lock
F4 (Delete) on that Session record
This terminates the connection and rolls back the SQL transaction.
From SQL
Once you know the SPID shown in the BlkBy column, you can use this TSQL query command to kill it:
Kill <SPID>
This will also cause a rollback of the locking transaction.
If you found this blog helpful, be sure to check out our other blogs written specifically for NAV developers at https://dandikairo.blogspot.ug


Comments

Comment: 
Dear Kyle,
In "Inside NAV" section, you said that "Find the Session ID that holds the blocking lock". How we do that? Session ID is not same with spid, is it?
If we kill spid in blkby with sql query, does it also rollback all the transactions that use a different spid?
Thank in advance.
Best Regards,
Kairo Dan Okello

Comments

Popular posts from this blog

Quick Fix Visual Studio displaying NAV Report Layout as XML

I got this issue with Visual Studio 2015 Enterprise Edition.  Every time I open a Dynamics NAV report layout in Visual Studio, RDLC is rendered as XML file instead of visual layout with all the fields and tool boxes.  How the report layout looks:  FIX : In order to fix the issue you need to install  "Microsoft SQL Server Data Tools" .  To install "Microsoft SQL Server Data Tools" you need to go to  Control Panel   ->  Programs and Features  - >  Microsoft Visual Studio <Edition>  -> Change Or you can re run the installation setup.  From the features list, enable "Microsoft SQL Server Data Tools" option and proceed.  Once the installation is completed you are good to go. This time report layout will open in correct design layout.  Hope this helps you to resolve the issue. happy designing.  Please provide your feedback with a comment.  Thank you and Regards, +256775120005 Kairo Okello Dan ERP Solutions Consultant

The Difference Between Microsoft Dynamics NAV and AX

The Difference Between Microsoft Dynamics NAV and AX Microsoft Dynamics offers a variety of ERP solutions. You might say there is a solution for every purpose and every industry. Two of the offerings,  Dynamics NAV  and  Dynamics AX (now part of  Dynamics 365 ) share some of the same features so you might wonder: ‘what are the differences and which is right for my organization?’ Both ERP solutions are highly customizable, available in and adaptable to many languages and currencies used around the world. The two solutions can also be employed in a central location or across diverse satellite locations and are designed to grow as a business grows. Their industry-specific functionality can assure compliance with local and regional requirements. In short, both solutions could rightly be described as comprehensive and well equipped to manage complex requirements of supply chain and inventory. So, what is the difference? Is one better than the other for your particular organiz

How to install a Microsoft Dynamics NAV cumulative update

How to install a Microsoft Dynamics NAV 2018 cumulative update Introduction This article describes how to install a cumulative update for Microsoft Dynamics NAV 2018. You have to recompile all objects after you install a cumulative update. A cumulative update is a cumulative set of files that includes all hotfixes and regulatory features that have been released for Microsoft Dynamics NAV 2018. A cumulative update includes files that are separated into the following folders: APPLICATION DVD See  Upgrading the Data to Microsoft Dynamics NAV 2018  for details. How to install the cumulative update files APPLICATION The APPLICATION folder includes the following files: AccumulatedChangeLog.<Locale>.<Build No.>.txt Changelog.<Locale>.<Build No.>.txt CUObjects.<Locale>.<Build No.>.fob Objects.<Locale>.Objects.<Locale>.<Build No.>.txt To install the application files, follow these