How to provide '@sync_last_received_anchor' parameter? RRS feed

  • Question

  • Hey,

    I am quite new to the SyncFX and am using it, to sync a SQLCE db on a PDA via a WCF service to a server db running on SQL 2008.

    When I am executing my code, the GetSchema() works fine and the schema is successfully synched to the client. But when the method GetChanges() is called, I am getting the following error:

    Unable to enumerate changes at the DbServerSyncProvider for table 'Study' in synchronization group 'Study'.
    Inner Ex: The parameterized query '(@sync_last_received_anchor datetime2(7),@sync_new_received_anch' expects the parameter '@sync_last_received_anchor', which was not supplied.

    I adapted a sample project from the SyncFX homepage to do my synchronization. (http://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=sync&ReleaseId=1713) At the sample, everything works fine, but my code does not work.

    I don't know, how to provide the missing parameter, 'cause usually, the SyncFX is doing it itself, isn't it?

    I tried out several modes for SyncDirection: Snapshot, DownloadOnly and Bidirectional, but none of them works for me.

    On the client side, I am using the following code for the SyncAgent Init:

        public abstract class SyncServiceBase : SyncAgent
            protected virtual void AddSyncTable(string table, SyncDirection direction, TableCreationOption option)
                Configuration.SyncTables.Add(table, option, direction);
        public class StudiesSyncService :  SyncServiceBase
            public const string STUDY_TABLE = "Study";
            public StudiesSyncService()
                //Hook between SyncAgent and SqlCeClientSyncProvider
                LocalProvider =
                    new SqlCeClientSyncProvider(App.LocalConnectionString, true);
                AddSyncTable(STUDY_TABLE, SyncDirection.Bidirectional, TableCreationOption.DropExistingOrCreateNewTable);           
                RemoteProvider =
                    new ServerSyncProviderProxy(CSSServiceFacade.Service, TableScope.Studies);

    On the server side, the following code snippets:

        public class StudiesSyncProvider : DbServerSyncProvider
            public const string STUDY_TABLE = "Study";
            public StudiesSyncProvider()
                Connection = new SqlConnection(AppFacade.ConnectionString);
                // SelectNewAnchor command
                SqlCommand selectNewAnchorCmd = new SqlCommand();
                selectNewAnchorCmd.CommandText = "SELECT @" + SyncSession.SyncNewReceivedAnchor + " = GETUTCDATE()";
                SqlParameter newRecAnchor = new SqlParameter();
                newRecAnchor.ParameterName = "@" + SyncSession.SyncNewReceivedAnchor;
                newRecAnchor.DbType = DbType.DateTime2;
                newRecAnchor.Direction = ParameterDirection.Output;
                SelectNewAnchorCommand = selectNewAnchorCmd;
                AddSyncAdapter(STUDY_TABLE, "Study_GUID", "StartDate", "EndDate", "LastEditDate", "CreationDate");
            protected virtual void AddSyncAdapter(string tablename, params string[] columns)
                // Property Details
                var builder = new SqlSyncAdapterBuilder((SqlConnection)this.Connection);
                builder.SyncDirection = SyncDirection.Bidirectional;
                builder.CreationTrackingColumn = "CreationDate";
                builder.UpdateTrackingColumn = "LastEditDate";
                builder.TableName = tablename;
                if (columns != null && columns.Length > 0) 
                var adapter = builder.ToSyncAdapter();
                adapter.TableName = tablename;
                // Add the configured adapter to the collection

    Does anybody see an error in this code or know, why my code is not working correctly?

    Thanks for any reply in advance.

    Best regards,

    • Edited by Harald Köstinger Sunday, April 26, 2009 11:51 AM
    • Moved by Hengzhe Li Friday, April 22, 2011 3:23 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Sunday, April 26, 2009 11:49 AM


  • Hi together,

    almost 10 hours later to the post, I found out, what the problem is/was.

    as you see in the code above, I worked with the new SQL Server data type datetime2. But somehow, this seems to cause the problem in my case.

    On the sql server, I worked with the default value of getdate() for the CreationDate and LastEditDate fields.
    Somehow, this was a little bit to much for the sync FX.

    What did I do?
    * changed all the CreationDate and LastEditDate fields from datetime2(7) back to datetime with default getutc date()
    * worked with DbType.DateTime in the code

    Everything works fine now.

    Best regards,
    Sunday, April 26, 2009 9:51 PM