locked
Batching remote server to compact edition. How can I get it to work? RRS feed

  • Question

  • Hi Everyone,

    I have a remote SQL 2005 database and am trying to synchronize with CE on my local machine.  Most of the tables sync okay.   One table however is very large, has some modest sized images in it and 24000 rows resulting in about 4 gb.  So in order to sync this table, at least to make the initial snapshot, I am attempting to use batching.  I have implemented most of the events associated with the Orchestrator and the progress event on SyncCeProvider.  When I attempt to sync, the networking graph on Task Manager shows an encouraging steady network traffic but even though I am running on a fairly fast network connection the sync will not complete.  With breakpoints in all the events, none of them fire. Also no files appear in the batching directory.  Can anyone help please.  My code is shown below:

        class Sync_Engine
        {
            public void Sync_tblItemSample()
            {
    
                // create the sync orhcestrator
               
                SqlCeSyncProvider p = new SqlCeSyncProvider("tblItemSampleScope", DB.ceConn);
                p.MemoryDataCacheSize = 2000;
                p.BatchingDirectory = @"C:\Users\Chris Tagg\Documents\CSI\MakeSnapshotOfLibrary\Batching Directory";
                
                p.SyncProgress += new EventHandler<DbSyncProgressEventArgs>(p_SyncProgress);
    
                MySyncOrchestrator syncOrchestrator = new MySyncOrchestrator(p, new SqlSyncProvider("tblItemSampleScope", DB.conn));
                // subscribe for errors that occur when applying changes to the client
                ((SqlCeSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed
                    += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);
    
                ((SqlCeSyncProvider)syncOrchestrator.LocalProvider).BatchSpooled += new EventHandler<DbBatchSpooledEventArgs>(Sync_Engine_BatchSpooled);
                ((SqlCeSyncProvider)syncOrchestrator.LocalProvider).BatchApplied += new EventHandler<DbBatchAppliedEventArgs>(Sync_Engine_BatchApplied);
    
                ((SqlCeSyncProvider)syncOrchestrator.LocalProvider).ApplyingChanges += new EventHandler<DbApplyingChangesEventArgs>(Sync_Engine_ApplyingChanges);
                ((SqlCeSyncProvider)syncOrchestrator.LocalProvider).ChangesSelected += new EventHandler<DbChangesSelectedEventArgs>(Sync_Engine_ChangesSelected);
                ((SqlCeSyncProvider)syncOrchestrator.LocalProvider).ChangesApplied += new EventHandler<DbChangesAppliedEventArgs>(Sync_Engine_ChangesApplied);
                ((SqlCeSyncProvider)syncOrchestrator.LocalProvider).SelectingChanges += new EventHandler<DbSelectingChangesEventArgs>(Sync_Engine_SelectingChanges);
                // execute the synchronization process
                Console.WriteLine("Sync about to start");
                SyncOperationStatistics syncStats = syncOrchestrator.Synchronize();
                syncOrchestrator.DisplayStats(syncStats, "initial");
    
            }
    
            void Sync_Engine_SelectingChanges(object sender, DbSelectingChangesEventArgs e)
            {
                Console.WriteLine("Selecting Changes: " + e.ToString());
            }
    
            void p_SyncProgress(object sender, DbSyncProgressEventArgs e)
            {
                Console.WriteLine("Sync Progress: " + e.ToString());
            }
    
            void Sync_Engine_ChangesApplied(object sender, DbChangesAppliedEventArgs e)
            {
                Console.WriteLine("Changes Applied: " + e.ToString());
            }
    
            void Sync_Engine_ChangesSelected(object sender, DbChangesSelectedEventArgs e)
            {
                Console.WriteLine("Changes Selected: " + e.ToString());
            }
    
            void Sync_Engine_ApplyingChanges(object sender, DbApplyingChangesEventArgs e)
            {
                Console.WriteLine("Applying Changes: " + e.ToString());
            }
    
            void Sync_Engine_BatchApplied(object sender, DbBatchAppliedEventArgs e)
            {
                Console.WriteLine("Batch Applied: " + e.ToString());
            }
    
            void Sync_Engine_BatchSpooled(object sender, DbBatchSpooledEventArgs e)
            {
                Console.WriteLine("Batch Spooled: " + e.ToString());
            }
    
            public static void Sync_tblItemNPIAPattern()
            {
    
                // create the sync orhcestrator
                SyncOrchestrator syncOrchestrator = new SyncOrchestrator();
    
                // set local provider of orchestrator to a CE sync provider associated with the 
                // ProductsScope in the SyncCompactDB compact client database
                syncOrchestrator.LocalProvider = new SqlCeSyncProvider("tblItemNPIAPatternScope", DB.ceConn);
    
                // set the remote provider of orchestrator to a server sync provider associated with
                // the ProductsScope in the SyncDB server database
                syncOrchestrator.RemoteProvider = new SqlSyncProvider("tblItemNPIAPatternScope", DB.conn);
    
                // set the direction of sync session to Upload and Download
                syncOrchestrator.Direction = SyncDirectionOrder.Download;
    
                // subscribe for errors that occur when applying changes to the client
                ((SqlCeSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed
                    += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);
    
                // execute the synchronization process
                SyncOperationStatistics syncStats = syncOrchestrator.Synchronize();
    
                // print statistics
                Console.WriteLine("Start Time: " + syncStats.SyncStartTime);
                Console.WriteLine("Total Changes Uploaded: " + syncStats.UploadChangesTotal);
                Console.WriteLine("Total Changes Downloaded: " + syncStats.DownloadChangesTotal);
                Console.WriteLine("Complete Time: " + syncStats.SyncEndTime);
                Console.WriteLine(String.Empty);
    
            }
    
            public static void Sync_tblItemTag()
            {
    
                // create the sync orhcestrator
                SyncOrchestrator syncOrchestrator = new SyncOrchestrator();
    
                // set local provider of orchestrator to a CE sync provider associated with the 
                // ProductsScope in the SyncCompactDB compact client database
                syncOrchestrator.LocalProvider = new SqlCeSyncProvider("tblItemTagScope", DB.ceConn);
    
                // set the remote provider of orchestrator to a server sync provider associated with
                // the ProductsScope in the SyncDB server database
                syncOrchestrator.RemoteProvider = new SqlSyncProvider("tblItemTagScope", DB.conn);
    
                // set the direction of sync session to Upload and Download
                syncOrchestrator.Direction = SyncDirectionOrder.Download;
    
                // subscribe for errors that occur when applying changes to the client
                ((SqlCeSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed
                    += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);
    
                // execute the synchronization process
                SyncOperationStatistics syncStats = syncOrchestrator.Synchronize();
    
                // print statistics
                Console.WriteLine("Start Time: " + syncStats.SyncStartTime);
                Console.WriteLine("Total Changes Uploaded: " + syncStats.UploadChangesTotal);
                Console.WriteLine("Total Changes Downloaded: " + syncStats.DownloadChangesTotal);
                Console.WriteLine("Complete Time: " + syncStats.SyncEndTime);
                Console.WriteLine(String.Empty);
    
            }
    
            public static void Sync_tblItemPattern()
            {
    
                // create the sync orhcestrator
                SyncOrchestrator syncOrchestrator = new SyncOrchestrator();
    
                // set local provider of orchestrator to a CE sync provider associated with the 
                // ProductsScope in the SyncCompactDB compact client database
                syncOrchestrator.LocalProvider = new SqlCeSyncProvider("tblItemPatternScope", DB.ceConn);
    
                // set the remote provider of orchestrator to a server sync provider associated with
                // the ProductsScope in the SyncDB server database
                syncOrchestrator.RemoteProvider = new SqlSyncProvider("tblItemPatternScope", DB.conn);
    
                // set the direction of sync session to Upload and Download
                syncOrchestrator.Direction = SyncDirectionOrder.Download;
    
                // subscribe for errors that occur when applying changes to the client
                ((SqlCeSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed
                    += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);
    
                // execute the synchronization process
                SyncOperationStatistics syncStats = syncOrchestrator.Synchronize();
    
    
                // print statistics
                Console.WriteLine("Start Time: " + syncStats.SyncStartTime);
                Console.WriteLine("Total Changes Uploaded: " + syncStats.UploadChangesTotal);
                Console.WriteLine("Total Changes Downloaded: " + syncStats.DownloadChangesTotal);
                Console.WriteLine("Complete Time: " + syncStats.SyncEndTime);
                Console.WriteLine(String.Empty);
    
            }
    
            static void Program_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e)
            {
                // display conflict type
                Console.WriteLine(e.Conflict.Type);
    
                // display error message 
                Console.WriteLine(e.Error);
            }
        }
    
        public class MySyncOrchestrator : SyncOrchestrator
        {
            public MySyncOrchestrator(RelationalSyncProvider local, RelationalSyncProvider remote)
            {
                this.LocalProvider = local;
                this.RemoteProvider = remote;
                this.Direction = SyncDirectionOrder.Download;
            }
            
            public void DisplayStats(SyncOperationStatistics syncStats, string syncType)
            {
                if (syncType == "initial")
                {
                    Console.WriteLine("*************** Initial Syncronisation **********************");
                }
                else if (syncType == "subsequent")
                {
                    Console.WriteLine("*************** Subsequent Syncronisation **********************");
                }
    
                Console.WriteLine("Start Time: " + syncStats.SyncStartTime);
                Console.WriteLine("Total Changes Uploaded: " + syncStats.UploadChangesTotal);
                Console.WriteLine("Total Changes Downloaded: " + syncStats.DownloadChangesTotal);
                Console.WriteLine("Complete Time: " + syncStats.SyncEndTime);
                Console.WriteLine(String.Empty);
            }
    
        }
    


    Chris Tagg

    Monday, August 13, 2012 2:36 PM

Answers

  • for the events you want to listen to, you subscribe to the the localprovider which is your client. your sync direction is download, so the changesselected, selectingchanges are firing on your remote provider.

    if you want to debug further, enabling sync framework tracing in verbose mode: http://msdn.microsoft.com/en-us/library/cc807160.aspx

    also, you mentioned you have images, what's your row size? the batch size cannot be lower than the row size. sync fx will not split a row into separate batches.

    • Marked as answer by Chris Tagg Thursday, August 16, 2012 8:21 AM
    Monday, August 13, 2012 3:01 PM

All replies

  • for the events you want to listen to, you subscribe to the the localprovider which is your client. your sync direction is download, so the changesselected, selectingchanges are firing on your remote provider.

    if you want to debug further, enabling sync framework tracing in verbose mode: http://msdn.microsoft.com/en-us/library/cc807160.aspx

    also, you mentioned you have images, what's your row size? the batch size cannot be lower than the row size. sync fx will not split a row into separate batches.

    • Marked as answer by Chris Tagg Thursday, August 16, 2012 8:21 AM
    Monday, August 13, 2012 3:01 PM
  • Thank you JuneT.

    The rows should not be more than a single megabyte.  I have tried setting the batch size to 20 mb without success.  I will look at verbose tracing later on in the week.  I have been pulled off this job temporarily.  I will let you know how I get on. - Chris


    Chris Tagg

    Monday, August 13, 2012 3:33 PM
  • Thanks JuneT

    Got it working! - Chris


    Chris Tagg

    Thursday, August 16, 2012 8:22 AM