0

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?

Elisabeth
  • 20,496
  • 52
  • 200
  • 321
  • see http://stackoverflow.com/questions/4681280/whats-the-best-way-to-manage-concurrency-in-a-database-access-application – ken2k Jun 08 '12 at 14:08
  • @Bond No its rather some theoretical info I need what can happen practically. – Elisabeth Jun 08 '12 at 14:25

2 Answers2

1

In Read committed default Isolation level of sql server:

If concurrent request to accesss a object is come then sql server creates the queue for them and process them one by one. Second user will wait for a predefined time for user 1 to complete the task and throw the error if unable to complete the task in that time frame. This time frame is configurable in sql server and in ADO.net.

It all depends on isloation level defined in sql server whether you want concurrent access or not.

Read more about ISOLATION Level in DB

Romil Kumar Jain
  • 20,239
  • 9
  • 63
  • 92
  • I have only specifically mention the default isolation used in sql server but the approach for concurrent execution and role of isolation is same for all db engines. – Romil Kumar Jain Jun 08 '12 at 14:17
0

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.

pyrocumulus
  • 9,072
  • 2
  • 43
  • 53
  • I have to disagree with your answer to the first point. There is no reason why it **always** only happens to one person. – Adam Houldsworth Jun 08 '12 at 14:17
  • Well common sense says it should, shouldn't it? I mean it could depend on how you code it and the exact DAL, but that would render this whole question mute. In a regular system request A will be handled before request B (or the other way around). I'll edit my answer to reflect this a bit. – pyrocumulus Jun 08 '12 at 14:21
  • Possibly, but as I go on to explain, it isn't that simple. In the very basic case of optimistic concurrency, most likely yes. – Adam Houldsworth Jun 08 '12 at 14:22
  • That is true, but I didn't see any reason to not go by the simplest situation. The question the Elisa poses is to broad/vague to answer any other way. Simply too many possibilites. I do agree with you that the situation could be a lot more complex. – pyrocumulus Jun 08 '12 at 14:24
  • @Clound Yes my question is broad/vague because I am of the very beginning and trying to gather basic knowledge about concurrency before I start fumbling around with isolation levels :P – Elisabeth Jun 09 '12 at 21:41