Concurrency Violation

  • Thread starter Thread starter Nathan
  • Start date Start date
N

Nathan

Without having to post my code and explain how this error was generated, I
was wondering if someone could just tell me what would generally cause this
error message: "Concurrency violation, the update command affected 0
records." I've received this message on two separate events; one of the
times there were no records that were supposed to be updated (that I could
see).

Thanks
Nathan
 
Concurrency Violations occur when the change you are trying to make to the
data is in conflict with the data itself.

If you and I are both accessing the same customer record (and remember in
..NET we each get a copy of the original data) and I delete the record and
update the original database, the record will be gone. Now, you are still
working on your copy which my delete doesn't affect) and you change the
customers phone number and attempt to update the database, what will happen?

Since, I already deleted the customer record from the database, how could
you modify his/her phone number. This is a concurrency violation.

It is best to add a "WHERE" clause to your "UPDATE" statement that
identifies the particular record being updated (usually the WHERE clause
singles out a record by its primary key identifier). This way before the
update attempts to do its thing, it must first find the correct reocord, if
it can't, you won't get an error because the UPDATE won't even try.
 
Back
Top