Skip to content

Latest commit

 

History

History
94 lines (66 loc) · 3.41 KB

sp-releaseapplock-transact-sql.md

File metadata and controls

94 lines (66 loc) · 3.41 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs monikerRange
sp_releaseapplock (Transact-SQL)
sp_releaseapplock releases a lock on an application resource.
markingmyname
maghan
randolphwest
07/16/2024
sql
system-objects
reference
sp_releaseapplock_TSQL
sp_releaseapplock
sp_releaseapplock
TSQL
=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current

sp_releaseapplock (Transact-SQL)

[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance]

Releases a lock on an application resource.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

sp_releaseapplock
    [ [ @Resource = ] N'Resource' ]
    [ , [ @LockOwner = ] 'LockOwner' ]
    [ , [ @DbPrincipal = ] N'DbPrincipal' ]
[ ; ]

Arguments

[ @Resource = ] N'Resource'

A lock resource name specified by the client application. @Resource is nvarchar(255), with a default of NULL. @Resource is binary-compared, thus is case-sensitive regardless of the collation settings of the current database.

The application must ensure that the resource is unique. The specified name is hashed internally into a value that can be stored in the [!INCLUDE ssNoVersion] lock manager.

[ @LockOwner = ] 'LockOwner'

The owner of the lock, which is the @LockOwner value when the lock was requested. @LockOwner is varchar(32), with a default of Transaction. The value can also be Session. When the @LockOwner value is Transaction, by default or specified explicitly, sp_getapplock must be executed from within a transaction.

[ @DbPrincipal = ] N'DbPrincipal'

The user, role, or application role that has permissions to an object in a database. @DbPrincipal is sysname, with a default of public. 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.

Return code values

>= 0 (success), or < 0 (failure).

Value Result
0 Lock was successfully released.
-999 Indicates parameter validation or other call error.

Remarks

When an application calls sp_getapplock multiple times for the same lock resource, sp_releaseapplock must be called the same number of times to release the lock.

When the server shuts down for any reason, the locks are released.

Permissions

Requires membership in the public role.

Examples

The following example releases the lock associated with the current transaction on the resource Form1 in the [!INCLUDE sssampledbobject-md] database.

USE AdventureWorks2022;
GO

EXEC sp_getapplock @DbPrincipal = 'dbo',
    @Resource = 'Form1',
    @LockMode = 'Shared';

EXEC sp_releaseapplock @DbPrincipal = 'dbo',
    @Resource = 'Form1';
GO

Related content