DBConcurrency exception not occuring when data has been updated elsewhere

68 views Asked by At

Situation:

I'm writing a Winforms app using C# in VS2013 with .NET4.0.

I have a datagridview bound to a dataadapter that loads data from a MySQL table. dataadapter SQL command have been built manually as some reformatting is needed to accord with date and boolean handling on the database. This is a multi user environment so data contention is possible. I therefore handle DBConcurrency exceptions when carrying out dataadapter.Update().

For testing the adapter is filled, bound to the dgv and then I use MySQLWorkbench to delete one of the displayed rows. If I then try to update that row in the dgv the DBConcurrency exception is thrown correctly.

Issue:

If however I only amend the row with MySQLWorkbench, then update through the dgv the DBConcurrency exception is not thrown and the update is successful. Hence any update that another user might have made gets lost. (NB I am ensuring that the MySQLWorkbench change is properly committed first!)

Question:

How do I get the DBConcurrency exception thrown when there is amend contention?

EDIT

This is actually a tabbed application with a number of datagridviews each linked to a MySQL table. All have the issue. A really simple example is a "maker" table consisting of:

maker_id    int(11)      not nullable auto-increment
maker_name  varchar(127) not nullable

The SQL is generated through code and populated via parameters. Through the debugger just before datadapter.Update I see:

UPDATE maker SET maker_id = @maker_id, maker_name = @maker_name WHERE maker_id = @maker_id
0

There are 0 answers