- Error number
- 1222
- Severity
- 16 (user-correctable error)
- State
- 51 (row lock) or 56 (schema lock) (see the state table below)
- Product
- Microsoft SQL Server Database Engine
- Versions
- All supported SQL Server versions (2016 to 2025), Azure SQL Database, Azure SQL Managed Instance
- Category
- Concurrency & Locking
- Last reviewed
- 23 October 2026
On this page
What it means
Error 1222 means a statement waited for a lock longer than the session LOCK_TIMEOUT allows, so it gave up; another session is holding that lock.
By default a blocked statement waits as long as it takes. A session that has run SET LOCK_TIMEOUT n (n milliseconds) waits only that long and then raises 1222. The SET may come from an application, driver or tool rather than your own code. The cause is always another session holding a conflicting lock, usually inside a transaction that has not committed yet. Nothing was chosen as a victim, unlike a deadlock (error 1205): the other session simply carries on.
Only the statement that timed out is cancelled. In our tests an open transaction stayed open (@@TRANCOUNT 1, XACT_STATE() 1), so code that carries on and commits will commit the earlier statements without the failed one. Roll back in your error handler, or use SET XACT_ABORT ON. The state number tells you roughly what kind of lock was awaited (see the table), but the fix is the same: find the blocker.
| State | Meaning |
|---|---|
| 51 | Reproduced on SQL Server 2025: the statement waited for a row (key) lock held by another session, for example a SELECT or UPDATE behind an uncommitted UPDATE. |
| 56 | Reproduced on SQL Server 2025: the statement waited for a schema lock, for example a SELECT on a table that another session altered inside an open transaction. |
Common causes
- Another session holds locks in a long or forgotten open transaction, for example a query window with BEGIN TRANSACTION and no COMMIT.
- A long-running UPDATE, DELETE, index rebuild or ALTER TABLE holds locks on rows or on the whole table.
- Missing indexes make statements scan and lock far more rows than they need, so they collide more often.
- The session LOCK_TIMEOUT is set very low (or to 0) by the application, a driver or a tool, so even short waits fail.
Diagnose it
Read-only These queries only read metadata and dynamic management views. They do not change data, permissions or configuration, so they are safe to run first.
Who is blocked, and by whom?
SELECT r.session_id, r.blocking_session_id, r.wait_type, r.wait_time AS wait_ms,
r.wait_resource, r.command, DB_NAME(r.database_id) AS database_name,
t.text AS running_sql
FROM sys.dm_exec_requests AS r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
WHERE r.blocking_session_id <> 0; Each waiting request with the session that blocks it. Run it while the problem is happening; once your statement has timed out it no longer appears. Wait types starting LCK_M_ are lock waits.
What is the blocking session doing?
Replace 57 with the blocking_session_id from the first query. A blocker with status sleeping and an open transaction is usually an uncommitted transaction left in an application or a query window.
SELECT s.session_id, s.login_name, s.host_name, s.program_name, s.status,
s.open_transaction_count, s.last_request_end_time, ib.event_info AS last_sql
FROM sys.dm_exec_sessions AS s
OUTER APPLY sys.dm_exec_input_buffer(s.session_id, NULL) AS ib
WHERE s.session_id = 57; Who and what holds the lock: login, machine, application, how many transactions it has open and the last statement it sent.
Which locks are being waited for?
SELECT tl.request_session_id, tl.resource_type, tl.resource_description,
tl.request_mode, tl.request_status,
OBJECT_NAME(p.object_id) AS object_name
FROM sys.dm_tran_locks AS tl
LEFT JOIN sys.partitions AS p ON p.hobt_id = tl.resource_associated_entity_id
WHERE tl.resource_database_id = DB_ID()
AND tl.request_status = N'WAIT'; The resource (KEY, PAGE, OBJECT, METADATA) and lock mode each blocked session wants. Run it in the affected database.
What lock timeout does this session use?
SELECT @@LOCK_TIMEOUT AS lock_timeout_ms; -- -1 means wait for ever (the default) A small positive value, or 0, means the application chose to fail fast. Find where it is set (connection code, ORM settings, tools) before changing it.
How to fix it
Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.
Ask the blocking session to commit or roll back
Read-onlyUse the second diagnostic to find who holds the lock. Very often it is an open query window or a stalled application call; committing or rolling back there releases the lock at once, then rerun your statement. Microsoft gives the same order: find the holder, end that transaction if appropriate, rerun.
Handle 1222 in code: roll back, then retry or report
Client or network sideBecause the transaction stays open after 1222, roll it back in the error handler. Retrying after a short pause is reasonable when the blocking is brief; otherwise report a clear "busy, try again" message.
SET XACT_ABORT ON; -- any error rolls back the whole transaction
SET LOCK_TIMEOUT 5000;
BEGIN TRY
BEGIN TRANSACTION;
UPDATE dbo.Accounts SET balance = balance - 100 WHERE id = 1;
COMMIT TRANSACTION;
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION;
THROW; -- the caller can retry on ERROR_NUMBER() = 1222
END CATCH;
Shorten transactions and add the indexes they need
Changes schemaLocks are held until the transaction ends, so keep transactions small and commit promptly; never wait for user input inside one. An index on the columns in WHERE clauses lets statements lock only the rows they touch instead of scanning. Test new indexes on a copy first: they add work to every write.
CREATE INDEX IX_Orders_status ON dbo.Orders (status);
Use row versioning so readers do not wait for writers
Changes configurationWith READ_COMMITTED_SNAPSHOT on, ordinary READ COMMITTED reads use the last committed row version and no longer wait for row locks held by writers. It does not help writers waiting for writers, or anyone waiting behind schema changes.
Caution: This changes how every READ COMMITTED query in the database behaves (reads may return the previous committed version instead of waiting) and adds version store usage. Test the application first. The ALTER needs to be the only active connection in the database and waits until it is.
ALTER DATABASE AppDb SET READ_COMMITTED_SNAPSHOT ON;
Last resort: end the blocking session with KILL
Changes database stateOnly when the blocker is clearly abandoned, its owner cannot be reached, and the blocking is hurting other users. Identify it first with the diagnostics above. Raising LOCK_TIMEOUT is the other blunt option: it trades the error for longer waits and does not remove the blocking.
Caution: KILL rolls back all uncommitted work of that session, which can take as long as the work itself and keeps holding locks while it rolls back. Never kill a session you have not identified (system sessions, jobs, replication or other applications), and tell its owner.
-- After identifying the blocker (replace 57 with its session_id)
KILL 57;
Examples
A read waits behind an uncommitted UPDATE
-- Setup
CREATE TABLE dbo.Accounts (id INT PRIMARY KEY, balance DECIMAL(12,2) NOT NULL);
INSERT INTO dbo.Accounts (id, balance) VALUES (1, 500), (2, 500);
-- Session 1: holds an exclusive lock on row 1 for 5 seconds
BEGIN TRANSACTION;
UPDATE dbo.Accounts SET balance = balance - 100 WHERE id = 1;
WAITFOR DELAY '00:00:05';
COMMIT TRANSACTION;
-- Session 2, started while session 1 is waiting
SET LOCK_TIMEOUT 2000; -- give up after 2 seconds
SELECT id, balance FROM dbo.Accounts WHERE id = 1;
Msg 1222, Level 16, State 51, Line 2 Lock request time out period exceeded.
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
An UPDATE times out and the transaction stays open
-- Setup: as above, plus
CREATE TABLE dbo.AuditLog (id INT IDENTITY PRIMARY KEY, note NVARCHAR(100) NOT NULL);
-- Session 1: the same 5 second UPDATE of row 1 as above
-- Session 2
SET LOCK_TIMEOUT 2000;
BEGIN TRANSACTION;
INSERT INTO dbo.AuditLog (note) VALUES (N'adjust account 1');
UPDATE dbo.Accounts SET balance = 0 WHERE id = 1; -- times out
SELECT @@TRANCOUNT AS open_transactions, XACT_STATE() AS xact_state;
ROLLBACK TRANSACTION; -- without this the INSERT could still be committed
Msg 1222, Level 16, State 51, Line 4 Lock request time out period exceeded. The statement has been terminated. open_transactions xact_state ----------------- ---------- 1 1
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
Waiting behind an uncommitted ALTER TABLE (schema lock)
-- Session 1: a schema change left inside an open transaction
BEGIN TRANSACTION;
ALTER TABLE dbo.Accounts ADD note VARCHAR(50) NULL; -- holds a schema modification lock
WAITFOR DELAY '00:00:05';
ROLLBACK TRANSACTION;
-- Session 2: even a read of a different row must wait
SET LOCK_TIMEOUT 1000;
GO
-- A separate batch: in our test, a SELECT that needed compiling in the same batch
-- as the SET waited for the schema lock with no timeout at all.
SELECT id, balance FROM dbo.Accounts WHERE id = 2;
Msg 1222, Level 16, State 56, Line 3 Lock request time out period exceeded.
Reproduced on SQL Server 2025 (17.0.1145.4), 23 October 2026.
How to prevent it
Keep transactions short, commit promptly and never leave one open across user interaction; in SSMS, check the transaction count before walking away from a query window. Index the columns used to find rows so statements lock only what they change, and run schema changes and large maintenance in quiet periods.
If your application sets LOCK_TIMEOUT, handle 1222 explicitly: roll back, then retry or report. Monitor blocking (the first diagnostic, or the blocked process report) so you find long lock holders before users do. Do not switch to NOLOCK to avoid the error: it reads uncommitted and sometimes duplicated or missing rows. See transactions, locks and deadlocks.
Common questions
Does error 1222 roll back my transaction?
No. Only the statement that timed out is cancelled; in our test the transaction was still open and committable afterwards. Roll back in your error handler or use SET XACT_ABORT ON.
I never set LOCK_TIMEOUT. Why do I get 1222?
Something else on that connection did: a driver or ORM setting, a tool, or code that ran earlier on the same connection. SELECT @@LOCK_TIMEOUT shows the value your session is using; -1 means wait for ever.
What is the difference between error 1222 and error 1205?
Error 1222 is a single statement giving up after waiting too long; nobody was killed and the blocker keeps running. Error 1205 is a deadlock: SQL Server found a circle of waits and rolled back one whole transaction.
Learn more on CodeWithSQL
- Transactions, locks and deadlocks
- SQL transactions and ACID explained
- How SQL indexes improve performance
Official documentation
- MSSQLSERVER_1222 (Microsoft Learn)
- SET LOCK_TIMEOUT (Transact-SQL)
- Understand and resolve blocking problems (Microsoft Learn)
- Transaction locking and row versioning guide
Last technically reviewed 23 October 2026; examples and diagnostics run on SQL Server 2025 (17.0.1145.4). Message text checked against the engine's sys.messages catalogue.