0

I have two sql server databases, One is server and other is client. I want to sync these databases. I have provisioned the Server and Client Db and Both of them provisioned successfully. But When I execute sync method It gives following error.

Retrieving the COM class factory for component with CLSID {046C184F-2188-4C99-A95A-9C0DCDC19050} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

My code to sync is-

 SqlConnection clientConn = new SqlConnection(@"Data Source=.; Initial Catalog=SyncDbClient; Integrated Security=True");

        SqlConnection serverConn = new SqlConnection("Data Source=.; Initial Catalog=SyncDb; Integrated Security=True");

        // create the sync orhcestrator
        SyncOrchestrator syncOrchestrator = new SyncOrchestrator();

        // set local provider of orchestrator to a sync provider associated with the 
        // MySyncScope in the client database
        syncOrchestrator.LocalProvider = new SqlSyncProvider("MySyncScope", clientConn);

        // set the remote provider of orchestrator to a server sync provider associated with
        // the MySyncScope in the server databasew
        syncOrchestrator.RemoteProvider = new SqlSyncProvider("MySyncScope", 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
        ((SqlSyncProvider)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);
        Console.ReadLine();
Vivek Mishra
  • 1,772
  • 1
  • 17
  • 37

2 Answers2

0

This StackOverflow question references the same error number you mentioned (80040154):

Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80040154

Looks like this user resolved their issue by setting the correct platform target in the VS project file settings.

This might not be the answer but thought I would post it in case it helps.

(Tried to leave this as a comment but I don't have enough reputation points to do so.)

Community
  • 1
  • 1
  • Another StackOverflow question which might be helpful: http://stackoverflow.com/questions/14199072/microsoft-error-while-synchonizing-call-from-iis - It again suggests that the problem may be something to do with 32 vs 64bit components. – James Duffield Apr 14 '15 at 09:18
0

you need to make sure your app's target platform is the same platform as the Sync Fx you installed.

e.g., x86 Sync Fx, app must target x86 as well.

JuneT
  • 7,840
  • 2
  • 15
  • 14