Monday, March 26, 2012

how to aquire lock on a database by using SQL ?

how to aquire lock on a database by using SQL ?What lock are you trying to acquire? For what purpose?
If you want to acquire an application lock, use
sp_getapplock.
If you want to control what type of lock a SELECT, INSERT,
UPDATE, or DELETE should put on a table, you can choose to
use various locking hints such as HOLDLOCK, NOLOCK,
TABLOCK, TABLOCKX, etc.
Linchi
>--Original Message--
>
>.
>|||> What lock are you trying to acquire? For what purpose?
I want to get a lock from my app for entire database.
This lock has to prevent any other user to read (or only write) any data in
the database.
> If you want to acquire an application lock, use sp_getapplock.
What is "resource_name" in the sp ? Is it any existing object in the
database or
just any string known to my app ?
> If you want to control what type of lock a SELECT, INSERT,
> UPDATE, or DELETE should put on a table, you can choose to
> use various locking hints such as HOLDLOCK, NOLOCK,
> TABLOCK, TABLOCKX, etc.
If SELECT affects only one record, does it lock the only record when I
cpecify HODLOCK ?
SHould I start transaction explicitely ?|||> If you want to acquire an application lock, use
> sp_getapplock.
Is the lock held per a database ?

No comments:

Post a Comment