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

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 codestatic 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 orhcestratorSyncOrchestrator syncOrchestrator = new SyncOrchestrator();// set local provider of orchestrator to a sync provider associated with the// ProductsScope in the SyncExpressDB express client databasesyncOrchestrator.LocalProvider = new SqlSyncProvider("UserssScope", clientConn);// set the remote provider of orchestrator to a server sync provider associated with// the ProductsScope in the SyncDB server databasesyncOrchestrator.RemoteProvider = new SqlSyncProvider("UsersScope", serverConn);// set the direction of sync session to Upload and DownloadsyncOrchestrator.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 processSyncOperationStatistics syncStats = syncOrchestrator.Synchronize();// print statisticsConsole.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 typeConsole.WriteLine(e.Conflict.Type);// display error messageConsole.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 , thanksTuesday, October 25, 2011 7:31 AM