locked
ErrorOccured because of unique index RRS feed

  • Question

  • Im working with the sync service to syncronice two SqlExpress databases. Im using SqlExpress 2008, and visual studio 2008.
    I have run into a problem with conflict handling where i want to sync a table that looks like this:
    PK GUID LogId
    FK ItemId
    FK VersionId

    DateTime2 Updated
    Fk UserId
    ...

    Where the PK is auto generated when i insert into the table, and there is an
    unique index on ItemId and VersionId.

    When the two databases that i want to sync have created the same Log entry that is an entry with the same ItemId and VersionId, but with different LogId I get the following exception:

    Cannot insert duplicate key row in object 'dbo.Log' with unique index 'IX_ItemId_VersionId'.\r\nThe statement has been terminated.

    The conflict that im detecting is a ErrorOccurred, so im only getting the data for the client, and i want to be able to let the user chose which data he wants to keep. It might seem like the two are identical, but there are some more data in the table like updated (tells when this was created) and UserId(the user who created the Log) so the two are not identical. What i would like is to be able to present the user with the data from both the client and the server so that he can chose from this and select the one he wants to keep. To do this i would like to be able to detect my conflict as a
    ClientInsertServerInsert instead of an ErrorsOccurred. So is there a way to get sync service to detect the conflict differently.
    Alternativly is there a way to get some data from the sync service, in this example ItemId and VersionId and then stop the sync service so that i can manyaly update old of the databases with the id from the other database (I hope this will generate a ClientInsertServerInsert instead of the ErrorsOccurred im getting now).

    I hope someone can help me Smile

    • Moved by Hengzhe Li Friday, April 22, 2011 7:41 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Thursday, December 11, 2008 5:49 PM

Answers

  • We are using the following scenario to show the conflicts to the server:

    1. The server always wins in case of conflicts (As it is not comprehensible for users to have their edits changed without notice)
    2. Conflicts are shown to the client that causes the conflict
    In our 3 tier scenario, we take two steps to show the conflicts to a client:
    1. Synchronize all tables in question applying bidirectional sync
    2. Record conflicts that occur on the server by writing the conflicts to a server table tb_syncproblem in the DbServerSyncProvider_ApplyChangeFailed event.
    3. Subsequently, syncronize tb_syncproblem as download or snapshot synchronization from the server up to the client.
    After these steps, you have all information you need on the client and can display the problem to the user.
    Monday, December 15, 2008 12:22 PM