We regularly get long periods of time where the sales line table will be locked. Earlier today there was about an hour period where the table was intermittently locked stopping users form entering anything in the sales line.
Does anyone have any tips on how you to easily identify which user is causing the table lock? It would be good to find out what the user / users were doing to cause the lock.
Use SQL Management Studio/or Visual Studio Code with SQL Vsix-file:
SELECT DISTINCT
name AS database_name,
session_id,
host_name,
login_time,
login_name,
reads,
writes
FROM sys.dm_exec_sessions
LEFT OUTER JOIN sys.dm_tran_locks ON sys.dm_exec_sessions.session_id = sys.dm_tran_locks.request_session_id
INNER JOIN sys.databases ON sys.dm_tran_locks.resource_database_id = sys.databases.database_id
WHERE resource_type <> ‘DATABASE’
–AND request_mode LIKE ‘%X%’
–AND name =‘YourDatabaseNameHere’
ORDER BY name
use [Demo Database 365BC]
select spid,cmd,waittime,lastwaittype,cpu,physical_io,login_time,last_batch,status,hostname,program_name,nt_username, nt_domain
from master.dbo.sysprocesses where dbid = db_id(’[Demo Database 365BC]’)