Path: csiph.com!aioe.org!.POSTED!not-for-mail From: Anton Shepelev Newsgroups: comp.databases.ms-sqlserver Subject: Using sp_getapplock outside a transaction Date: Sat, 25 Nov 2017 14:56:29 +0300 Organization: Aioe.org NNTP Server Lines: 29 Message-ID: <20171125145629.a8f9f75371e03662bf0496dd@gmail.com> NNTP-Posting-Host: Bi9VZxU/8bdAeaqLIY+52Q.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Newsreader: Sylpheed 3.5.0 (GTK+ 2.24.23; i686-pc-mingw32) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.databases.ms-sqlserver:1979 Hello, all According to the documentation for sp_getapplock available at https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-getapplock-transact-sql 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 exe- cuted from within a transaction. When I try, however, to get a lock owned by the ses- sion outside a transaction: EXEC sp_getapplock 'test', 'Exclusive', @LockOwner = 'Session' EXEC sp_releaseapplock 'test' it fails with: The statement or function must be executed in the context of a user transaction. Does not this behavor it contradict the documenta- tion? -- Anton Shepelev