locked
Merge Conflict Resolution Policy using Client Sync Provider and DbServerSyncProvider. RRS feed

  • Question

  • Hi,

    I am using SqlExpressClientSyncProvider as a client sync provider and DbServerSyncProvider as a server sync provider. Here I am using Sql server 2008 change tracking for tracking the changes and I am doing BiDirectional Synchronization for my purpose. Here in case of ClientInsertServerInsert type of Conflict I want to have both data of client and server. Basically I want to implement Merge conflict resolution i.e the changes from both source and destination are merged to form a new version of the item, which is then sent to the destination to be applied(in bidirectional it should applied to both source and destination).  I have seen examples of doing that using SqlSyncProvider. Can I do this using DbServerSyncProvider. Or can I use custom conflict resolution in DbServerSyncProvider. Please give me some hint or provide some example for the same.

    Thanks,

    <input id="gwProxy" type="hidden"></input> <input id="jsProxy" onclick="jsCall();" type="hidden" />
    Monday, April 26, 2010 7:49 PM

Answers

  • you should be good with your approach then.

     just replace the primary key in the change dataset (e.Context.DataSet) for  the conflicting row and retry applying the change (ApplyAction.RetryWithForceWrite)

    Wednesday, April 28, 2010 12:23 PM

All replies

  • you can subscribe to the ApplyChangesFailed event, catch the ClientInsertServerInsert conflict, inspect the conflicting rows (e.Conflict.ServerChange and e.Conflict.ClientChange) and then merge.

    see the ClientUpdateServerUpdate sample merge here : http://msdn.microsoft.com/en-us/library/bb725997(SQL.105).aspx

    Monday, April 26, 2010 11:50 PM
  • Hi JuneT,

    Thanks for your reply, In the above example it is for ClientUpdateServerUpdate scenario and they also using GUID column as a primary key.

    Here in this case we have Primary key data type is integer. When client insert a row with some primary key and server also inserts the row with same primary key. So as a result I want both rows to be merged in both database. See example below for more explanation.

    Example:

    Customer (Client db) (we have customer client db, which has inserted one row with primary key 100)

    Customer_id(PK) name,    city

    100                     abc       NY

     

    Customer (Server db) (we have customer server db, which has inserted one row with primary key 100)

    Customer_id(PK)    name,    city

    100                        xyz        SFO

     

    While synchronizing it will detect the ClientInsertServerInsert conflict, so I want it to resolve as merge resolution and after synchronization data will be like this in both tables

    Client table

    Customer_id(PK) name,    city

    100                     abc       NY

    101                     xyz       SFO

    --------------------------------------------

    Server table

    Customer_id(PK)    name,    city

    100                     abc       NY

    101                     xyz       SFO

    What could be the possible solution for this, can't Sync framework handle this by default. Or we need to make custom resolution(changing primary key by our own) for that. Or we should use GUID as a primary key for this.

     

    Tuesday, April 27, 2010 10:49 AM
  • i just cited the example on the link to give you an idea how to go about inspecting the client and the server values.

    to answer your question, no, Sync Fx can't handle merging or resolving PK violations by default (you can tell it though if you want to keep the client row or the server row).

    Even if you change one of the keys during the conflict resolution (in ApplyChangeFailed event), you still have a chance of having a potential conflict with another client uploading the same key (in your example, you changed the server row to 101, what if client XYZ also uses 101?)

    If you are able to change the PK to use GUIDs then much better.

    See http://msdn.microsoft.com/en-us/library/bb726011.aspx for more details on choosing appropriate primary keys.

    hth,

    junet

    Tuesday, April 27, 2010 11:29 AM
  • Hi junet,

    Thanks for you reply, we are using different range of primary keys in differnet client in order to prevent primary key collision, and it is working fine.

    Thanks

    Wednesday, April 28, 2010 10:55 AM
  • you should be good with your approach then.

     just replace the primary key in the change dataset (e.Context.DataSet) for  the conflicting row and retry applying the change (ApplyAction.RetryWithForceWrite)

    Wednesday, April 28, 2010 12:23 PM