Violation of primary key constraint, multiple users

Posted by MC. on Stack Overflow See other posts from Stack Overflow or by MC.
Published on 2010-06-11T21:41:35Z Indexed on 2010/06/11 21:52 UTC
Read the original article Hit count: 211

Lets say UserA and UserB both have an application open and are working with the same type of data. UserA inserts a record into the table with value 10 (PrimaryKey='A'), UserB does not currently see the value UserA entered and attempts to insert a new value of 20 (PrimaryKey='A'). What I wanted in this situation was a DBConcurrencyException, but instead what I have is a primary key violation. I understand why, but I have no idea how to resolve this. What is a good practice to deal with such a circumstance? I do not want to merge before updating the database because I want an error to inform the user that multiple users updated this data.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about sql-server