SQL Server Error 1224: Invalid Application Lock Resource
In this article
SQL Server error 1224, "An invalid application lock resource was passed," means your code (or a tool) called the application lock system with a resource name that SQL Server cannot accept. The fix is almost always to correct the resource string and the lock owner and database principal parameters in the sp_getapplock or sp_releaseapplock call, then re-run the procedure. This guide walks through diagnosing the exact cause and applying the right correction.
What You'll Need
- Access to SQL Server Management Studio (SSMS) or Azure Data Studio with permission to run queries in the affected database.
- The stored procedure or application code that calls
sp_getapplockorsp_releaseapplock. - Permission to view the database's application locks (members of the
publicrole can usually querysys.dm_tran_locks; altering procedures requiresALTERpermission). - A test environment where you can reproduce the error without affecting production traffic.
Step-by-Step
- Reproduce the error and capture the exact call. Run the failing procedure or application action with the same parameters that triggered error 1224. In SSMS, enable the Actual Execution Plan or simply copy the
EXEC sp_getapplock ...statement from the code. The error message usually appears in the Messages tab with the resource name that was rejected. - Inspect the resource parameter. The
@Resourceargument ofsp_getapplockmust be a non-NULL, non-empty string of up to 255 characters. Check for: a NULL variable that was never assigned, an empty string (''), a string longer than 255 characters, or a value containing characters your application passed incorrectly (for example, a Unicode string cast tovarcharthat lost characters). Correct the value so it is a short, stable identifier such asOrderProcessing_42. - Check the lock owner and database principal.
sp_getapplockaccepts@LockOwnervalues ofTransaction(the default) orSession. If you specifySession, the lock is held until explicitly released or the session ends. Also verify@DbPrincipalis a valid database principal (usuallypublicordbo). An invalid principal name can produce misleading errors, so confirm the principal exists in the current database. - Confirm the database context. Application locks are scoped to the current database. If your procedure runs in a different database than the one where the lock was acquired, the resource name may not match. Add
USE [YourDatabase];at the top of your test script, or qualify the procedure call with the correct database name. - Verify the lock is not already held with a different owner. Query
sys.dm_tran_lockswhereresource_type = 'APPLICATION'to see existing application locks, their resource descriptions, and the owning session. If a previous session left a lock open (for example, aSession-owned lock that was never released), release it withsp_releaseapplockusing the same resource name and owner, or end the session. - Fix the release call. Error 1224 can also occur in
sp_releaseapplockif the resource name or lock owner does not match the one used to acquire the lock. Ensure the release call uses the identical@Resourcestring and the same@LockOwnervalue as the acquire call. - Test the corrected call in isolation. Run a minimal script:
EXEC sp_getapplock @Resource = 'TestLock', @LockMode = 'Exclusive', @LockOwner = 'Session';then release it with the same parameters. If that succeeds, replace the test values with your real resource name and owner and test again. - Update the application code and deploy. Once the corrected parameters work in SSMS, update the stored procedure or application code, then deploy to the affected environment. Re-run the original failing action to confirm error 1224 no longer appears.
Common Mistakes
- Passing a NULL or empty
@Resourcevalue because a variable was declared but never set. - Using a resource name longer than 255 characters, which SQL Server rejects.
- Mixing
TransactionandSessionlock owners between acquire and release calls. - Assuming the error is a permissions problem when it is actually a malformed parameter.
- Forgetting that application locks are database-scoped and testing in the wrong database context.
- Releasing a lock from a different session than the one that acquired it when the owner is
Session.
Tips
- Keep resource names short, descriptive, and deterministic (for example, include an order ID or job name) so they are easy to trace.
- Use
Transactionownership when the lock should be released automatically at the end of the transaction; useSessiononly when you need the lock to survive across multiple transactions in the same connection. - Add error handling around
sp_getapplockto catch return codes and log the resource name for faster diagnosis. - Query
sys.dm_tran_locksregularly during development to see which application locks are active. - Document the resource naming convention in your team's code standards to prevent mismatches between acquire and release calls.
Troubleshooting
If the error persists after correcting the parameters, check the following. First, confirm the procedure you edited is the one actually being executed (schema-qualified names and synonyms can cause confusion). Second, run sp_helptext on the procedure to verify the deployed definition matches your changes. Third, look for triggers or nested procedure calls that might be issuing their own sp_getapplock with bad parameters. Fourth, check for connection pooling issues: if an application reuses a session that holds a Session-owned lock, a later call with a different resource name may conflict. Fifth, if the error appears only under load, capture the exact statement with SQL Server Profiler or Extended Events filtering on error 1224, then compare the captured parameters against your code. Finally, if you cannot identify the caller, search all stored procedures and application code for sp_getapplock and sp_releaseapplock to find every usage.
Frequently Asked Questions
What causes SQL Server error 1224?
It is caused by passing an invalid resource name (NULL, empty, or longer than 255 characters) or mismatched lock owner/database principal parameters to sp_getapplock or sp_releaseapplock.
Can error 1224 happen on release as well as acquire?
Yes. If the resource name or lock owner used in sp_releaseapplock does not match the values used to acquire the lock, SQL Server can return error 1224.
Does error 1224 mean I have a permissions problem?
Not usually. It is a parameter validation error. Permissions issues typically produce different error numbers, such as 229 or 15151.
How do I see which application locks are currently held?
Query sys.dm_tran_locks and filter on resource_type = 'APPLICATION'. The resource_description column shows the resource name.
Can I use any string as a resource name?
No. It must be a non-NULL string of up to 255 characters. Keep it short and consistent between acquire and release calls.
Does the database context matter for application locks?
Yes. Application locks are scoped to the current database, so the acquire and release calls must run in the same database context.