I am trying to set up synchronization between two SQL Compact 3.5 databases using SqlCeSyncProvider. I am able to create a scope for the two databases, which creates a meta table. When I try to run SyncOrchestrator.Synchronize() though, I get the following error and am not able to get the two databases to synchronize when I insert data:

"An error occurred when initializing adapters for scope 'Person'. Ensure that the scope name specified on the provider exists in the scope metadata table, and that the correct base tables are specified for that scope."

When I run the following code, three tables are created for each database: Sync_Person_tracking, Sync_scope_config, and Sync_scope_info. Both databases contain the same scope name of Person in the Sync_scope_info table.

    SqlCeSyncScopeProvisioning ceConfig = new SqlCeSyncScopeProvisioning();
    SqlCeConnection ceConn = (SqlCeConnection)syncProvider.Connection;
    string scopeName = syncProvider.ScopeName;
    if (!ceConfig.ScopeExists(scopeName, ceConn)) {
        var description = new DbSyncScopeDescription();
        description.ScopeName = scopeName;
        var table = new DbSyncTableDescription("Person");
        var pkCol = new DbSyncColumnDescription("ID", "int");
        pkCol.IsPrimaryKey = true;
        table.Columns.Add(new DbSyncColumnDescription("Name", "nvarchar 50"));
        table.Columns.Add(new DbSyncColumnDescription("Height", "int"));
        table.Columns.Add(new DbSyncColumnDescription("Weight", "int"));
        ceConfig.ObjectPrefix = "Sync";

In the above code, syncProvider is a SqlCESyncProvider object with a connection string attached to the specified database.

Here is the code I use to set up synchronization between the databases using SyncOrchestrator:

    _syncOrchestrator.LocalProvider = localSyncProvider;
    _syncOrchestrator.RemoteProvider = remoteSyncProvider;
    _syncOrchestrator.Direction = SyncDirectionOrder.DownloadAndUpload;

    try {
        var sync = _syncOrchestrator.Synchronize();
        Console.WriteLine(string.Format("Sync Downloads: {0}\nSync Uploads: {1}\nSync Start Time: {2}\nSync End Time: {3}",
            sync.DownloadChangesTotal.ToString(), sync.UploadChangesTotal.ToString(),
            sync.SyncStartTime, sync.SyncEndTime));
    } catch (Exception ex) {
        Console.WriteLine(string.Format("Sync Orchestrator threw exception: {0}", ex.Message));

Thanks in advance for any help!


I was able to solve the error by changing the provisioning. Instead of calling the above code for each of the two databases, I created a single function as shown below:

    public void SetupScope() {
        if (ProvidersCollection["Local"] != null && ProvidersCollection["Remote"] != null) {
            var localConnection = (SqlCeConnection)((SqlCeSyncProvider)ProvidersCollection["Local"]).Connection;
            var remoteConnection = (SqlCeConnection)((SqlCeSyncProvider)ProvidersCollection["Remote"]).Connection;

            var localScopeDescription = new DbSyncScopeDescription("LocalPerson");
            var localPersonTableDescription = SqlCeSyncDescriptionBuilder.GetDescriptionForTable("Person", remoteConnection);

            var localDatabaseConfiguration = new SqlCeSyncScopeProvisioning(localConnection);
            try {
                localDatabaseConfiguration.ObjectPrefix = "Sync";
            } catch (Exception ex) {
                Console.WriteLine(string.Format("{0}", ex.Message));

            var remoteScopeDescription = new DbSyncScopeDescription("RemotePerson");
            var remotePersonTableDescription = SqlCeSyncDescriptionBuilder.GetDescriptionForTable("Person", localConnection);

            var remoteDatabaseConfiguration = new SqlCeSyncScopeProvisioning(remoteConnection);
            try {
                remoteDatabaseConfiguration.ObjectPrefix = "Sync";
            } catch (Exception ex) {
                Console.WriteLine(string.Format("{0}", ex.Message));

The difference here is that for each of the two databases, I now reference the connection of the other database when setting up my table descriptions.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.