locked
First synchronization is not uploading existing data RRS feed

  • Question

  • I am trying to synchronize a 3.5 SSCE database to a SQL Server 2005 database using a WCF architecture.  The SSCE database is a custom created database (meaning it was not generated by Visual Studio but rather through code using the SqlCeEngine).

     

    Prior to the initial synchronization the client SSCE database has existing transactions.  Therefore, on the first synchronization I need these existing transactions to be uploaded to the server.  I tried to implement a way to do this by attaching an event handler to the SchemaCreated event and then calling the SetTableSentAnchor() method.  I am setting the Sent Anchor value to January 1, 2008 which I know is older than any existing data transactions.  I cannot get this work as described.  The code given below is the SchemaCreated event handler code.

     

    Additionally, I am also setting the ReceivedAnchor to DateTime.Now so that DownloadOnly tables do not pull download-only data on the first synchronization.  Funny thing about this is that it still pulls down some data but each time I try the same test (all test parameters staying equal) the sync service tries to download a different number of duplicate records.  For example, each time I refresh/reset the database and try again the number of "duplicate record" conflicts changes.

     

     

    void client_SchemaCreated(object sender, SchemaCreatedEventArgs e)

    {

    // Initialize the "SentAnchor" on the first synchronization.

    SyncAnchor sentAnchor = ((SqlCeClientSyncProvider)sender).GetTableSentAnchor(e.Table.TableName);

    if (sentAnchor.IsNull())

    {

    using (MemoryStream strm = new MemoryStream())

    {

    byte[] timestamp = BitConverter.GetBytes((new DateTime(2008, 1, 1)).ToBinary());

    BinaryFormatter formatter = new BinaryFormatter();

    formatter.Serialize(strm, timestamp);

    ((SqlCeClientSyncProvider)sender).SetTableSentAnchor(e.Table.TableName, new SyncAnchor(strm.ToArray()));

    }

    }

     

    // Initialize the "ReceivedAnchor" on the first synchronization.

    SyncAnchor receivedAnchor = ((SqlCeClientSyncProvider)sender).GetTableReceivedAnchor(e.Table.TableName);

    if (receivedAnchor.IsNull())

    {

    using (MemoryStream strm = new MemoryStream())

    {

    byte[] timestamp = BitConverter.GetBytes(DateTime.Now.ToBinary());

    BinaryFormatter formatter = new BinaryFormatter();

    formatter.Serialize(strm, timestamp);

    ((SqlCeClientSyncProvider)sender).SetTableReceivedAnchor(e.Table.TableName, new SyncAnchor(strm.ToArray()));

    }

    }

    }

     

     

    Thanks!   ~ Darrin ~

    • Moved by Max Wang_1983 Friday, April 22, 2011 7:53 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Friday, May 2, 2008 11:06 PM