
June 15th, 2009, 11:41 AM
|
|
Registered User
|
|
Join Date: Jun 2009
Posts: 2
Time spent in forums: 19 m 42 sec
Reputation Power: 0
|
|
|
SELECT with ROWLOCK
Hi,
i am writing a client/server application, where 200+ clients have to access a database, read a record and update it. Two clients must not be able to get the same record, if they access the database at the same time. I wrote the following transaction, and while one client issues this transaction, none of the other clients shouldn't be able to access the rows that were selected by the first, until the transaction finishes.
BEGIN TRANSACTION
DECLARE @a varchar(20)
DECLARE @b varchar(20)
DECLARE @c datetime
SELECT TOP 1 @a=cipher, @b=name, @c=date from Table WITH (ROWLOCK)
WHERE date > getdate()
UPDATE TABLE SET date = GETDATE() WHERE key=@a
COMMIT
When i simulate this with two Query analyzers, all the locking and updating works out fine, however after checking my application logs it seems that two clients that access the database at exactly the same time still get the same row.
Is there a problem in the transaction itself or am i missing something on a larger scale?
Best regards,
Marko
|