SQL Server error 997, "failed to get the update lock on," is a concurrency error, not a corruption or disk failure. It means a session tried to acquire an update (U) lock on a resource — usually a row or page — and the lock manager could not grant it within the allowed time, often because another session already holds a conflicting lock or because lock escalation and memory pressure have made the lock request wait too long. The fastest working fix is to identify the blocking session with sp_who2 or the sys.dm_exec_requests DMV, then either let the blocking transaction finish, kill it if it is idle and abandoned, or reduce the lock footprint by shortening transactions and adding proper indexes. The steps below walk through diagnosis, safe resolution, and prevention.
What You'll Need
- SQL Server Management Studio (SSMS) or Azure Data Studio connected with a login that has
VIEW SERVER STATEpermission (sysadmin or a monitoring role). - The name of the database and, if possible, the table or query that raised the error.
- The ability to open a second query window — you should never troubleshoot blocking from the same session that is blocked.
- A maintenance window if you may need to kill a session or restart the SQL Server service; killing a session rolls back its open transaction, which can take time on large updates.
Step-by-Step
- Confirm the error is current. Reproduce the failing statement in a new query window with the same login. If it now succeeds, the blocking transaction has already ended and you are looking at a historical event. Check the SQL Server error log and, if configured, the system_health Extended Events session for the exact timestamp before going further.
- Find the blocking chain. In a new query window run
EXEC sp_who2;and look for rows with a non-zeroBlkByvalue. The session inBlkByis the head blocker. For more detail, querysys.dm_exec_requestsjoined tosys.dm_exec_sessionsand filter onblocking_session_id <> 0. Note thesession_id,wait_type,wait_time, andcommandof the head blocker. - Inspect what the head blocker is doing. Use
DBCC INPUTBUFFER(session_id);to see the last statement sent by that session, and querysys.dm_tran_locksfiltered on the same session to see which object and resource it holds. If the blocker is a longUPDATEorDELETE, the update lock conflict is expected and the fix is to wait or to shorten the transaction. - Decide whether to wait or intervene. If the blocking session is actively running a legitimate batch, let it finish. If it is sleeping with an open transaction (
status = 'sleeping'andopen_transaction_count > 0), it is an abandoned transaction from an application that did not commit or roll back — this is the classic cause of error 997. That session should be killed. - Kill the abandoned session only after checking the cost. Run
KILL session_id;. Be aware that killing a session with an open transaction triggers a rollback, which can take as long as the original work and will hold locks until it completes. Do not kill sessions running critical jobs without confirming with the application owner. - Reduce lock escalation pressure. If the error recurs on large updates, break the statement into batches (for example, update 5,000 rows at a time in a loop with a commit between batches) so SQL Server does not escalate row or page locks to a table lock. Also verify that the statement's
WHEREclause is supported by an index; a scan on a large table takes far more locks than a seek. - Check for a stuck distributed transaction. If the blocking session is waiting on a distributed transaction coordinator (DTC) resource, review the DTC status and the application's transaction handling. Error 997 can appear when a transaction remains unresolved; resolving or restarting the DTC service (with the application stopped) is the usual remedy.
- Verify the fix. Re-run the original statement and confirm it completes. Then re-check
sp_who2to ensure no blocking chain remains, and monitor the error log for a day to confirm the error does not return.
Common Mistakes
- Killing the blocked session instead of the head blocker — the block simply moves to the next waiting session.
- Killing a session with a large open transaction without allowing for rollback time; the locks stay held until rollback finishes.
- Adding
NOLOCKhints everywhere as a "fix." That hides the symptom, allows dirty reads, and does not address the abandoned transaction or missing index. - Assuming error 997 means disk or memory failure and restarting the server. A restart clears the symptom but loses the diagnostic evidence; capture the blocking chain first.
- Ignoring application-side connection pooling bugs that leave transactions open when a request times out.
Tips
- Set a sensible
LOCK_TIMEOUTon reporting or batch sessions so they fail fast instead of piling up behind a blocker. - Keep transactions as short as possible: do the data retrieval first, then open the transaction, modify, and commit immediately.
- Enable the
blocked process thresholdconfiguration so SQL Server can raise a blocked-process report you can alert on. - Use Extended Events to capture
lock_deadlockandlock_timeoutevents with the actual statement text for post-incident review. - Review indexes on tables that receive frequent updates; missing indexes on foreign keys and filter columns are a common source of wide lock coverage.
Troubleshooting
If killing the head blocker does not clear the error, check whether the blocking session ID has changed — a new session may have taken over the same lock. Query sys.dm_tran_locks by resource rather than by session to see every holder of the object. If the blocker is a system process (for example, a replication agent or a backup), stop that process cleanly rather than killing it. If the error appears immediately on a single statement regardless of other activity, examine the execution plan for a table scan or a missing index, and check whether the table has a large number of rows being updated in one transaction. If the error only appears under load, look for lock escalation by checking sys.dm_db_index_operational_stats for index_lock_promotion_attempt_count. If you cannot identify the blocker with the DMVs, take a live snapshot with sp_whoisactive if it is installed, or capture a brief Extended Events session on lock_timeout. Finally, if the problem persists after all of the above, engage the application team: the root cause is usually a transaction that is opened and not closed, and no amount of server-side tuning will fix that.
Frequently Asked Questions
Is error 997 a deadlock?
No. A deadlock is detected automatically and one session is chosen as the victim (error 1205). Error 997 is a lock request that timed out or could not be granted, typically because another session held a conflicting lock for too long.
Does error 997 damage data?
No. The statement that failed is rolled back, and the database remains consistent. The risk is to application logic that does not handle the error and retry.
Can I prevent it by using READ COMMITTED SNAPSHOT isolation?
It can reduce reader-writer blocking, but it does not prevent two writers from conflicting on the same row. It is a useful mitigation, not a cure for abandoned transactions.
Why does the error mention an "update lock" specifically?
Update locks are taken when a session reads a row with the intent to modify it. They are compatible with shared locks but not with other update or exclusive locks, so they are often the first lock to fail when two sessions target the same rows.
Should I restart SQL Server to clear it?
Only as a last resort. Restarting clears all sessions and locks but destroys the diagnostic evidence and interrupts every other user. Capture the blocking chain first.
Does the error appear in Azure SQL Database too?
Yes, the same locking behavior applies, but you cannot use KILL on system sessions and some DMVs are restricted. Use the Query Store and the portal's performance tools to identify the blocking query.