2010-11-26 140 views
0

我有一个SQL 2008 R2服务器。 我已经创建了一个使用向导的出版物,似乎没问题。 “系统数据库”部分有一个“分布”数据库,其中没有太多内容。 (不知道这是否已经存在,或者“发布向导”是否已经创建了它。) 我已经安装了网络同步并且可以通过IIS7和自签名证书访问relisapi.dll。SQL Server 2008通过网络同步复制到SQL Express 2005

我的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引发错误:

The subscription to publication 'My publication' could not be verified. Ensure that all Merge Agent command line parameters are specified correctly and that the subscription is correctly configured. If the Publisher no longer has information about this subscription, drop and recreate the subscription.

在服务器上,使用 “复制监视器” 它显示我的订阅作为“单元化”。

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

"adventure-works\garrett1" 

但冒险的作品是否是服务器,实例或数据库,谁是garrett1(登录或别的东西),目前尚不清楚。那实际上应该是什么呢?

因为我对复制一无所知,而且我一直在关注MSDN和一些书籍,所以我会认真考虑下一步该怎么做。

对不起,这么久了!

回答

0

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

首先在我的开发PC上,机器已经在某个时间点重新命名,所以连接到我的本地用户SQL是错误的。

其次,IIS7上的“自签名证书”是解析为内部名称,而不是从外部世界通过HTTPS可以看到的真实名称。我们获得了正确域名的测试证书,并且工作正常!

1

根据the documentationSubscription.Hostname的设置对于让出版物正常工作并不重要 - 它是合并发布进行分区时用户为HOST_NAME提供的价值。有关过滤出版物的更多信息,请参阅here

如果你确信你有correctly configured your environment支持网络同步,你将不得不一次调试这一块。

通过为发布商的另一个数据库设置基于非基于Web的订阅以证明该出版物按预期工作,可能值得开始。假设可行,请尝试在SQL 2005 Express实例上设置非Web订阅,然后继续测试Web同步。

0

好吧,继承人一些关于HOST_NAME()的更多信息,如果你有兴趣。

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

基本上你用它来一个变量传递给出版商与您选择的值(在服务器过载HOST_NAME功能)。这允许您过滤行,例如Employee.ID = CONVERT(HOST_NAME()int),以仅获取subscrption所需的行。

相关问题