Optimistic locking - once again

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mfg
Posts: 10
Joined: Wed 03 Oct 2007 13:49
Location: Zabrze

Optimistic locking - once again

Post by mfg » Tue 11 Dec 2007 21:23

I found this information in the previous messages:

>> How do I actually check whether the row has been updated by another user?

> Setting CheckRowVersion to True is enough.

I set CheckRowVersion to True in your example SdacDemo-> CachedUpdates, I added a TimeStamp field to the dbo.emp table, I opened 2 copies of sdacDemo and I was editing the same record in the same time. Nothing happend.
In that case should I get any error message or there is another way to catch this event ?

I use Sdac 4.30, Delphi 5, MsSql 2005.
Thanks for your help.
ZS

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Thu 13 Dec 2007 08:52

You should also set the DMLRefresh option to True.

jigesh
Posts: 16
Joined: Tue 11 Oct 2005 21:04

Post by jigesh » Thu 13 Dec 2007 19:32

Antaeus wrote:You should also set the DMLRefresh option to True.
Where can I find the DMLRefresh option

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Fri 14 Dec 2007 08:40

You will find DMLRefresh within Options of TMSQuery, TMSTable, TMSStoredProc components.

mfg
Posts: 10
Joined: Wed 03 Oct 2007 13:49
Location: Zabrze

Post by mfg » Wed 02 Jan 2008 00:08

I set DMLRefresh, CheckRowVersion to True and it works almost in the way I want, I've got an optimistic locking.

But I still have a little problem.
When 2 users edit the same record in the same time, one of them has got an error message "Update failed. Found 0 records".
I'wouldn't like to get this message - is it possible to get exactly message "error optimistic transaction" or something like this ?
I know that I can replace this message "Update failed. Found 0 records" to "error optimistic transaction" in PostError event, but I would like to avoid this situation, because this error message ("Update failed. Found 0 records") could be also cause by another database/sdac event (I find a lot of examples with this error message on this forum).

kind regards
ZS

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Thu 03 Jan 2008 10:29

It is better to change this message in your event handler. Just add a couple of conditions that verify values of DMLRefresh and CheckRowVersion options to be sure about the reason of the error.

mfg
Posts: 10
Joined: Wed 03 Oct 2007 13:49
Location: Zabrze

side effect DMLRefresh = True (text field)

Post by mfg » Fri 04 Jan 2008 23:33

when I set DMLRefresh := True I got an error message when I make post:
"Bad parameter [my_text_field_name] Output parameters "text", "ntext", or image are not acceptable", if I use a text type field in TMSQuery.
How to avoid this error ?
I don't have this error if I Generate SQL - but in that case optimistic locking doesn't work :)

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 09 Jan 2008 16:14

Thank you for information. We have reproduced this problem and fixed it. This fix will be included in the next SDAC build.

Post Reply