同步框架 DbProvisioningException
我正在尝试学习同步框架。 我按照MSDN文档一步步操作,但没有成功。惊讶吗?! 我需要的是将 SQL Express 数据库与 SQL Express 数据库同步。 在阅读有关配置和我需要做的其他准备的内容时,我永远无法找到是否每次我想使用同步时都必须运行它。我的意思是,规定->同步->取消配置。 另一件事是,我在逐步制作 MSDN 示例时遇到了这个奇怪的异常。
DbProvisioningException“MomScope”已经存在...不应该存在吗?
代码:
private void InitializeSync()
{
SqlConnection sourceConn = new SqlConnection(ConfigManager.Config.SourceSyncConnectionString);
SqlConnection myConn = new SqlConnection(ConfigManager.Config.ConnectionString);
#region SET SOURCE PROVIDER
SqlSyncProvider sourceSqlProv = new SqlSyncProvider("MomSync", sourceConn);
DbSyncScopeDescription sourceScope = new DbSyncScopeDescription("MomScope");
DbSyncTableDescription productsSourceTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Mom_Products", sourceConn);
DbSyncTableDescription customersSourceTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Mom_Customer", sourceConn);
DbSyncTableDescription ordersSourceTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Mom_Orders", sourceConn);
DbSyncTableDescription paymentsSourceTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Mom_Payments", sourceConn);
sourceScope.Tables.Add(productsSourceTableDesc);
sourceScope.Tables.Add(customersSourceTableDesc);
sourceScope.Tables.Add(ordersSourceTableDesc);
sourceScope.Tables.Add(paymentsSourceTableDesc);
SqlSyncScopeProvisioning sourceProvision = new SqlSyncScopeProvisioning(sourceConn, sourceScope);
sourceProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);
try
{
sourceProvision.Apply();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
#endregion
#region SET MY PROVIDER
SqlSyncProvider myProvider = new SqlSyncProvider("MomSync", myConn);
DbSyncScopeDescription scopeSourceDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope("MomScope", sourceConn); <===== DbProvisioningException (MomScope already exists????)
SqlSyncScopeProvisioning myProvision = new SqlSyncScopeProvisioning(myConn, scopeSourceDesc);
try
{
myProvision.Apply();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
#endregion
#region SET SYNC ORCHESTRATOR
OrcheStrator = new SyncOrchestrator
{
LocalProvider = myProvider,
RemoteProvider = sourceSqlProv,
Direction = SyncDirectionOrder.UploadAndDownload
};
((SqlSyncProvider)OrcheStrator.LocalProvider).ApplyChangeFailed += ApplyChangeFailedHandler;
#endregion
}
有合适的同步示例吗?那么我可以正确地弄清楚如何创建这个任务吗?
谢谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果有人仍然感兴趣...
只需在 apply() 之前对 sourceProvision.Exists() 进行检查
http://msdn.microsoft.com/en-us/library/dd919024.aspx
Should anyone still be interested...
Just implement a check on sourceProvision.Exists() right before you apply()
http://msdn.microsoft.com/en-us/library/dd919024.aspx
您无需每次在同步前进行配置。可以一次性提供,然后您可以从那里开始同步。当然,如果取消配置发生在某个时间..sycn 之后就无法完成。
就您而言,正如消息所暗示的那样,似乎已经存在同名的内容。通过运行以下语句进行检查
如果它返回具有您尝试添加的范围名称的行,您可以执行以下操作。
(或)
You need not provision everytime before sync. Provision can be one time and then you can sync from there on. Ofcourse if de-provision happens at time ..sycn canot be done after that.
In your case, as the message suggests, there seems to be existing already with that same name. Check by running following statement
If it returns rows with scope name which you are trying to add, you can do following things.
(OR)