locked
SQL CE sync with SQL Server 2008: Just one shot at each record? RRS feed

  • Question

  • I am using the sync framework to synchronize data between a local SQL CE database and a hosted SQL Server 2008 database.  So far everything is working beautifully and I am amazed by this technology.  It is one of the best things that I have seen in 20 years.

    I only have one problem right now.  It appears that when a record cannot be synced from the client to the server, the sync agent will report an error, but only the first time.  After that one shot, it seems to just ignore the record for the rest of it's life.  I want it to attempt to sync that same record every single time, and throw the exception every single time if necessary as well.

    So for example, let's say that I have a customer record that I attempt to sync, but it fails due to a foreign key constraint on the server.  The next day, related records have been added such that the foreign key constraint should no longer cause a problem on the server for the customer record that I am trying to add.  The next time I sync, I would like for it to try that same customer record again.  But instead, it just ignores that record altogether - it neithers syncs it nor does it throw an exception.  It just pretends that the record no longer exists.  That customer record could potentially stay in my local sdf file forever without me even knowing it.

    How can I "reset" that customer record in my local sdf, such that the sync agent tries to synchronize it every single time?

    • Moved by Max Wang_1983 Thursday, April 21, 2011 5:54 PM forum consolidation (From:SyncFx - Technical Discussion [ReadOnly])
    Friday, February 13, 2009 4:24 AM

Answers

All replies

  • It looks like you may be using OCS V1.
    In OCS V1
    once the error is raised the row will not be synced the next time unless the app aborts sync. OCS V1 does not use sync knowledge. By default it has a single number as anchor and the anchor advances if the app decides to continue at the failed row event. If the app does not want to continue then it needs to raise an exception and abort the sync. 
    Another possibility is to store the row that didn’t sync, then retouch the row to let the sync agent pick it up during the next sync.


    Jeremie (Microsoft Sync Framework)
    • Proposed as answer by Jeremie Sartor Saturday, February 14, 2009 1:15 AM
    Saturday, February 14, 2009 1:13 AM
  • That is an outstanding explanation and I understand completely. 

    However, I have not seen anything in the ApplyChangeFailedEventArgs that provides information on the exact record that failed.  I see a lot of very helpful information about the error, but I really need to know the primary key or some other tidbit of information about the record, itself, if I am going to "retouch" it or otherwise fix that particular record.  Surely I am missing something here, because you talk about "storing the row that didn't sync" so there must be some way to get to it.

    Also, at the risk of sounding slow, what is OCS V1?  Are saying that I am running an older version of some component?

    Thanks for your help!
    Saturday, February 14, 2009 10:56 PM
  • Okay, I continued RTFM but ... 

    I realize now that for me, the code that sets up the sync adapter on each table is auto-generate by Visual Studio (I am just adding a new "LocalDatabaseCache" to the project and a wizard generates this code).  So the question is, how do I code for "SelectConflictUpdatedRowsCommand" without modifying the auto-generated code, which could get overwritten?
    Tuesday, February 17, 2009 2:56 PM
  • 'Handle Data Conflicts and Errors' topic [http://msdn.microsoft.com/en-us/library/bb725997.aspx] explains in detail how to handle data conflicts and how to identify the conflicted row. Specifically, EventLogger.LogEvents() in the example, shows how to know which row is in conflict. All the information is in 'ApplyChangeFailedEventArgs'.

    Also, take a look at webcast 'MSDN Webcast: Optimizing Online, Enabling Offline with SQL Server Compact and Sync Services for ADO.NET (Level 200)http://www.microsoft.com/events/series/detail/webcastdetails.aspx?seriesid=114&webcastid=4454
    The 2nd demo in the webcast (starts at 29:03) shows how to extend sync designer code to add custom conflict resolution logic.

    Monday, February 23, 2009 8:54 PM