我有一个 SQL 2008 R2 服务器。我使用向导创建了一个出版物,似乎还可以。“系统数据库”部分中有一个“分发”数据库,其中没有很多。(不确定这是否已经存在或者“发布向导”是否创建了它。)我已经设置了网络同步并可以通过 IIS7 和自签名证书访问 relisapi.dll。
我的 ASP.NET 网站安装程序安装了 SQL Express 2005。我编写了一个小站点来测试订阅的创建和初始同步。我不会“创建初始”数据库,因为我假设第一次同步会将所有内容从服务器上拉下来。
以下代码似乎有效,因为订阅是在 SQL Express 和 SQL 2008 服务器中创建的。
' 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()
但是同步会引发错误:
无法验证对出版物“我的出版物”的订阅。确保正确指定所有合并代理命令行参数并且正确配置订阅。如果发布者不再拥有有关此订阅的信息,请删除并重新创建订阅。
在服务器上,使用“复制监视器”将我的订阅显示为“统一化”。
我认为一个问题是我的 subscription.HostName 是错误的。MSDN 上的 Microsoft 示例说
"adventure-works\garrett1"
但目前尚不清楚 Adventure-works 是服务器、实例还是数据库,以及 garrett1 是谁(登录名或其他)。那么这实际上应该是什么?
由于我对复制一无所知,而且我一直在关注 MSDN 和一些书籍,因此我希望得到一些关于下一步该去哪里的指示。
对不起,这么久!