Using Microsoft's Sync Framework Tool, I've provisioned two Microsoft SQL Server Databases (first code snippet). Next, in an attempt to sync the data in them, I ran some code from MSDN's tutorials that I've tailored to fit my databases, which are both very simple and not complex at all (second code snippet).
My problem is that when I run the sync code, I get an error:
Cannot apply changes because the local provider does not have adapters configured for the following tables that were received from the remote provider: Spray_History. Ensure that the correct adapters have been added to both providers for Scope 'SprayHistory_SCOPE', and that any table mapping has been correctly configured.
I'll also include some snippets of the database tables just to show that the server provisioning appears to have gone successfully.
Server Provisioning
//Create a connection to the DustSuppression database (the Catalog name here changes for each database)
SqlConnection sqlConnection = new SqlConnection("Data Source = TKTEST-2; Initial Catalog = Dust_Suppression; Integrated Security = SSPI");
//Create a sync scope for SprayHistory table in database (we can name it whatever we want when we create it)
DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("SprayHistory_SCOPE");
//Specify name of sync scope and list of tables to be synced (this needs to be the actual table name & server connection)
DbSyncTableDescription tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Spray_History", sqlConnection);
//Add the table description to the scope description
scopeDesc.Tables.Add(tableDesc);
//Provision the database with sync related artifacts (create provision object using scope description & server connection)
SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(sqlConnection, scopeDesc);
//Since the SprayHistory table already exists, inform the sync tool to skip creating it
serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);
//Start the provisioning
serverProvision.Apply();
Sync Data Between Servers
static void Main(string[] args)
{
//Connection string to the client (assume this to be S2)(this would normally be an ExpressDB)
SqlConnection clientConnection = new SqlConnection("Data Source=TKTEST-2;Initial Catalog=Dust_Suppression;Integrated Security=SSPI");
//Connection string to the database (assume this to be S1)(this would be the normal SQL DB)
SqlConnection serverConnection = new SqlConnection("Data Source=TKTEST-2;Initial Catalog=DustSuppression;Integrated Security=SSPI");
//Create a sync orchestrator
SyncOrchestrator syncOrchestrator = new SyncOrchestrator();
//Set local provider of orchestrator to a sync provider (S2)(this would normally be an ExpressDB)
syncOrchestrator.LocalProvider = new SqlSyncProvider("SprayHistory_SCOPE", clientConnection);
//Set remote provider of orchestrator to a server sync provider (S1)(this would be the normal SQL DB)
syncOrchestrator.RemoteProvider = new SqlSyncProvider("SprayHistory_SCOPE", serverConnection);
//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);
}
static void Program_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e)
{
// display conflict type
Console.WriteLine(e.Conflict.Type);
// display error message
Console.WriteLine(e.Error);
}
SSMS Snippets
