我正在尝试使用 microsoft 同步框架将远程 SQL 数据库与本地 SQL 数据库同步
当它为 2 个不同的数据库运行本地 SQL 时,它就像魅力一样,当我为远程数据库尝试相同的代码 - 本地数据库同步时,它以错误结束
当前操作无法完成,因为没有为同步配置数据库,或者您没有同步配置表的权限。
如何克服上述异常
这是我的代码
var serverProvision = new SqlSyncScopeProvisioning(serverConn); if (!serverProvision.ScopeExists(tableName)) { try { var scopeDesc = new DbSyncScopeDescription(tableName); scopeDesc.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable(tableName, serverConn)); serverProvision.PopulateFromScopeDescription(scopeDesc); serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip); serverProvision.Apply(); } catch (Exception exception) { MessageBox.Show(exception.Message); } }
var clientProvision = new SqlSyncScopeProvisioning(clientConn);
if (!clientProvision.ScopeExists(tableName))
{
try
{
var scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(tableName, serverConn);
clientProvision.PopulateFromScopeDescription(scopeDesc);
clientProvision.Apply();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
var serverProvider = new SqlSyncProvider(tableName, serverConn);
var clientProvider = new SqlSyncProvider(tableName, clientConn);
var syncOrchestrator = new SyncOrchestrator{Direction = SyncDirectionOrder.DownloadAndUpload,LocalProvider = clientProvider, RemoteProvider = serverProvider};
((SqlSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed += ProgramApplyChangeFailed;
syncOrchestrator.Synchronize();
谢谢
维奈