代码之家  ›  专栏  ›  技术社区  ›  DomBat

通过web同步将SQL Server 2008复制到SQL Express 2005

  •  0
  • DomBat  · 技术社区  · 15 年前

    我有一个SQL 2008 R2服务器。 我用这个向导创建了一个出版物,看起来不错。 “系统数据库”部分有一个“分发”数据库,其中没有太多内容。(不确定它是否已经存在,或者“发布向导”是否创建了它。) 我已经设置了web同步,并且可以通过IIS7和自签名证书访问relisapi.dll。

    我的ASP.NET网站安装程序安装SQL Express 2005。 我写了一个小网站来测试订阅和初始同步的创建。 我不“创建初始”数据库,因为我认为第一次同步将从服务器上删除所有内容。

    以下代码似乎可以工作,因为订阅是在SQL 2008服务器的SQL Express中创建的。

    ' Define the pull subscription.
                subscription = New MergePullSubscription()
                subscription.ConnectionContext = subscriberConn
                subscription.PublisherName = publisherName
                subscription.PublicationName = publicationName
                subscription.PublicationDBName = publicationDbName
                subscription.DatabaseName = subscriptionDbName
                subscription.HostName = hostname
                subscription.CreateSyncAgentByDefault = True
    
                ' Specify the Windows login credentials for the Merge Agent job.
                subscription.SynchronizationAgentProcessSecurity.Login = winLogin
                subscription.SynchronizationAgentProcessSecurity.Password = winPassword
    
                ' Enable Web synchronization.
                subscription.UseWebSynchronization = True
                subscription.InternetUrl = webSyncUrl
    
                ' Specify the same Windows credentials to use when connecting to the
                ' Web server using HTTPS Basic Authentication.
                subscription.InternetSecurityMode = AuthenticationMethod.BasicAuthentication
                subscription.InternetLogin = winLogin
                subscription.InternetPassword = winPassword
    
                If Not subscription.LoadProperties() Then
                    ' Create the pull subscription at the Subscriber.
                    subscription.Create()
    

    然后我运行以下代码:

            If Not subscription.PublisherSecurity Is Nothing Or _
                   subscription.DistributorSecurity Is Nothing Then
    
                    '0: Only error messages are logged.
                    '1: All progress report messages are logged.
                    '2: All progress report messages and error messages are logged.
                    subscription.SynchronizationAgent.OutputVerboseLevel = 2
                    subscription.SynchronizationAgent.Output = "c:\createmerge.txt"
    
                    ' Synchronously start the Merge Agent for the subscription.
                    subscription.SynchronizationAgent.Synchronize()
    

    但是syncronize抛出了一个错误:

    无法验证对发布“我的发布”的订阅。确保正确指定了所有合并代理命令行参数,并且正确配置了订阅。如果发布服务器不再具有有关此订阅的信息,请删除并重新创建订阅。

    在服务器上,使用“复制监视器”,它显示我的订阅是“统一的”。

    我认为一个问题是subscription.HostName错误。MSDN上的微软示例

    "adventure-works\garrett1"
    

    但目前还不清楚adventure是服务器、实例还是数据库,以及谁是garrett1(登录名或其他什么)。那么这到底应该是什么呢?

    因为我对复制一无所知,而且我只是在关注MSDN和一些书籍,所以我想知道下一步该怎么做。

    对不起,这么久了!

    3 回复  |  直到 15 年前
        1
  •  1
  •   Ed Harper    15 年前

    基于 the documentation ,的设置 Subscription.Hostname 对使发布正常工作并不重要-它是订阅服务器提供的值 HOST_NAME 当合并发布被分区时。见 here 有关筛选的发布的详细信息。

    如果你有信心 correctly configured your environment 要支持web同步,必须一次调试这一部分。

    可能需要首先在发布服务器上为另一个数据库设置非基于web的订阅,以证明该发布按预期工作。假设可行,请尝试在SQL 2005 Express实例上设置非web订阅,然后继续测试web同步。

        2
  •  0
  •   DomBat    15 年前

    好吧,我遇到麻烦有两个原因。

    首先在我的开发PC上,机器在某个时候被重命名了,所以到本地订阅服务器SQL的连接是错误的。

    其次,IIS7上的“自签名证书”解析为一个内部名称,而不是外部世界通过HTTPS可以看到的真实名称。我们得到了一个正确域名的测试证书,运行良好!

        3
  •  0
  •   DomBat    15 年前

    好的,如果你感兴趣的话,这里有一些关于主机名()的更多信息。

    http://msdn.microsoft.com/en-us/library/ms152478%28v=SQL.110%29.aspx

    基本上,您可以使用它向发布服务器传递一个您选择的值(这会重载服务器上的主机名函数)。这允许您筛选行,例如Employee.ID=CONVERT(HOST_NAME()as int),以仅获取子选项中所需的行。