我正在尝试在mvc4网站中同步一个sql的两个数据库?
我有这个代码同步它显示没有错误但它没有执行
using Microsoft.Synchronization;
using Microsoft.Synchronization.Data;
using Microsoft.Synchronization.Data.SqlServer;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Planetskool.Controllers
{
public class DataSyncViewController : Controller
{
//
// GET: /DataSyncView/
public ActionResult Index()
{
string sqlazureConnectionString = "Server=(LocalDb)\v11.0;Initial Catalog=aspnet-Planetskool-20130901224447;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-20130901224447.mdf";
string sqllocalConnectionString = "Server=(LocalDb)\v11.0;Initial Catalog=aspnet-Planetskool-20130901224446;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-20130901224446.mdf";
using (SqlConnection serverCon = new SqlConnection(sqlazureConnectionString))
using (SqlConnection clientCon = new SqlConnection(sqllocalConnectionString))
{
var provider1 = new SqlSyncProvider("scope1", serverCon);
var provider2 = new SqlSyncProvider("scope1", clientCon);
prepareServer(provider1);
prepareClinet(provider2, serverCon);
SyncOrchestrator sync = new SyncOrchestrator();
sync.LocalProvider = provider1;
sync.RemoteProvider = provider2;
sync.Synchronize();
return View();
}}
private static void prepareServer(SqlSyncProvider provider)
{
SqlConnection connection = (SqlConnection)provider.Connection;
SqlSyncScopeProvisioning config = new SqlSyncScopeProvisioning(connection);
if (!config.ScopeExists(provider.ScopeName))
{
DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(provider.ScopeName);
scopeDesc.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("Author_Master", connection));
config.PopulateFromScopeDescription(scopeDesc);
config.SetCreateTableDefault(DbSyncCreationOption.CreateOrUseExisting);
config.Apply();
}
}
private static void prepareClinet(SqlSyncProvider provider, SqlConnection sourceConnection)
{
SqlConnection connection = (SqlConnection)provider.Connection;
SqlSyncScopeProvisioning config = new SqlSyncScopeProvisioning(connection);
if (!config.ScopeExists(provider.ScopeName))
{
DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(provider.ScopeName);
scopeDesc.Tables.Add(SqlSyncDescriptionBuilder.GetDescriptionForTable("Author_Master", sourceConnection));
config.PopulateFromScopeDescription(scopeDesc);
config.Apply();
}
}
}
}
答案 0 :(得分:0)
您可以在详细模式下启用同步框架跟踪以跟踪同步。同样,您是否忘记设置同步方向?