all groups > sql server programming > september 2006 >
You're in the

sql server programming

group:

selecting and locking a record from distributed DB



selecting and locking a record from distributed DB Muhammad Ahsin Saleem
9/24/2006 9:33:15 PM
sql server programming: hi
everyone I have a problem that I have an application having a shared DB
and I want that when I retrieve a record from database for one machine
then that record must be locked so that others couldnot modify that
record. I need urgant help I shall be thankful to all of you if anybody
can help me.
Re: selecting and locking a record from distributed DB Muhammad Ahsin Saleem
9/24/2006 10:30:20 PM
Actually I want that If my system gives one record to one person for
modification or to do some work on it then record must not be given to
any other. for example in this case I have a project for telemarkting.
there are 3-4 person sitting in front of systems and have one shared
DB. Now my project should gave them a Company's contact no so that they
can communicate with that company. I want that if my syatem gives
company record 1 to employee 1 then it should not be given to any other
person. Can you guide me about stored procedure that can do this or is
there any alternative way availabe for it. Ishall be very thankful to
you.

[quoted text, click to view]
Re: selecting and locking a record from distributed DB Uri Dimant
9/25/2006 12:00:00 AM

Hi

[quoted text, click to view]

And others are just waiting or what?

Again
BEGIN TRAN
COMMIT TRAN
will lock the session untill it the transaction will be commited or
rollback

Another way I can think is to maintain an additon column to indicate whether
the company ID has aleady given and doing an appropriate job for others




[quoted text, click to view]

Re: selecting and locking a record from distributed DB Uri Dimant
9/25/2006 12:00:00 AM
I'm not sure that understand your requirement

BEGIN TRAN

SELECT col FROM TableName (UPDLOCK,HOLDLOCK)


COMMIT TRAN

Note, readers don't get blocked

[quoted text, click to view]

Re: selecting and locking a record from distributed DB Uri Dimant
9/25/2006 12:00:00 AM
Hi
CREATE PROCEDURE usp_GetCompanyCode
@CompanyCode INT
AS

BEGIN TRAN

SELECT <columns> FROM TableName WITH (UPDLOCK,HOLDLOCK)
--Do here another operation

COMMIT TRAN



GO

---Usage

EXEC usp_GetCompanyCode @CompanyCode =1000




[quoted text, click to view]

Re: selecting and locking a record from distributed DB Muhammad Ahsin Saleem
9/25/2006 12:55:36 AM
Others are also getting data from the DB at the same time. Also kindly
if you can give me stored procedure code do give me I need it very
badly.
[quoted text, click to view]
Re: selecting and locking a record from distributed DB Muhammad Ahsin Saleem
9/25/2006 9:01:31 PM
Thank You very much Uri for your so much Cooperation. I have tried it
and got desired result.
[quoted text, click to view]
AddThis Social Bookmark Button