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

发布于 2024-10-04 04:58:03 字数 2832 浏览 2 评论 0原文

我有一个 SQL 2008 R2 服务器。 我已经使用向导创建了一个出版物,看起来一切顺利。 “系统数据库”部分中有一个“分发”数据库,内容不多。 (不确定它是否已经存在或者是否是“发布向导”创建的。) 我已经设置了 Web 同步,并可以通过 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 和一些书籍,因此我希望得到一些关于下一步该去哪里的指示。

抱歉这么长!

I have a SQL 2008 R2 server.
I've created a publication using the wizard which seemed to go ok.
There is a 'distribution' database in the 'system databases' section that has not a lot in it. (Not sure if this was there already or whether the "Publication Wizard" created it.)
I have setup web sync and have access to relisapi.dll via IIS7 and a self signed certificate.

My setup program for my ASP.NET website installs SQL Express 2005.
I have written a little site to test the creation of a subscription and initial sync.
I do not "create an initial" database as I'm presuming the first sync will pull everything down from the server.

The following bit of code seems to work because a subscription is created in SQL Express & in the SQL 2008 server.

' 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()

Then I run this bit of code:

        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()

but the syncronize throws the error:

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.

On the server, using "Replication Monitor" it is showing my subscription as "Unitialized".

I think one problem is that my subscription.HostName is wrong. The Microsoft examples on MSDN say

"adventure-works\garrett1"

but it isn't clear whether adventure-works is the server, instance or database and who is garrett1 (a login or something else). So what should this actually be?

Since I don't know anything about replication and I've just been following MSDN and some books, I'd apreciate some pointers as to where to go next.

Sorry this is so long!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沫离伤花 2024-10-11 04:58:03

根据文档,该设置Subscription.Hostname 的值对于发布工作而言并不重要 - 它是合并发布分区时订阅者为 HOST_NAME 提供的值。有关过滤的出版物的详细信息,请参阅此处

如果您确信自己已正确配置您的环境以支持 Web同步,你将不得不一次调试这一块。

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

Based on the documentation, the setting of Subscription.Hostname isn't critical to getting the publication working - it's the value the subscriber supplies for HOST_NAME when the merge pubication is partitioned. See here for more information about filtered publications.

If you're confident that you have correctly configured your environment to support web sync, you're going to have to debug this one piece at a time.

It might be worth starting by setting up a non-web based subscription for another database on the publisher to prove that the publication is working as expected. Assuming that works, try setting up a non-web subscription on a SQL 2005 Express instance, and then move on to testing web sync.

三生路 2024-10-11 04:58:03

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

首先,在我的开发 PC 上,机器在某个时刻已被重命名,因此与本地订阅者 SQL 的连接是错误的。

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

Ok, there were two reasons I was having trouble.

Firstly on my development PC, the machine had been renamed at some point, so the connection to my local subscriber SQL was wrong.

Secondly, the "self-signed certificate" on IIS7 was resolving to an internal name and not the real name that could be seen via HTTPS from the outside world. We got a test certificate for the correct domain and it worked fine!

风为裳 2024-10-11 04:58:03

好的,如果您有兴趣,这里有一些有关 HOST_NAME() 的更多信息。

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

基本上,您使用它来将变量传递给发布者,其中包含您选择的值(这会重载服务器上的 HOST_NAME 函数)。这允许您过滤行,例如 Employee.ID = CONVERT(HOST_NAME() as int) 以仅获取订阅时所需的行。

Ok, heres some more info about HOST_NAME() if you're interested.

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

Basically you use it to pass a variable to the publisher with a value of your choice (which overloads HOST_NAME function at the server). This allows you to filter rows, such as Employee.ID = CONVERT(HOST_NAME() as int) to only get the rows you require at the subscrption.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文