AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 79603
Accepted
Nathan
Nathan
Asked: 2009-10-30 09:01:00 +0800 CST2009-10-30 09:01:00 +0800 CST 2009-10-30 09:01:00 +0800 CST

Sql Server 2005 复制:如何使用 sql 脚本设置订阅?

  • 772

通过复制设置向导时,我可以在最后选择生成脚本。该脚本适用于发布设置,但是,当我为订阅设置运行生成的脚本时,我遇到了问题并且复制不起作用。但是,如果我不生成脚本,而只是让向导自己启动复制,那么一切正常。我真的很想用脚本自动化订阅设置。

生成的订阅脚本为:

-----------------BEGIN: Script to be run at Publisher 'SERVER\INSTANCE'-----------------
use [PublisherDatabase]
exec sp_addsubscription @publication = N'PublicationName', @subscriber = N'server\instance', @destination_db = N'SubscriberDatabase', @subscription_type = N'Push', @sync_type = N'automatic', @article = N'all', @update_mode = N'read only', @subscriber_type = 0
exec sp_addpushsubscription_agent @publication = N'PublicationName', @subscriber = N'server\instance', @subscriber_db = N'SubscriberDatabase', @job_login = null, @job_password = null, @subscriber_security_mode = 1, @frequency_type = 64, @frequency_interval = 0, @frequency_relative_interval = 0, @frequency_recurrence_factor = 0, @frequency_subday = 0, @frequency_subday_interval = 0, @active_start_time_of_day = 0, @active_end_time_of_day = 235959, @active_start_date = 20091028, @active_end_date = 99991231, @enabled_for_syncmgr = N'False', @dts_package_location = N'Distributor'
GO
-----------------END: Script to be run at Publisher 'FLANDERS\TESTING'-----------------

当我运行上面的脚本时,它完成而没有错误。但是,订阅永远不会出现在 Sql Server Management Studio Replication->Local Subscriptions 树中,并且永远不会复制数据。

然而奇怪的是,运行查询:

use distribution
select * from MSSubscriptions

给出结果集:

publisher_database_id publisher_id publisher_db                                                                                                                     publication_id article_id  subscriber_id subscriber_db                                                                                                                    subscription_type sync_type status subscription_seqno                 snapshot_seqno_flag independent_agent subscription_time       loopback_detection agent_id    update_mode publisher_seqno                    ss_cplt_seqno
--------------------- ------------ -------------------------------------------------------------------------------------------------------------------------------- -------------- ----------- ------------- -------------------------------------------------------------------------------------------------------------------------------- ----------------- --------- ------ ---------------------------------- ------------------- ----------------- ----------------------- ------------------ ----------- ----------- ---------------------------------- ----------------------------------
3                     0            PublisherDatabase                                                                                                                3              1           -1            virtual                                                                                                                          0                 1         1      0x00000027000001230003             0                   1                 2009-10-29 10:41:37.540 1                  10          0           0x00000027000001230003             0x00000027000001230003
3                     0            PublisherDatabase                                                                                                                3              1           -2            virtual                                                                                                                          0                 1         2      0x00000027000001230003             0                   1                 2009-10-29 10:41:37.603 1                  11          0           0x00000027000001230009             0x00000027000001230009
3                     0            PublisherDatabase                                                                                                                3              1           0             SubscriberDatabase                                                                                                               0                 1         1      0x000000270000013B0008             0                   1                 2009-10-29 10:54:58.140 1                  12          0           0x000000270000013B0008             0x000000270000013B0008

这似乎表明订阅存在。

万一这很重要,这是一个仅推送的发布/订阅,并且发布者和订阅者数据库都在同一台服务器上。

我还需要做什么才能让订阅从 sql 脚本工作?

编辑:交叉发布到http://www.sqlservercentral.com/Forums/Topic811043-291-1.aspx

sql-server
  • 1 1 个回答
  • 1595 Views

1 个回答

  • Voted
  1. Best Answer
    Nathan
    2009-11-05T12:08:24+08:002009-11-05T12:08:24+08:00

    弄清楚了。直接从 Management Studio 生成订阅时,它会自动启动快照代理。但是,Management Studio 为订阅生成的脚本不会启动快照代理。将以下行添加到生成的脚本中可以使事情正常进行:

    EXEC sp_startpublication_snapshot @publication = N'InstitutionPublication'
    

    所以我修改后的订阅者完整脚本是:

    -----------------BEGIN: Script to be run at Publisher 'SERVER\INSTANCE'-----------------
    -----------------BEGIN: Script to be run at Publisher 'SERVER\INSTANCE'-----------------
    use [Profile]
    exec sp_addsubscription @publication = N'PublicationName', @subscriber = N'server\instance', @destination_db = N'destinationDatabaseName', @subscription_type = N'Push', @sync_type = N'automatic', @article = N'all', @update_mode = N'read only', @subscriber_type = 0
    exec sp_addpushsubscription_agent @publication = N'PublicationName', @subscriber = N'server\instance', @subscriber_db = N'destinationDatabaseName', @job_login = null, @job_password = null, @subscriber_security_mode = 1, @frequency_type = 64, @frequency_interval = 0, @frequency_relative_interval = 0, @frequency_recurrence_factor = 0, @frequency_subday = 0, @frequency_subday_interval = 0, @active_start_time_of_day = 0, @active_end_time_of_day = 235959, @active_start_date = 20091104, @active_end_date = 99991231, @enabled_for_syncmgr = N'False', @dts_package_location = N'Distributor'
    GO
    -----------------END: Script to be run at Publisher 'SERVER\INSTANCE'-----------------
    
    EXEC sp_startpublication_snapshot @publication = N'PublicationName';
    GO
    
    • 0

相关问题

  • sql server 连接字符串上的网络数据包大小以提高吞吐量

  • 基于 Microsoft 的服务器(IIS、MSSQL 等)上的病毒扫描应排除哪些内容?

  • SQL 洗衣清单

  • OPENROWSET、二进制文件、varchars 和 varbinaries

  • 聚集索引与非聚集索引?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    Windows 中执行反向 DNS 查找的命令行实用程序是什么?

    • 14 个回答
  • Marko Smith

    如何检查 Windows 机器上的端口是否被阻塞?

    • 4 个回答
  • Marko Smith

    我应该打开哪个端口以允许远程桌面?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    kch 如何更改我的私钥密码? 2009-08-06 21:37:57 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve