locked
Unable to cast object of type 'Microsoft.Synchronization.Data.SqlServer.SqlSyncProvider' to type 'Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider'. RRS feed

  • Question

  • I have a program that sync sqlserver 2008 and sqlexpress2008 and im getting this error :

    Unable to cast object of type 'Microsoft.Synchronization.Data.SqlServer.SqlSyncProvider' to type 'Microsoft.Synchronization.Data.SqlServerCe.SqlCeSyncProvider'.

    any help

     

    Tuesday, October 25, 2011 7:09 AM

Answers

  • your local provider is of type SqlSyncProvider but you're casting it as SqlCeSyncProvider here:

      ((SqlCeSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed

    change this to :

      ((SqlSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed

    • Marked as answer by pnthree Tuesday, October 25, 2011 7:30 AM
    Tuesday, October 25, 2011 7:22 AM

All replies

  • can you post the part where you're getting the error?
    Tuesday, October 25, 2011 7:13 AM
  • here is my code
     static void Main(string[] args)
            {
                SqlConnection clientConn = new SqlConnection(@"Data Source=.\express; Initial Catalog=PMS; Persist Security Info=True;User ID=sa;Password=4dm1np455");
                SqlConnection serverConn = new SqlConnection(@"Data Source=.\sqlserver2008; Initial Catalog=PMS; Persist Security Info=True;User ID=sa;Password=4dm1np455");
                // create the sync orhcestrator
                SyncOrchestrator syncOrchestrator = new SyncOrchestrator();
                // set local provider of orchestrator to a sync provider associated with the 
                // ProductsScope in the SyncExpressDB express client database
                syncOrchestrator.LocalProvider = new SqlSyncProvider("UserssScope", clientConn);
                // set the remote provider of orchestrator to a server sync provider associated with
                // the ProductsScope in the SyncDB server database
                syncOrchestrator.RemoteProvider = new SqlSyncProvider("UsersScope", serverConn);
                // set the direction of sync session to Upload and Download
                syncOrchestrator.Direction = SyncDirectionOrder.UploadAndDownload;
                // 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);
        }
    Tuesday, October 25, 2011 7:17 AM
  • your local provider is of type SqlSyncProvider but you're casting it as SqlCeSyncProvider here:

      ((SqlCeSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed

    change this to :

      ((SqlSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed

    • Marked as answer by pnthree Tuesday, October 25, 2011 7:30 AM
    Tuesday, October 25, 2011 7:22 AM
  • it worked , thanks
    Tuesday, October 25, 2011 7:31 AM