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(pkCol);
table.Columns.Add(new DbSyncColumnDescription("Name", "nvarchar 50"));
table.Columns.Add(new DbSyncColumnDescription("Height", "int"));
table.Columns.Add(new DbSyncColumnDescription("Weight", "int"));
description.Tables.Add(table);
ceConfig.PopulateFromScopeDescription(description);
ceConfig.SetCreateTableDefault(DbSyncCreationOption.Skip);
ceConfig.ObjectPrefix = "Sync";
ceConfig.Apply(ceConn);
}
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!