Re: Sql Server Queue?
From: Raterus (raterus_at_hotmail.com)
Date: 01/03/05
- Next message: Louis Davidson: "Re: ALTER IDENTITY setting..."
- Previous message: DavidM: "Re: Command Object, SQL Stored Procedure, and Data Type"
- In reply to: David Browne: "Re: Sql Server Queue?"
- Next in thread: David Browne: "Re: Sql Server Queue?"
- Reply: David Browne: "Re: Sql Server Queue?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 3 Jan 2005 13:04:44 -0500
I haven't played with locks much, so I have a question about this. Say I lock down this stored procedure as you suggested.
PersonA runs this procedure, quickly followed by PersonB running the same procedure. Will PersonB be hit with an error since the stored procedure is currently "locked" or will sql server wait until PersonA's procedure finishes, then automatically start PersonB's?
Thanks,
--Michael
"David Browne" <davidbaxterbrowne no potted meat@hotmail.com> wrote in message news:eE28k8a8EHA.2088@TK2MSFTNGP10.phx.gbl...
> >"Raterus" <raterus@hotmail.com> wrote in message
>> >news:ex6rBQa8EHA.1396@tk2msftngp13.phx.gbl...
>>Hello,
>
>>I have a long running stored-procedure. End users can start this procedure
>>anytime >they want (It runs a search on some data). My problem is, if they
>>ever (and they do) >start this sproc a couple of times all at once, they
>>will break the process. (Not so >much the stored procedure execution, just
>>the programming logic within the stored >procedure.
>
>>I'd like to have some sort of queue process that manages the execution of
>>this stored >procedure, instead of starting the sproc directly, they would
>>just add it to a queue, and >it would make sure they stored procedure is
>>not ran concurrently.
>
> The easiest and most reliable way to control concurrency of a stored
> procedure is through locking. If the table locking required by your
> procedure is not sufficient, you can use sp_getapplock to explicity
> serialize invocations of your procedure.
>
> Use
>
> alter procedure foo_once as
> begin transaction
> exec sp_getapplock @Resource = 'foo_once_mutex', @LockMode = 'Exclusive'
> WAITFOR DELAY '00:00:10'
> print 'done'
> commit transaction
>
> If your procedure uses a transaction. This is the most reliable since it
> enlists the applock in your transaction, and it will be automatically
> released when you commit or roll back. If you must run your procedure
> without a transaction, use
>
> alter procedure foo_once as
> exec sp_getapplock @Resource = 'foo_once_mutex',
> @LockMode = 'Exclusive',
> @LockOwner = 'Session'
> WAITFOR DELAY '00:00:10'
> print 'done'
> exec sp_releaseapplock @Resource = 'foo_once_mutex',
>
> but here you are responsable for releasing the app lock manually. If you
> don't, it will last until the session ends.
>
> David
>
>
>
- Next message: Louis Davidson: "Re: ALTER IDENTITY setting..."
- Previous message: DavidM: "Re: Command Object, SQL Stored Procedure, and Data Type"
- In reply to: David Browne: "Re: Sql Server Queue?"
- Next in thread: David Browne: "Re: Sql Server Queue?"
- Reply: David Browne: "Re: Sql Server Queue?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|