I have a local SQL CE database and I am trying to sync to a remote SQL Server database using the Microsoft Sync Framework. I have provisioned both the CE and the Server databases, but when I try to Sync, using SyncOrchestrator, I get an error The stored procedure '[tablename_selectchanges]' doesn't exist..
When provisioning the local and remote databases, I first enable tracking on the appropriate tables, then do the following:
CE:
var localScopeDescription = new DbSyncScopeDescription(scopeName);
foreach (var table in tables) {
localScopeDescription.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable(table, remoteConnection));
}
var localDatabaseConfiguration = new SqlCeSyncScopeProvisioning(localConnection, localScopeDescription);
if (!localDatabaseConfiguration.ScopeExists(scopeName)) {
localDatabaseConfiguration.ObjectPrefix = "Sync";
localDatabaseConfiguration.SetCreateTableDefault(DbSyncCreationOption.Skip);
localDatabaseConfiguration.Apply();
}
Server:
var remoteScopeDescription = new DbSyncScopeDescription(scopeName);
foreach (var table in tables) {
remoteScopeDescription.Tables.Add(SqlCeSyncDescriptionBuilder.GetDescriptionForTable(table, localConnection));
}
var remoteDatabaseConfiguration = new SqlSyncScopeProvisioning(remoteConnection, remoteScopeDescription);
if (!remoteDatabaseConfiguration.ScopeExists(scopeName)) {
remoteDatabaseConfiguration.ObjectPrefix = "Sync";
remoteDatabaseConfiguration.SetCreateTableDefault(DbSyncCreationOption.Skip);
remoteDatabaseConfiguration.SetCreateTrackingTableDefault(DbSyncCreationOption.Create);
remoteDatabaseConfiguration.SetCreateTriggersDefault(DbSyncCreationOption.Create);
remoteDatabaseConfiguration.SetCreateProceduresDefault(DbSyncCreationOption.Skip);
remoteDatabaseConfiguration.SetPopulateTrackingTableDefault(DbSyncCreationOption.Create);
remoteDatabaseConfiguration.SetUseBulkProceduresDefault(true);
remoteDatabaseConfiguration.Apply();
}
If I remove the SetCreateProceduresDefault(DbSyncCreationOption.Skip) line, which seems to prevent the creation of this procedure, I get the following error:
Invalid column name ‘__sysChangeTxBsn’.
Invalid column name ‘__sysInsertTxBsn’.
Invalid column name ‘__sysTrackingContext’.
Am I setting up my provisioning wrong, and if so, how can I fix this? Or could these errors be caused by something else?
The question was answered here by JuneT, hopefully this helps someone else who encounters this problem.
My problem was caused by tracking my changes before I added table descriptions to the server, causing the invalid column names.