locked
How to tell if there was a conflict during synchronization? RRS feed

  • Question

  • Hi - I'm new to Microsoft Sync Framework and would appreciate some help with the following question:

    I'm syncing a Sql Server CE 3.5 to Sql Server 2008 using the local data cache in Visual Studio 2008 and WCF Service Lybrary (Proxy).

    I am writing a log file for the sync and would like my application to email me the log file after sync has been completed - but only if there was a conflict on the client and /or the server. From the sync stats at the completion of synchronization I can detect how many changes were downloaded / uploaded or if there was a failure downloading or uploading. But how can I detect if there was a conflict (even a resolved conflict)? I cannot access the serversyncprovider directly, as it's only available via proxy.

    Thank you.

    Edit: Another question that this is connected to: If I decide to email the log file from the serversyncprovider, when would I send it? What event fires to let me know that synchronization is completed on the server? I don't want to send the email each time it enters the applychangefailed event. Is there a way to tell?
    Monday, July 25, 2011 10:05 AM

Answers

  • how did you create the client proxy for your WCF service? did you just uset Add Web Reference /Add Service Reference?

    You can use callbacks to inform the client of events (but am not a big fan of callbacks).

    As i have mentioned, if you look at your proxy, there is call to ApplyChanges, the return value of the server side call is a SyncContext that has the conflicts dataset.

    as for you question number 2, you know the sync is over when your call to Synchronize is done. You can aggregate the conflicts everytime an event is fired and store it somewhere where you can access it after the call to Synchronize.

    • Marked as answer by CWinks Wednesday, July 27, 2011 6:52 PM
    Wednesday, July 27, 2011 1:20 AM
  • Thank you very much for your answer.

    Only after researching the topic of WCF  / Service and Proxy more did I realize that your previous answer contained the information I was looking for, I just hadn't understood it properly...

    The way I implemented my solution was to create another two methods on the service (like the few already exposed) that a) returns the number of conflicts it encountered to the client and b) that tells the serverprovider to end of the log file and return it as a byte array.

    This way I was able to combine both client and server log files and email it as a complete report of what happened during sync when conflicts occur.

    Thanks again for your help!

    • Marked as answer by CWinks Wednesday, July 27, 2011 6:58 PM
    Wednesday, July 27, 2011 6:58 PM

All replies

  • have you tried subscribing to the provider's ChangesApplied event?  the event args should have a Context.GroupProgress.TablesProgress should have conflict collection for each table in the sync group.

     

    Monday, July 25, 2011 10:31 AM
  • Thank you for your reply.

    I tried subscribing to the ChangesApplied event on both the client and the server, like this:

            For Each t As SyncTableProgress In e.Context.GroupProgress.TablesProgress
                If t.Conflicts.Count > 0 Then
                    ....
                End If
            Next

    I was able to get the information I need on the server, but on the client it doesn't detect any conflicts, even if I know that there were! (I guess because there are no conflicts anymore, since they were resolved on the server already.) I still have the two problems I started out with:

    1) How can I know on the client whether there were any conflicts on the server during synchronization?
    2) The changesApplied fires after each batch of changes were applied. What event can I subscribe to that will notify me after all changes to all tables have been completed i.e. when synchronization is complete? So that I can send one email with a log file containing all conflicts?

    Many thanks

    Monday, July 25, 2011 12:55 PM
  • the conflicts on the client and the server are tracked separately, so you have to subscribe to both local and remote provider's events.

    how are you subscribing to the server ChangesApplied? another place you can get the conflicts is in the ApplyChanges method of the proxy. the syncontext return value of the WCF service's ApplyChanges has the conflicts dataset as well.

    afaik, ChangesApplied is the best event to catch. if you're getting it by batch, then you can simply aggregate all the conflicts return by every batch.


    Monday, July 25, 2011 2:02 PM
  • thank you for your reply

    It hasn't helped in my case yet, as my original issues still apply:

    1) I have subscribed to both client and server changesApplied events, and I am getting the correct information from each one individually. My question is, however, if there is any way to get the information from the server to the client. (Like sending a message or upload a file or fire an event from the server to the client) Is there a way to raise an event on the server that gets sent via proxy to the client, that the client can subscribe to? I need the server to somehow communicate with the client.

    2) I still don't have a way of determining when syncing is over on the server's side. What you said is true - I can aggregate all the conflicts. However how can I know when I have reached my last sync group?? Is there any way of telling when the serverSyncProvider has gone through all stages of syncing? It seems strange to me that there isn't anything exposed that enables you to do something after sync is completed. I would expect there to be an event "OnSyncBegin" and something like "OnSyncEnd".

    Any help is really appreciated.


    Edit: On the client there's a syncAgent that orchistrates synchronization. Is there something like that on the server as well???

    Tuesday, July 26, 2011 8:54 AM
  • While trying to find a solution I came up with the following:

    Could I possibly use the WCF service to do a callback communicate with my client? I am a novice at WCF - could someone guide me in the right direction, specifically how to do WCF callback to the client using the service Visual Studio set up for me when I separated the server part of the LocalDataCache into its own service. I'm studying the following: http://johnwsaunders3.wordpress.com/2009/05/17/how-to-consume-a-web-service/ but I don't know how to use it in my situation. Please advise...

    Thank you!

    Tuesday, July 26, 2011 10:06 AM
  • how did you create the client proxy for your WCF service? did you just uset Add Web Reference /Add Service Reference?

    You can use callbacks to inform the client of events (but am not a big fan of callbacks).

    As i have mentioned, if you look at your proxy, there is call to ApplyChanges, the return value of the server side call is a SyncContext that has the conflicts dataset.

    as for you question number 2, you know the sync is over when your call to Synchronize is done. You can aggregate the conflicts everytime an event is fired and store it somewhere where you can access it after the call to Synchronize.

    • Marked as answer by CWinks Wednesday, July 27, 2011 6:52 PM
    Wednesday, July 27, 2011 1:20 AM
  • Thank you very much for your answer.

    Only after researching the topic of WCF  / Service and Proxy more did I realize that your previous answer contained the information I was looking for, I just hadn't understood it properly...

    The way I implemented my solution was to create another two methods on the service (like the few already exposed) that a) returns the number of conflicts it encountered to the client and b) that tells the serverprovider to end of the log file and return it as a byte array.

    This way I was able to combine both client and server log files and email it as a complete report of what happened during sync when conflicts occur.

    Thanks again for your help!

    • Marked as answer by CWinks Wednesday, July 27, 2011 6:58 PM
    Wednesday, July 27, 2011 6:58 PM