Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Detect locked records without exceptions ?
Sun, Nov 15 2009 12:35 AMPermanent Link

Charalampos Michael
Hello,
  Is it possible to detect if the record is locked/edited by another
  user without needing to try to edit it in order to get the exception ?

Thank you

--
Charalampos Michael - [Creation Power] - http://www.creationpower.gr
Mon, Nov 16 2009 3:54 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Michael,

<< Is it possible to detect if the record is locked/edited by another user
without needing to try to edit it in order to get the exception ? >>

Why do you wan to know whether the row is locked or not ?  We have this
discussion here on the newsgroups occasionally, and it always involves this
type of code:

if RecordIsLocked then
  ShowMessage('Record is locked')
else
  begin
  Edit;  << This can still fail here with a record lock exception !!!!
  Post;
  end;

And my answer is always the same - just respond to the record lock exception
via an OnEditError handler, and show the message to the user there.  The
result is the same.

Using RecordIsLocked is not reliable, because between the time of the call,
and the time of the Edit/Delete, the record may be unlocked or locked again
by another session.

--
Tim Young
Elevate Software
www.elevatesoft.com

Mon, Nov 16 2009 5:45 PMPermanent Link

Charalampos Michael
Dear Tim,

> Michael,
>
> << Is it possible to detect if the record is locked/edited by another user
> without needing to try to edit it in order to get the exception ? >>
>
> Why do you wan to know whether the row is locked or not ?  We have this
> discussion here on the newsgroups occasionally, and it always involves this
> type of code:
>
> if RecordIsLocked then
>    ShowMessage('Record is locked')
> else
>    begin
>    Edit;  << This can still fail here with a record lock exception !!!!
>    Post;
>    end;
>
> And my answer is always the same - just respond to the record lock exception
> via an OnEditError handler, and show the message to the user there.  The
> result is the same.
>
> Using RecordIsLocked is not reliable, because between the time of the call,
> and the time of the Edit/Delete, the record may be unlocked or locked again
> by another session.

In C/S (not shared/multi-user) still RecordIsLocked is not reliable ?

Doesn't "Enable Row Change Detection" makes "RecordIsLocked" more
reliable ? (at least in C/S environment ? In a previous discussion you
said that ServerSessionLocks can detect other locks)

Back on BDE days i used the following code:
http://info.borland.com/devsupport/bde/bdeapiex/dbiisrecordlocked.html

Thank you

--
Charalampos Michael - [Creation Power] - http://www.creationpower.gr
Mon, Nov 16 2009 10:41 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Michael,

<< In C/S (not shared/multi-user) still RecordIsLocked is not reliable ? >>

No, because the ElevateDB Database Server can be used with other ElevateDB
Database Servers on the same databases.  Picture a situation with a fast SAN
and multiple server machines.

<< Doesn't "Enable Row Change Detection" makes "RecordIsLocked" more
reliable ? >>

No, one has nothing to do with the other.

<< (at least in C/S environment ? In a previous discussion you said that
ServerSessionLocks can detect other locks) >>

It can read all of the locks *at a given point in time*, which is still no
good for what you're trying to do, due to the same reason that I mentioned
before - between the time that you look at which locks are placed and the
time that you actually try to lock the row, the row could have already been
locked again by another session.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image