Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Lock out a stored proc

Author  Topic 

Lupison
Starting Member

5 Posts

Posted - 2008-09-25 : 13:58:57
I have a multi threaded application, I want a stored proc to lock out other threads from using it while it's being executed by one thread.

Basically I'm looking for a way to lock out a stored proc while it's being executed so nothing else can call it.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-25 : 14:01:29
There isn't a simple way to do this in SQL Server. You'd have to put code inside the stored procedure to say it's in use and the very first thing it does is to check if it is in use. You'd store the information in a table. This is prone to issues though.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-25 : 14:02:31
Have a look at sp_getapplock system stored procedure in books online

http://msdn.microsoft.com/en-us/library/ms189823.aspx
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-25 : 14:03:47
Interesting, didn't know about that one.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Lupison
Starting Member

5 Posts

Posted - 2008-09-25 : 14:08:45
One of my team was experimenting with that and he could never get it to just lock the SP, it would either lock the table or the page.
Go to Top of Page
   

- Advertisement -