DBCurrency

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

User A and User B modify the same record, UserB save first.
As User A save it , I will get the concurrency error.
I know I can use
Try
..... dsTable.udpate()
catch err As DbCurrency
messagebox.show("UpdateFailed ")
end try

However, How can I let User A know "User B save the same record already ",
and ask USER A whether overwrite it or not , If User A press "Yes" , his
record should saved correctly.
Does anyone know how to do ??
Thanks a lot.
 
Should be possible... here's one way to handle it...

Once you catch the error, show a message box that gives the option whether
or not to replace the existing record (within the catch).

If the user response = Yes, then RELOAD that record into your dataset
(assuming you're using a dataset). If you don't, VB will continue to notice
the data in the dataset still conflicts with what's now in the database.

Next, just overwrite that dataset fields (which now contain User A's data,
which also match what's in the underlying database) with whatever the user B
has entered on-screen. Then just save it (e.g.
OleDbDataAdapter1.Update(DataSet1)).

BTW, even if user answers NO, you may still have to re-load your dataset
with the new data (and refresh the screen with the data saved by user A).
This just helps to avoid other concurrency errors.

Hope this helps!
Tim
 
1. there is NO automatic concurrancy checking. the closest visual studio
comes to it is if you use the data adapter wizard to "generate sql
statements" and, under the advanced tab, you select "use optimistic
concurrancy". What this does is simply generate a UPDATE SQL statement that
compares the prior value of all the fields to the current value in the WHERE
clause. If any field has changed the update does not occur (ie: zero records
are updated). This corresponds to the "whole record" method of concurrancy
checking. The other method is to compare last updated timestamp, or some
sort of version number for the record. (ie each time you update a record you
either update the timestamp, or increment the version by 1). The important
thing to realize is that this is basically all a manual method of doing
concurrancy checking. If you don't use the wizard (I never do) then you have
to code some sort of concurrancy check into your update statement manually.

2. there is an exception called "DBConcurrencyException" which, by it's
name, seems to indicate that it will catch concurrency violations... WRONG.
Reading the documentation for it, this exception will be thrown "whenever 0
records are affected" by an sql statement (ie an update statement). Reading
the documentation reveals that "when 0 records are affected it is PROBABLY
due to a concurrency violation" (which YOU have coded in your WHERE clause).

So, the bottom line is this... if you want to catch a concurrency violation
you have to code it yourself using your own methodology. The only tool
ADO.NET gives you is to throw a DBConcurrencyException when 0 records are
affected by an SQL statement. Everything else is up to you to code. Now, I'm
not saying that this is necessarily bad, I'm just saying that it would have
been nice is MS didn't dance around the issue and make it PERFECTLY CLEAR
that there is no automatic concurrency check.

I believe the above statements are correct to the best of my knowledge. I
provide no warrantee, guarantee, or represent that I have any brains at all.

Regards,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top