locked
Microsoft Sync Framework: Sql CE and sql 2008 RRS feed

  • Question

  • Microsoft Sync Framework:

    Sql CE and sql 2008 with change tracking option.

    I am facing a problem, when i have a record inserted in sql CE and it needs to upload on sql 2008 with uploadonly direction. The server sync process gives clientInsertServerInsert conflict and it is impossible that server can add new row to this table.

    Anybody have idea.

    Another thing i noticed is that if I use the sql sever ce database created by VS.NET's design time sync UI(where you select the tables you want in your client db) the problem does not occurs. But when i distribute my application with blank sql sever ce database the error is throw for each inserted row on client.

    When we made any change in client database (SqlCE), the changes are uploaded and fire ApplyChangeFailed event with conflict ClientInsertServerInsert if a new row is inserted. For example i have a table books (Name, Qty) and i have configure this table direction UploadOnly when i insert an record on client it goes to server successfully but conflict occurred "ClientInsertServerInsert" that mean server also insert same value that is impossible. And if on all changes conflict arises it slow down the process, and may cause problem. i use this line to continue.e.Action = ApplyAction.Continue;

    Anchor issue?

    Thursday, April 1, 2010 1:53 PM

Answers

  • the last received anchor will not be set since you're only uploading changes. what was the names of the two extra columns on the server change conflict row?

    the "ClientInsertServerInsert" conflict is quite confusing as it may not necessarily mean a duplicate row has been inserted on both local and remote replicas. It can actually mean that the insert simply failed.

    I'm guessing you get the error because of this part in the Insert command:

       "IF CHANGE_TRACKING_MIN_VALID_VERSION(object_id(@sync_table_name)) > @sync_last_received_anchor " +
                        "RAISERROR (N'SQL Server Change Tracking has cleaned up tracking information for table ''%s''. " +
                        "To recover from this error, the client must reinitialize its local database and try again'" +
                        ",16,3,@sync_table_name)";

    Since you are synching UploadOnly, the received anchor is null and such would cause the error. And the error is not necessarily because of a duplicate insert.

    you may want to settle with setting sync to bidirectional and just configure sync not to download changes... you will actually run into issues with uploading updates later... chk out http://jtabadero.spaces.live.com/blog/cns!BF49A449953D0591!1207.entry on how to enable bidirectional sync and the issue with updates.

    • Marked as answer by malik123 Sunday, April 4, 2010 8:27 AM
    Saturday, April 3, 2010 2:20 PM

All replies

  • 1. Did SQL server table has those rows (seemed conflicts) before the sync?

    2. How was the SQL CE database created (for the sync app)? Did you create blank SQL CE database and insert rows which already inserted on the server?

    Thanks.


    Leo Zhou ------ This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, April 1, 2010 4:55 PM
    Answerer
  • adding to Leo's question, what's your primary key? anything else contained in the error property (e.Error)?
    Friday, April 2, 2010 4:07 AM
  • No sql server does not have those rows before.

    Once i try to add my own empty schema and then i remove the database and now sync provide create database during sync.

    NO SERVER DOES NOT HAVE THE ROW THAT IS INSERTER ON SQLCE.

    Basically the row key is uniequeidentifier on client and server and is not an identity.

    The problem seems to be with anchors as when new db is created by sync designer and then it is used in sync operation no conflict arise on my machine.

    But when i delete the db as there are no filter applies on design time. The new db is created by sync provider automatically and then on each change on client i got conflict.

    I use WCF for server sync process.

    Error property is empty.

    Thanks

     

    Friday, April 2, 2010 5:51 AM
  • am assuming you just changed the sync direction to UploadOnly after the designer generated code, is that right?

    can you do a trace of the SQL being sent to the server using SQL Profiler?

    try also comparing the contents of the ClientChange and ServerChange in the Conflict property of the ApplyChangeFailedEventArgs

    Friday, April 2, 2010 1:22 PM
  • No direction was define in partial class before the designer execution. If i use the designer db it have no conflicts but when i delete the db and sync service create the new db, only upload direction table cause conflict. The data is same on client and server change, only server has two extra column, one is like System.Byte and one is empty.

    I have noticed that if i use bi-direction i have no conflict. In this case we need to filter that no records come down. The main thing i have noticed that system table of CE database __syssyncArticles have null value in Received anchor for upload only tables in the newly created db.

    And i think this error is come "the client must reinitialize its local database and try again" with conflict.

     

    Am i missing something or i m giving the direction on wrong place.

    I really appreciate your response.

    Saturday, April 3, 2010 4:47 AM
  • the last received anchor will not be set since you're only uploading changes. what was the names of the two extra columns on the server change conflict row?

    the "ClientInsertServerInsert" conflict is quite confusing as it may not necessarily mean a duplicate row has been inserted on both local and remote replicas. It can actually mean that the insert simply failed.

    I'm guessing you get the error because of this part in the Insert command:

       "IF CHANGE_TRACKING_MIN_VALID_VERSION(object_id(@sync_table_name)) > @sync_last_received_anchor " +
                        "RAISERROR (N'SQL Server Change Tracking has cleaned up tracking information for table ''%s''. " +
                        "To recover from this error, the client must reinitialize its local database and try again'" +
                        ",16,3,@sync_table_name)";

    Since you are synching UploadOnly, the received anchor is null and such would cause the error. And the error is not necessarily because of a duplicate insert.

    you may want to settle with setting sync to bidirectional and just configure sync not to download changes... you will actually run into issues with uploading updates later... chk out http://jtabadero.spaces.live.com/blog/cns!BF49A449953D0591!1207.entry on how to enable bidirectional sync and the issue with updates.

    • Marked as answer by malik123 Sunday, April 4, 2010 8:27 AM
    Saturday, April 3, 2010 2:20 PM
  • Thanks for your help.

    Sunday, April 4, 2010 8:28 AM
  • Hi

    I am using wcf service for remote provider as server is on another machine.

    Following is the line of code where i set the remote provider.

    this.RemoteProvider = new ServerSyncProviderProxy(new SplSynchronizationContractsClient());

    How can i set it with server provide to access adapter command as you mention bellow.

    1. LocalDataCache1ServerSyncProvider remoteProvider = (LocalDataCache1ServerSyncProvider )syncAgent.RemoteProvider;
    2. remoteProvider.TestSyncAdapter.SelectIncrementalInsertsCommand = null ;

    I try to set the commands on server library but i found following error.

    Unable to initialize the client database, because the schema for table 'Logs' could not be retrieved by the GetSchema() method of DbServerSyncProvider. Make sure that you can establish a connection to the client database and that either the SelectIncrementalInsertsCommand property or the SelectIncrementalUpdatesCommand property of the SyncAdapter is specified correctly.

     

    Can you please have a look on my comments and give an idea?

    Thanks

    Monday, April 5, 2010 10:33 AM
  • how did you go about creating your WCF service?

     

    Monday, April 5, 2010 2:36 PM
  •  

    Check this architecture, i have same scenario.

    http://www.codeproject.com/KB/smart/sync_services.aspx

    Monday, April 5, 2010 4:28 PM
  • alright, so am assuming you used the designer to generate the WCF service then.

    you can locate the file suffixed .SyncContract.cs.

    locate the constructor (suffixed SyncService), then you can access the adapter from this._serverSyncProvider

     

     

     

    Tuesday, April 6, 2010 1:30 AM