Strange problem propagating changes back to client during n-tier bidirectionnal sync RRS feed

  • Question

  • Hi all,

    Using visual studio 2008 and the local data cache Sync wizard got the Bi-directional Scenario to work after following the instructions in the New Pdf doc that explains how to extend the designer code but did not remove server tracking columns from sync commands (I couldn't get the bi-directional sync to work after doing that.. and seems like it is just a precaution)

    I am now trying to do some custom conflict resolution, and have followed the advice given to me in a previous post to put a unique key index on a column where I need to avoid duplicates but is not the PK to make the insert of these duplicates fail so that I can handle the ErrorsOccured conflict type and do some custom changes before inserting the client changes on the server, and then having these changes persisted to the client on download.


    Thanks Yummen Bai by the way!

    I got as far as being ables to get the columns changed befor inserting them on the server but even after handeling the ChangesApplied event too do a dummy update on the fields that I have changed on the server so that they get downloaded again to the client, the changes do not get downloaded.

     Here is the dummy update to make sure the LastEditDate field is different
    Code Snippet

    void LCQLocalDataCacheServerSyncProvider_ChangesApplied(object sender,
    Microsoft.Synchronization.Data.ChangesAppliedEventArgs e)


                //If _updateConflictGuids contains at least one GUID, update the UpdateId

                //column so that each change is downloaded to the client.

                if (_updateConflictGuids.Count > 0)


                    SqlCommand updateTable = new SqlCommand();

                    updateTable.Connection = (SqlConnection)e.Connection;

                    updateTable.Transaction = (SqlTransaction)e.Transaction;

                    updateTable.CommandText = String.Empty;

                    for (int i = 0; i < _updateConflictGuids.Count; i++)


                        updateTable.CommandText +=

                            " UPDATE dbo.company SET sync_LastEditDate= null " +

                            " WHERE company_guid='" + _updateConflictGuids[i].ToString() + "'";





    I then changed the code so that i have 2 buttons, one that uploads and one that downloads. I upload first, the changes are applied and all works fine. Then I try downloading but the changes still don't get downloaded.. I have to actually do two updates manually on the server so that the changes get sent to the client.

    Does somebody have an idea?

    • Moved by Max Wang_1983 Friday, April 22, 2011 7:16 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Tuesday, June 24, 2008 6:11 PM

All replies


    there could be two possible reasons why the rows cannot be downloaded even you did the dummy update:


    1. the LastEditDate was set to NULL. this is incorrect, since where LastEditDate > @lastRecvAnchor will be false if the LastEditDate value is null. please change it to  " UPDATE dbo.company SET sync_LastEditDate= getdate() " + ( or getUTCDate() based on your design


    2. the update should update the UpdateOriginatorId to 0 ( or whatever value you choose for server changes ).


    I would expect #2 would be the cause for your case. I list #2 here since this would be a good pratice to make the two tracking columns changed at the same time.




    Tuesday, June 24, 2008 11:51 PM
  • Hi Yunwen

    Thank for the quick reply!

    for #1, I tried this and it has the same effect, the thing is that whatever I change in the update in ChangesApplied, the value of lastEditDate gets changed again with the onUpdate trigger in the database. The only thing I was trying to do is to just update anything to fire the onUpdate trigger.

    for #2, I am using the designer generated code, and followed the new documentation that explains how to extend this code for bidirectional sync, but no UpdateOriginatorId field is added using the wizard, and the docs don't say it is necessary to add it. I read somewhere that it just prevents the fields that have just been uploaded to be downloaded to the same client, but that this was just an optimization.

    I can't think of anything... I'll try to explain my scenario:

    Client DB:

    0001  "Company A"

    Server DB:

    GUID  NAME                              lastEditDate               CreationDate
    0002  "Company A"                    25/06/2008 09:51:34    25/06/2008 09:51:34

    After upload:

    Server DB:

    GUID  NAME                              lastEditDate               CreationDate
    0001   "Company A duplicate"     25/06/2008 09:53:58   25/06/2008 09:53:21
    0002   "Company A"                  
    25/06/2008 09:51:34   25/06/2008 09:51:34

    After Download 1 (even after the code to do the dummy update executes and I do another manual dummy update on the server)

    Client DB:

    GUID  NAME                     
    0001   "Company A"
    0002   "Company A

    So it downloads the company that wasn't on the client before, but doesn't download the changes made to the 0001 row. note that i don't have a unique key index on the client db, because all the conflicts are handled on the server.

    After Download 2 (after a manual dummy update on any field just to fire the update trigger again)

    Client DB:
    GUID  NAME                     
    0001   "Company A
    0002   "Company A

    It downloads the changes this time...

    So it is only after downloading once and then updating the row on the server and downloading again that the change is downloaded.



    Wednesday, June 25, 2008 10:02 AM
  • thanks, I can see row 0002 was downloaded to the client which is a good sign.


    can you check:

    1. what is the primary key column on the table ? are you relying on the unique index ?

    2. on the client, can you implement the ApplyingChanges event and check if the row 0001, "company A duplicate" was in the dataset to be applied ?

    3. on client, can you implement the ApplyChangeFailed event to see if there is any error indicating "row cannot be found "  if #2 shows the row is there.

    4. check the client database to see what is the Primary key column on the table.


    This would help us to narrow down this issue.




    Wednesday, June 25, 2008 6:25 PM