Problem developing sync app RRS feed

  • Question

  • I am trying to impement the tutorial here:


    I have copied everything and re-implemented it for my database and application. I'm just developing a test bed for my application to show how/that it will work and only synchronizing one table for now.

    I have created my server with the correct columns in the table I wish to sync and I have let the application create the client database on it's own as is described in the tutorial.

    if (!File.Exists(fileName))
        SqlCeEngine clientEngine = new SqlCeEngine(connString);

    This correctly creates my client database. 

    I get the following error when I try to synchronize:

    Unable to obtain a new server anchor. Make sure that you can establish a connection to the server database and that the SelectNewAnchorCommand property of the DbServerSyncProvider is specified correctly.

    I have narrowed this error down to the following code block as it refrences the SelectNewAnchorCommand property:

    SqlCommand anchorCmd = new SqlCommand();
    anchorCmd.CommandType = CommandType.Text;
    //anchorCmd.CommandText = "Select @" + SyncSession.SyncNewReceivedAnchor + " = @@DBTS";  // for SQL Server 2005 SP2, use "min_active_rowversion() - 1"
    anchorCmd.CommandText = "Select @" + SyncSession.SyncNewReceivedAnchor + " = GetDate()";  
    anchorCmd.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.Timestamp).Direction = ParameterDirection.Output;
    serverSyncProvider.SelectNewAnchorCommand = anchorCmd;

    I believe it to be an error with the parameters as the value is assigned as a null at runtime and i get the following SQL query:

    Select @sync_new_received_anchor = GetDate()

    This is an undeclared variable and I was under the impression that the parameters cmmand would have filled this in for me.

    Any help is appreciated.


    Wednesday, February 8, 2012 11:27 AM

All replies

  • GetDate() doesnt return a Timestamp.

    have you tried just running the Local Database Cache Wizard in VS? any particular reason you want to hand code this and use the older database provider?

    Wednesday, February 8, 2012 11:34 AM
  • I don't particularily want to hand code this at all, I have followed the following tutorial previously:


    I have an SQL server ful of data which I was able to synchronize with the client quite successfully. Able to generate and handle conflicts and display all of the data that is in my client table.

    But when it comes to aplying this to my main application and deploy this into a new environment where I don't have control of the main SQL server I am coming over stumbling blocks.

    I have my testing environment SQL Server with data that is syncing fine with my client application. I have created database deployment scripts of the existing database and have made a psudeo production environment, when I change the connection strings of my test application to suddenly point towards the "Empty" new sql server, it gives me errors.

    I'm not a massive fan of the designer because everytime you make a change to the schema of the database you are requiered to re run the designer. Unless of course I have misunderstood what exactlly is happening. 

    I hope this makes sense, thanks for your time.


    Wednesday, February 8, 2012 11:51 AM
  • sync framework doesnt automatically handle schema changes. so in one way or another,you still have to make some tweaks.

    if you use the designer, you can simply modify the generated code to reflect schema changes. if you used stored procs, you have to modify them just the same.

    what exactly is the error you're getting deploying to a new sql server? is it an empty database with no tables? or database with empty tables?

    Wednesday, February 8, 2012 12:04 PM
  • I have a client databse with rows of data in all of the tables, my server is a database with tables that have the same schema as the database that works and no data in them.

    The error that I am getting is the following:

    Unable to enumerate changes at the DbServerSyncProvider for table 'Assessments' in synchronization group 'AssessmentsSyncTableSyncGroup'.

    Wednesday, February 8, 2012 12:20 PM
  • are you using the built-in SQL Server Change Tracking? is it enabled on the new database and its tables?

    try enabling Sync Framework tracing in verbose mode so you get a more detailed error.

    • Edited by JuneT Wednesday, February 8, 2012 12:29 PM
    Wednesday, February 8, 2012 12:27 PM
  • How do I determine if the Change Tracking is enabled on the new database? I created the new database by generating database table creation scripts from the one that works. But there wasn't any mention of change tracking.

    Thanks for your assistance.


    Wednesday, February 8, 2012 2:37 PM
  • right click on the database, click properties and you should see an option for Change Tracking.

    Change Tracking should be enabled on the database and on the tables you want to sync.

    this is assuming you chose to use Sql Change Tracking when you  used the wizard.

    Wednesday, February 8, 2012 2:43 PM
  • I have checked on the SQL Server and there isn't a property for change tracking, this is most likely to do with the SQL Server being a 2005 server.

    I have also checked the wizard and "Use SQL Server change tracking" is Disabled.


    Wednesday, February 8, 2012 2:53 PM
  • if you're previous code is working against the built-in SQL Change Tracking and you re-point to a database not supporting Change tracking, that explains the error.

    you might have to regenerate the code to use custom change tracking.

    Thursday, February 9, 2012 1:38 AM