How to: Resolve Conflicts by Overwriting Database Values

To reconcile differences between expected and actual database values before you try to resubmit your changes, you can use KeepCurrentValues to overwrite database values. For more information, see Optimistic Concurrency: Overview.


In all cases, the record on the client is first refreshed by retrieving the updated data from the database. This action makes sure that the next update try will not fail on the same concurrency checks.


In this scenario, an ChangeConflictException exception is thrown when User1 tries to submit changes, because User2 has in the meantime changed the Assistant and Department columns. The following table shows the situation.

Manager Assistant Department
Original database state when queried by User1 and User2. Alfreds Maria Sales
User1 prepares to submit these changes. Alfred Marketing
User2 has already submitted these changes. Mary Service

User1 decides to resolve this conflict by overwriting database values with the current client member values.

When User1 resolves the conflict by using KeepCurrentValues, the result in the database is as in following table:

Manager Assistant Department
New state after conflict resolution. Alfred

(from User1)


(from User1)

The following example code shows how to overwrite database values with the current client member values. (No inspection or custom handling of individual member conflicts occurs.)


catch (ChangeConflictException e)
    foreach (ObjectChangeConflict occ in db.ChangeConflicts)
        //No database values are merged into current.

Catch ex As ChangeConflictException

    For Each occ As ObjectChangeConflict In db.ChangeConflicts
        ' No database values are merged into current.

End Try

See Also

How to: Manage Change Conflicts