Vladyslav Furdak
Vladyslav Furdak

Reputation: 1835

Accept actual changes to update in database C#, MS SQL

The situation is : I have a few dedicated clients (terminals) and one database, the operations perform in the following order :

  1. First client take actual row from database
  2. Second client take actual row from database
  3. First client make some changes and update database row
  4. Second client try to update the same row but this version is older than firstclient - there is a collision.

How to resolve it better ? Is there is some solution in MS SQL server ?

Upvotes: 0

Views: 98

Answers (1)

AaronLS
AaronLS

Reputation: 38367

Optimistic concurrency is used to detect this collision, which sounds like you are able to detect it already.

Usually you take one of two approaches, last in wins where you always overwrite changes, or first in wins where the second write will fail.

If you fail the second write, then you usually display a message to the user that data has changed and their changes will be lost, then you refresh the data.

Another option is to show them their current edits and then also show them the data after refreshing it(the first saved edits), and letting them choose whether they want to overwrite the changes.

This process is called conflict resolution, and the approach you take depends on who your users are and the business rules regarding the data in question.

Upvotes: 1

Related Questions