Sql Mvc4中针对两个不同用户的数据同步

Sql Mvc4中针对两个不同用户的数据同步,sql,asp.net-mvc-4,azure,sync,microsoft-sync-framework,Sql,Asp.net Mvc 4,Azure,Sync,Microsoft Sync Framework,我正在尝试同步mvc4网站中sql的两个数据库 我有这个代码来同步它显示没有错误,但它没有得到执行 using Microsoft.Synchronization; using Microsoft.Synchronization.Data; using Microsoft.Synchronization.Data.SqlServer; using System; using System.Collections.Generic; using System.Data.SqlClient; usin

我正在尝试同步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();
        }
    }

        }

    }

您可以在详细模式下启用同步框架跟踪来跟踪同步。同样,您忘记设置同步方向了吗?

您的初始目录相同,但数据文件不同,这是您的意图吗?@jlew不,这是错误的,初始目录也不同于未执行的目录