Board index » delphi » Update Lock with MS SQL 7 and D4/TQuery

Update Lock with MS SQL 7 and D4/TQuery

How can I set an update lock to a row in a tquery ?
I want to lock the row at the moment the user begins to change the data
(i think at OnStateChange), so that a second user cannot change the same
row as the first.
Any other tip for solving the problem of parallel data access/changing
is desired.

Thanks for your help.
Micha

 

Re:Update Lock with MS SQL 7 and D4/TQuery


update table with (rowlock) set...

Quote
Michael Borschel <michael.borsc...@horn-cosifan.de> wrote in message

news:3770E1AF.38F8C8B9@horn-cosifan.de...
Quote
> How can I set an update lock to a row in a tquery ?
> I want to lock the row at the moment the user begins to change the data
> (i think at OnStateChange), so that a second user cannot change the same
> row as the first.
> Any other tip for solving the problem of parallel data access/changing
> is desired.

> Thanks for your help.
> Micha

Re:Update Lock with MS SQL 7 and D4/TQuery


Bruce,

   How did you get this to work?  When I try this (Select * from whatever
(rowlock)), the lock is only active for the instant the query is running and
free once the query is complete.

For example:

Query.SQL.Add('Select * from whatever (rowlock) where whateverid = 1');
Query.Open;
{do whatever}

The lock is only active for the few milliseconds it takes to execute the
query, even when the query component is still active/open.  There is no
server mechanism to prevent another user from changing the data.  Do I have
to do an explicit begin/end transaction?

 For Michael ,the OnStateChange event is valid for when the client changes
data, not when the data changes on the server.

Thanks,
krf

Quote
Bruce wrote in message <7kr1eq$af...@forums.borland.com>...
>update table with (rowlock) set...

>Michael Borschel <michael.borsc...@horn-cosifan.de> wrote in message
>news:3770E1AF.38F8C8B9@horn-cosifan.de...
>> How can I set an update lock to a row in a tquery ?
>> I want to lock the row at the moment the user begins to change the data
>> (i think at OnStateChange), so that a second user cannot change the same
>> row as the first.
>> Any other tip for solving the problem of parallel data access/changing
>> is desired.

>> Thanks for your help.
>> Micha

Re:Update Lock with MS SQL 7 and D4/TQuery


Sorry, my mistake. It's "Select from table (nolock)..." the (rowlock) hint
is used with UPDATE and INSERT.

Quote
Kevin Frevert <kfrev...@midwayusa.com> wrote in message

news:7kr3lu$af711@forums.borland.com...
Quote
> Bruce,

>    How did you get this to work?  When I try this (Select * from whatever
> (rowlock)), the lock is only active for the instant the query is running
and
> free once the query is complete.

Other Threads