我尝试使用Microsoft同步框架在两个SQl服务器数据库之间同步数据,但它只以一种方式同步,任何建议?
SqlSyncProvider sqlProviderLocal = new SqlSyncProvider(downloadScope, sqlConnLocal);
SqlSyncProvider sqlProviderRemote = new SqlSyncProvider(downloadScope, sqlConnRemote);
SqlSyncScopeProvisioning scopeProvisionLocal = new SqlSyncScopeProvisioning(sqlConnLocal);
SqlSyncScopeProvisioning scopeProvisionRemote = new SqlSyncScopeProvisioning(sqlConnRemote);
scopeProvisionLocal.ObjectSchema = ".dbo";
scopeProvisionRemote.ObjectSchema = ".dbo";
string[] tablesToSync = ConfigurationManager.AppSettings["SyncTablesDownloadFromRemote"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (!scopeProvisionLocal.ScopeExists(downloadScope))
{
DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(downloadScope);
for (int i = 0; i < Tables.Length; i++)
{
scopeDesc.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable(Tables[i], sqlConnLocal));
}
scopeProvisionLocal.PopulateFromScopeDescription(scopeDesc);
scopeProvisionLocal.SetCreateTableDefault(DbSyncCreationOption.Skip);
scopeProvisionLocal.Apply();
}
if (!scopeProvisionRemote.ScopeExists(downloadScope))
{
DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(downloadScope, sqlConnLocal);
scopeProvisionRemote.PopulateFromScopeDescription(scopeDesc);
scopeProvisionRemote.Apply();
}
agent.LocalProvider = sqlProviderLocal;
agent.RemoteProvider = sqlProviderRemote;
agent.Direction = SyncDirectionOrder.DownloadAndUpload;
SyncOperationStatistics Uploadstats = agent.Synchronize();