Releases a lock on an application resource.
- [ @Resource = ] 'resource_name'
Is a lock resource name specified by the client application. The application must ensure that the resource is unique. The specified name is hashed internally into a value that can be stored in the SQL Server lock manager. resource_name is nvarchar(255) with no default. resource_name is binary compared, thus is case-sensitive regardless of the collation settings of the current database.
- [ @LockOwner = ] 'lock_owner'
Is the owner of the lock, which is the lock_owner value when the lock was requested. lock_owner is nvarchar(32). The value can be Transaction (the default) or Session. When the lock_owner value is Transaction, by default or specified explicitly, sp_getapplock must be executed from within a transaction.
- [ @DbPrincipal = ] 'database_principal'
Is the user, role, or application role that has permissions to an object in a database. The caller of the function must be a member of database_principal, dbo, or the db_owner fixed database role in order to call the function successfully. The default is public.
The following example releases the lock associated with the current transaction on the resource
Form1 in the
USE AdventureWorks; GO EXEC sp_getapplock @DbPrincipal = 'dbo', @Resource = 'Form1', @LockMode = 'Shared'; EXEC sp_releaseapplock @DbPrincipal = 'dbo', @Resource = 'Form1'; GO