﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / sp_getapplock / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 20 Jun 2013 04:13:25 GMT</lastBuildDate><ttl>20</ttl><item><title>sp_getapplock</title><link>http://www.sqlservercentral.com/Forums/Topic845998-391-1.aspx</link><description>Hi, My application allows a number of different users to be defined and currently a user can sign into the system, with the same account details, a number of times. I need to change this so that any one user can only ever be logged in once.So I was hoping that I could apply an application lock for each logged in user and check the status of the lock when attempting to sign in. I don't want the system to hang if the lock is already in place so I was trying to use the applock_test to check the status of the lock before trying to apply it. The problem I have is that the applock test always returns 1 even if the lock is in place. Am I doing something wrong? Is the better way to achieve this?Many Thanks JonThe code is wrapped in FoxPro but looks like this:* test the lock for the provided UserIDw_chklock = g_ocsdb.ExecSQL("SELECT applock_test('public','" + ALLTRIM(UPPER(p_userid)) + "', 'Exclusive', 'Session')")IF w_chklock &amp;gt; 0 * if the lock is available to grant lock it exclusively 	w_chklock = g_ocsdb.ExecSQL("EXEC sp_getapplock '" + ALLTRIM(UPPER(p_userid)) + "', 'Exclusive', 'Session',0")	w_userct = 0 ELSE* the lock is not available warn the user they cannot get in	w_userct = 1ENDIF</description><pubDate>Tue, 12 Jan 2010 04:06:51 GMT</pubDate><dc:creator>Jon-183221</dc:creator></item></channel></rss>