locked
Native Exception on syncAgent.Synchronize() RRS feed

  • Question

  • Hello,

    I am using N tier synchronization to sync SQL compact data with my mobile device using following code. However I get Native Exception and the app crashes on SyncStatistics syncStats = syncAgent.Synchronize() line. however if I use the same code within a desktop application.

    Any ideas will be very helpful.

    Thanks

    apurv

    Code Snippet

      private Exception SynchronizeTables()
            {
                try
                {
                    SyncAgent syncAgent = new SyncAgent();
                    SyncWebServiceProxy.Service syncWebService = new SyncWebServiceProxy.Service();
                    syncWebService.Url = "http://dtlt2341/TestSyncWebService/Service.asmx";
                    syncAgent.RemoteProvider = new ServerSyncProviderProxy(syncWebService);

                    //
                    // 2. Prepare client db connection and attach it to the sync provider

                    if (false == File.Exists(_dbFileLocation))
                    {
                        SqlCeEngine clientEngine = new SqlCeEngine(_connString);
                        clientEngine.CreateDatabase();
                        clientEngine.Dispose();
                    }
                    //                               


                    SqlCeClientSyncProvider clientSyncProvider = new SqlCeClientSyncProvider(_connString);
                    syncAgent.LocalProvider = clientSyncProvider;

                    //
                    // 4. Create SyncTables and SyncGroups
                    // To sync a table, a SyncTable object needs to be created and setup with desired properties:
                    // TableCreationOption tells the agent how to initialize the new table in the local database
                    // SyncDirection is how changes from with respect to client {Download, Upload, Bidirectional or Snapshot}
                    //
                    //
                    SyncTable tableFHGO= new SyncTable("dbo.tbl_forest_health_observations");
                    tableFHGO.CreationOption = TableCreationOption.DropExistingOrCreateNewTable;
                    tableFHGO.SyncDirection = SyncDirection.DownloadOnly;

                  

                    //
                    // Sync changes for both tables as one bunch, using SyncGroup object
                    // This is important if the tables has PK-FK relationship, grouping will ensure that
                    // and FK change won't be applied before its PK is applied
                    //
                    //
                    SyncGroup IFRISSyncGroup = new SyncGroup("AllChanges");
                    tableFHGO.SyncGroup = IFRISSyncGroup;


                    syncAgent.Configuration.SyncTables.Add(tableFHGO);
               

                   

                    //_progressForm = new ProgressForm();
                    //_progressForm.Show();

                    //clientSyncProvider.SyncProgress += new EventHandler<SyncProgressEventArgs>(ShowProgress);
                    try
                    {
                        SyncStatistics syncStats = syncAgent.Synchronize();
                       
                    }

                    catch (Exception ex)
                    {

                    }
                 

                   // _progressForm.EnableClose();
                    //_progressForm = null;

                    return null;

                }
                catch (Exception ex)
                {
                    return ex;

                }
            }


    • Moved by Max Wang_1983 Friday, April 22, 2011 6:02 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Tuesday, August 26, 2008 2:53 PM

Answers

  • figured out. Had to uninstall and re-install sql ce 3.5 components on device. Probably because I installed SQL Ce 3.5 SP1 on desktop but that doesnt get pushed on device it seems.
    Tuesday, August 26, 2008 4:04 PM