DataSet error in .NET: Concurrency Edit

1 minute read

Recently I encountered some strange error whilst working with DataSet in VS 2005. The system works in integration environment but gives some strange error in the acceptance environment. When updating one record in the dataset I got an error: "Concurrency Edit: This row has been modified by another user". I perfectly know that there’s no other user dealing with this record in parallel.

When I debug the code I can see that after calling the DataTableAdaptor update method, the dataset gets HasError “true” and one of the tables in it become to error state. Logically this is the table where I try to change a record. This record gives me the same error message:

image

Since the only difference between integration and acceptance environments is the database, I checked there if the field I am trying to change has different types. Apparently the type is the same but it’s float. I also checked the values and when in one table the values look like this in integration:

image

It looks completely different in acceptance:

image

As you can see the number of decimal digits in the second case is hitting the limit. This is because earlier we run a script in acceptance that decreased values of this column for 1%. Actually that gave me a clue what’s wrong. The data type for this field in the generated dataset can accept less decimal digits than database returns. When dataset is used with optimistic concurrency, it first checks that original values are the same as stored in the dataset memory cache. Also dataset checks after updating a record if the values have actually been updated by making an additional select statement after the update statement. This can be seen if you go to the dataset designer and check the Update command of your table adapter:

image

If you copy the whole update command and paste it to Notepad, you can see that it also contains a SELECT statement after UPDATE statement. This SELECT is invisible in the query designer.

So if any of those checks fail, dataset gives this “concurrency edit” error. In my case it happened because float values stored in the database and in the C# code were different just because if the number of decimal digits (rounding issue). This of course has nothing to do with concurrency and therefore this error is not easy to debug.

Updated: