Search code examples
c#sql-serverexceptionconcurrencydata-access-layer

Does a concurrect exception happen to both user


if a user edits a data record and the same time another user edits the same record too and both save.

1.) Will the concurrency exception ALWAYS happen only for one user?

Actually its logical that the first wins but who is the first in a technical aspect... Is it possible both user get this kind of exception?

2.)The one who was too late and getting now the concurrent exception I guess he can access the

new updated data record from the other user yes?


Solution

  • 1) I think so yes. One will always be earlier than the other; there is no other way around it. So one update will work as normal, the other will throw the concurrency exception.

    This might depend on the data access method you are using, there might be systems that can handle such situations more elegantly. But I doubt there are systems that will give both users the same exception without you building that behaviour on purpose.

    As Adam Houldsworth says: this could also depend on the way you code it yourself. You could check for multiple users beginning to edit the same record, and then throw the exception to both. But I do not believe that is what you are actually asking. If so; I misunderstood.

    2) Of course this is possible, but this is up to you to build in your application. Just catch the concurrency exception and refresh whatever edit form user B was trying to update. He/she can then try again. Generally speaking obviously; I do not know the specifics of your situation.