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
 
Hi Nathan,

Either delete of update failed because of WHERE conditions.
 
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.
 

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