Reputation: 1552
I am trying to synchronise 3 SQL Server 2008 tables to a SQL Server CE 3.5 database. The following code produces the error at the bottom. Any ideas whats going on? The tracking tables exist as well as the stored procedures.
Thanks
Code:
SyncLibrary.DatabaseSyncInfo inf = new SyncLibrary.DatabaseSyncInfo();
SynchronizationHelper hel = new SynchronizationHelper(inf);
inf.LocalConnectionString = @"Data Source=admin.domain.com,1435;Initial Catalog=ProjectAdmin;User ID=sa;Password=password";
inf.LocalDriverType = SyncLibrary.eSyncDriverType.SQLServer;
inf.RemoteConnectionString = @"Data Source=C:\Projects\Admin\TCPClient\ProjectAdmin.sdf";
inf.RemoteDriverType = SyncLibrary.eSyncDriverType.SQLCompact;
inf.ScopeName = "ProjectSCOPE";
System.Collections.Generic.List<string> tables = new System.Collections.Generic.List<string>();
tables.Add("Users");
tables.Add("SB_Questions");
tables.Add("Kiosks");
inf.SyncTables = tables;
SyncOperationStatistics ss = hel.DoSync();
Console.WriteLine("Start time: " + ss.SyncStartTime);
Console.WriteLine("Total changes uploaded: " + ss.UploadChangesTotal);
Console.WriteLine("Total changes downloaded: " + ss.DownloadChangesTotal);
Console.WriteLine("Complete time: " + ss.SyncEndTime);
public SyncOperationStatistics DoSync()
{
SqlSyncProvider localProvider = ConfigureSqlServerSyncProvider(new SqlConnection(this.dbInfo.LocalConnectionString));
RelationalSyncProvider remoteProvider = null;
if (dbInfo.RemoteDriverType == eSyncDriverType.SQLServer)
{
remoteProvider = ConfigureSqlServerSyncProvider(new SqlConnection(this.dbInfo.RemoteConnectionString));
}
else if (dbInfo.RemoteDriverType == eSyncDriverType.SQLCompact)
{
remoteProvider = ConfigureSqlServerCeSyncProvider(new SqlCeConnection(this.dbInfo.RemoteConnectionString));
}
//Set memory data cache size property. 0 represents non batched mode
localProvider.MemoryDataCacheSize = dbInfo.LocalBatchSize;
remoteProvider.MemoryDataCacheSize = dbInfo.RemoteBatchSize;
//Set batch spool location. Default value if not set is %Temp% directory.
if (string.IsNullOrEmpty(dbInfo.LocalBatchSpoolFolder) == false)
{
localProvider.BatchingDirectory = dbInfo.LocalBatchSpoolFolder;
}
if (string.IsNullOrEmpty(dbInfo.RemoteBatchSpoolFolder) == false)
{
remoteProvider.BatchingDirectory = dbInfo.RemoteBatchSpoolFolder;
}
SyncOperationStatistics stats = this.SynchronizeProviders(localProvider, remoteProvider);
//TimeSpan diff = stats.SyncEndTime.Subtract(stats.SyncStartTime);
//Print Sync stats object
//this.syncStats.Text = string.Format("Batching: {4} - Total Time To Synchronize = {0}:{1}:{2}:{3}",
// diff.Hours, diff.Minutes, diff.Seconds, diff.Milliseconds, (this._batchSize > 0) ? "Enabled" : "Disabled");
//this.ReadTableValuesForSelectedTab();
return stats;
}
Error:
Cannot apply changes because the local provider does not have adapters configured for the following tables that were received from the remote provider: Kiosks. Ensure that the correct adapters have been added to both providers for Scope 'ProjectSCOPE', and that any table mapping has been correctly configured.
Upvotes: 1
Views: 1009
Reputation: 437
In my case client provisioning was different from Server provisioning. I have de-provision database and applied provisioning. After that this error is removed.
try
{
SqlSyncScopeDeprovisioning obj1 = new SqlSyncScopeDeprovisioning(clientConn) { CommandTimeout = 60 * 30 };
obj1.DeprovisionScope(scopeName);
}
catch { }
// get the description of ProductsScope from the SyncDB server database
DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(scopeName, serverConnection);
SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(clientConn, scopeDesc);
if (!clientProvision.ScopeExists(scopeName))
{
//apply the scope definition
clientProvision.Apply();
}
Upvotes: 1
Reputation: 1144
It looks like there is a mismatch in table name on your remote database and local database.
Try using GlobalName property on TableDescription. For example if there is two tables with name Countries_Version and Countries but they do exposes same data and the only difference is name you can do something like below to get is mapped via GlobalName property.
DbSyncTableDescription CountriesTableDescription;
if (provider.Connection.Database.ToLower() == "peer1")
CountriesTableDescription = SqlSyncDescriptionBuilder.GetDescriptionForTable( "Countries_Version", (System.Data.SqlClient.SqlConnection)provider.Connection );
else
CountriesTableDescription = SqlSyncDescriptionBuilder.GetDescriptionForTable( "Countries", (System.Data.SqlClient.SqlConnection)provider.Connection );
// map to the Countries_Version table on peer2
CountriesTableDescription.GlobalName = "Countries";
Upvotes: 0