SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


sp_getapplock


sp_getapplock

Author
Message
Jon-183221
Jon-183221
Right there with Babe
Right there with Babe (732 reputation)Right there with Babe (732 reputation)Right there with Babe (732 reputation)Right there with Babe (732 reputation)Right there with Babe (732 reputation)Right there with Babe (732 reputation)Right there with Babe (732 reputation)Right there with Babe (732 reputation)

Group: General Forum Members
Points: 732 Visits: 287
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

Jon

The code is wrapped in FoxPro but looks like this:

* test the lock for the provided UserID
w_chklock = g_ocsdb.ExecSQL("SELECT applock_test('public','" + ALLTRIM(UPPER(p_userid)) + "', 'Exclusive', 'Session')")

IF w_chklock > 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 = 1
ENDIF
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search