Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 1220: Fix No More Lock Classes

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server error 1220 ("No more lock classes available from transaction") means a single transaction has exhausted the server's fixed pool of lock class slots. The immediate fix is to find and stop the runaway transaction, then reduce the number of distinct objects it touches. You cannot raise the limit with a configuration option, so the real work is identifying the offending query and rewriting it to acquire fewer lock classes at once.

What You'll Need

  • Access to SQL Server Management Studio (SSMS) or Azure Data Studio, connected with a login that can view server state (for example, a member of the sysadmin or processadmin role, or a login granted VIEW SERVER STATE).
  • The name of the database and, if possible, the application or job that triggered the error.
  • Permission to kill a session (ALTER ANY CONNECTION or sysadmin) if a blocking transaction must be stopped.
  • A maintenance window if the fix requires changing application code or indexing.

Step-by-Step

  1. Confirm the error text and capture the context. In SSMS, open a new query window and run SELECT @@VERSION; to note the build. Then check the SQL Server error log (Object Explorer > Management > SQL Server Logs) or the application log for the exact message and the session ID (SPID) that raised it. Write down the SPID and the time; you will need them in the next steps.
  2. Look for long-running or highly active transactions. Run SELECT session_id, transaction_id, transaction_begin_time, transaction_type, transaction_state FROM sys.dm_tran_active_transactions; joined to sys.dm_tran_session_transactions to see which sessions have open transactions. Sort by transaction_begin_time to spot the oldest, which is usually the culprit.
  3. Inspect the statement that is running. Query sys.dm_exec_requests joined to sys.dm_exec_sql_text for the SPID you found. Look at the sql_text column. Error 1220 almost always comes from a statement that touches a very large number of distinct objects in one transaction, such as a huge IN list, a cursor looping over thousands of tables, or dynamic SQL that references many partitions or schemas.
  4. Stop the runaway transaction if it is still active. Use KILL <spid>; with the SPID from step 1. This rolls back the transaction and releases its lock classes. Only do this after confirming the session is the one that raised the error; killing an unrelated session can interrupt other users. If the session is a system process or a replication agent, stop the corresponding job or agent instead.
  5. Identify the object pattern. If the statement is dynamic SQL, capture the generated text. If it is a stored procedure with a loop, review the loop. Count how many distinct tables, views, or partitions the transaction references. The lock class limit is per transaction, so a transaction that opens thousands of cursors or builds a massive UNION ALL across many objects will hit it.
  6. Rewrite the transaction to use fewer lock classes. Common fixes: split one large transaction into several smaller ones that commit between batches; replace a cursor over many objects with a single set-based query; reduce the number of partitions touched by adding a filter on the partitioning column; and avoid dynamic SQL that concatenates thousands of object names. If the application uses an ORM, check whether it is generating one statement per row; batch those statements.
  7. Review indexing and statistics on the affected tables. Missing indexes can cause a query to scan many partitions or objects, increasing lock classes. Run DBCC SHOW_STATISTICS on the key tables and update statistics with UPDATE STATISTICS <table>;. Create any missing indexes suggested by the actual execution plan, but test in a non-production environment first.
  8. Check for triggers and foreign keys. A trigger that fires per row and touches many tables multiplies lock classes. Review trigger logic and consider set-based triggers. Foreign keys with cascading actions across many child tables can also add lock classes per statement; verify the schema and adjust if necessary.
  9. Restart the SQL Server service only as a last resort. If the transaction cannot be killed and the instance is unresponsive, a service restart clears all lock classes, but it disconnects users and rolls back open transactions. Warn users and confirm you have a recovery plan before doing this. On a failover cluster, a restart may trigger a failover; coordinate with the team that owns the cluster.
  10. Monitor after the fix. Re-run the queries from steps 2 and 3 periodically, or set up a SQL Server Agent job that logs long-running transactions. Watch for the error recurring in the error log. If it does, return to step 5 and look for a different statement with the same pattern.

Common Mistakes

  • Assuming a configuration setting will raise the limit. There is no max lock classes option in sp_configure. The limit is internal and fixed per transaction; only rewriting the transaction helps.
  • Killing the wrong session. Always match the SPID from the error log to the session in sys.dm_exec_requests before running KILL. Killing a system session or a replication agent can cause data loss or replication lag.
  • Ignoring the application layer. Many cases come from an ORM or reporting tool that issues one statement per object. Fixing only the database side will not stop the pattern from recurring.
  • Restarting the service first. A restart clears the symptom but not the cause; the same transaction will hit the limit again. Use it only when the instance is unresponsive.
  • Forgetting to test in a non-production environment. Index and query changes can alter execution plans and performance. Validate on a copy of the database before deploying.

Tips

  • Keep transactions short. Commit work in batches rather than holding one transaction open across thousands of rows or objects.
  • Use SET NOCOUNT ON; in stored procedures to reduce network traffic, though it does not affect lock classes.
  • Capture the generated SQL from dynamic SQL statements with sys.dm_exec_sql_text so you can see exactly which objects are being referenced.
  • If the workload is a reporting query, consider running it against a read-only replica or a snapshot to avoid lock contention on the primary.
  • Document the SPID, statement text, and fix in a change log so future occurrences are faster to resolve.

Troubleshooting

If the error persists after rewriting the transaction, check whether the application is retrying the same statement in a loop. Look at sys.dm_exec_requests for multiple sessions running the same sql_text. If so, fix the retry logic or add a delay. If KILL does not terminate the session, the transaction may be rolling back; check sys.dm_exec_requests for command = 'KILLED/ROLLBACK' and wait. If the instance is unresponsive and you cannot connect, a service restart may be the only option, but confirm with your team and warn users first. If the error appears during index rebuilds or DBCC commands, reduce the batch size or run the operation during a maintenance window with fewer concurrent transactions.

Frequently Asked Questions

Can I increase the lock class limit with sp_configure?

No. There is no configuration option for lock classes. The limit is fixed per transaction, so the solution is to reduce the number of objects a transaction touches.

What causes error 1220?

A single transaction acquires too many lock classes, usually because it references thousands of distinct objects, partitions, or cursors in one unit of work.

Does restarting SQL Server fix it permanently?

No. A restart clears the current lock classes but does not change the transaction pattern, so the error will return if the same query runs again.

Is it safe to kill the session that raised the error?

Yes, if you have confirmed it is the correct SPID and the session is not a system or replication process. Killing it rolls back the transaction and releases lock classes.

Can error 1220 happen in Azure SQL Database?

The same limit applies to the SQL Server engine, so the error can occur in Azure SQL Database and Managed Instance. The fix is the same: rewrite the transaction to use fewer lock classes.