views:

135

answers:

3

In asp.net web site, We have enry form which can be accessible to administrator.

There are more then one administrator for entry. If all admin open form simultaneous and select some combobox value from form then how can we maintained concurrency

Because once first admin select value from combox and save then that value should remove from database.

But how can the problem of concurrency solve when let say two or three admin simultaneous save same value.

Where is right place code or at database? and how?

+1  A: 

You should read about optimistic concurrency control. Really it boils down to choosing between optimistic, pessimistic and last one wins. Usually the right choice is optimistic, unless it is a very time consuming process where failure for another user at the end would be frustrating.

As for the right place you need to tell how you are currently doing your Data Access Code. Also what database are you using?

This article will give you something to get started with.

RichardOD
A: 

In our app we handle it in both:

All our updates goes through a update-stored procedure. This sp thows an error when the field "Modified", what is mandetory, is newer then the given one. The error is thrown by a special exception class in the code and you can identify it as a concurrency exception.

E.g.:

  • Read 1: 12:00:00 (Modified date is in past, e.g. 11:00:00)
  • Read 2: 12:01:30 (No change of modified date)
  • Update 1: 12:03:00 (Set modified = 12:03:00)
  • Update 2: 12:04:00 (Concurrency excaption, because update see: Oh, modified is newer then the given one)
Kovu
Note that simple date/time field is not a good idea. Computers these days are so fast that two UPADTE operations can happen faster than the timer resolution unit. A counter is usually a better idea. See MSSQL "Timestamp" column type.
Vilx-
A: 

A common technique for implementing concurrency is to use a timestamp for updates, with you, as the developer writing code depending on your business process. Normally, the choices you have are: Last one in wins, so the last write wins, notify the user of the conflict and let them make the choice as to whether or not they wish to commit their changes, or merge the changed values.

This last technique isn't common with databases, as it means that the user commits one set of values, but a different set are updated, and this might come as a surprise to them (also, it requires complex rules). If you think about the way some source control providers work though, you can see how this is implemented.

In the case of a delete operation, there's no need to worry because does it really matter that two users deleted the same record? The second one will have no effect.

Pete OHanlon

related questions