sp_addpullsubscription (Transact-SQL)

更新日期: 2006 年 12 月 12 日

将请求订阅添加到快照或事务发布。此存储过程在订阅服务器上要创建请求订阅的数据库中执行。

主题链接图标Transact-SQL 语法约定

语法

sp_addpullsubscription [ @publisher= ] 'publisher'
    [ , [ @publisher_db= ] 'publisher_db' ]
        , [ @publication= ] 'publication'
    [ , [ @independent_agent= ] 'independent_agent' ]
    [ , [ @subscription_type= ] 'subscription_type' ]
    [ , [ @description= ] 'description' ]
    [ , [ @update_mode= ] 'update_mode' ]
    [ , [ @immediate_sync = ] immediate_sync ]

参数

  • [ @publisher=] 'publisher'
    发布服务器的名称。publisher 的数据类型为 sysname,无默认值。
  • [ @publisher_db=] 'publisher_db'
    发布服务器数据库名。publisher_dbsysname,默认值为 NULL。Oracle 发布服务器忽略 publisher_db
  • [ @publication=] 'publication'
    发布的名称。publication 的数据类型为 sysname,无默认值。
  • [ @independent_agent=] 'independent_agent'
    指定该发布是否有独立的分发代理。independent_agent 的数据类型为 nvarchar(5),默认值为 TRUE。如果为 true,则表示该发布有独立分发代理。如果为 false,则每个发布服务器数据库/订阅服务器数据库对都有一个分发代理。independent_agent 为发布属性,并且在此处的值必须与在发布服务器中的值相同。
  • [ @subscription_type=] 'subscription_type'
    订阅的类型。subscription_type 的数据类型为 nvarchar(9),默认值为 anonymous。您必须指定 subscription_type 的值为 pull,除非要创建订阅而不在发布服务器上注册此订阅。在此情况下,您必须指定一个 anonymous 值。如果在订阅配置期间无法建立到发布服务器的 SQL Server 连接,则必需此值。
  • [ @description=] 'description'
    发布的说明。description 的数据类型为 nvarchar(100),默认值为 NULL。
  • [ @update_mode=] 'update_mode'
    更新的类型。update_mode 的数据类型为 nvarchar(30),可以是下列值之一:

    说明

    read only(默认值)

    该订阅是只读的。在订阅服务器上所做的任何更改不会发送回发布服务器。应在订阅服务器不进行更新时使用。

    synctran

    启用对即时更新订阅的支持。

    queued tran

    启用排队更新的订阅。可以在订阅服务器上进行数据修改,将其存储在队列中,然后传播到发布服务器。

    failover

    将排队更新作为故障转移的情况下启用用于即时更新的订阅。可以在订阅服务器上进行数据修改并立即传播到发布服务器。如果发布服务器与订阅服务器未连接在一起,则可以将在订阅服务器上所做的数据修改存储在队列中,直到订阅服务器与发布服务器重新连接在一起。

    queued failover

    将订阅启用为排队更新订阅,并允许更改为立即更新模式。在订阅服务器和发布服务器之间建立连接之前,可以在订阅服务器上修改数据,并将数据修改存储在队列中。建立起持续连接后,即可将更新模式更改为立即更新。Oracle 发布服务器不支持。

  • [ @immediate_sync =] immediate_sync
    每次运行快照代理时是否创建或重新创建同步文件。immediate_sync 的数据类型为 bit,默认值为 1,且该值必须与 sp_addpublicationimmediate_sync 的值相同。immediate_sync 是发布的属性,而且它在此处的值必须与在发布服务器中的值相同。

返回代码值

0(成功)或 1(失败)

备注

sp_addpullsubscription 用于快照复制和事务复制。

ms174392.security(zh-cn,SQL.90).gif安全说明:
对于在队列中排队的更新订阅,请将 SQL Server 验证用于与订阅服务器的连接,并为每个订阅服务器连接指定一个不同的帐户。创建支持排队更新的请求订阅时,复制始终将连接设置为使用 Windows 身份验证(对于请求订阅,复制无法访问使用 SQL Server 身份验证所需的订阅服务器中的元数据)。在这种情况下,应执行 sp_changesubscription 以在配置订阅后将连接更改为使用 SQL Server 身份验证。

如果订阅服务器上没有 MSreplication_subscriptions (Transact-SQL) 表,则 sp_addpullsubscription 创建该表。它还向 MSreplication_subscriptions (Transact-SQL) 表中添加一行。对于请求订阅,应首先在发布服务器上调用 sp_addsubscription (Transact-SQL)

权限

只有 sysadmin 固定服务器角色成员或 db_owner 固定数据库角色成员才能执行 sp_addpullsubscription

示例

-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

-- Execute this batch at the Subscriber.
DECLARE @publication AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB AS sysname;
SET @publication = N'AdvWorksProductTran';
SET @publisher = $(PubServer);
SET @publicationDB = N'AdventureWorks';

-- At the subscription database, create a pull subscription 
-- to a transactional publication.
USE [AdventureWorksReplica]
EXEC sp_addpullsubscription 
  @publisher = @publisher, 
  @publication = @publication, 
  @publisher_db = @publicationDB;

-- Add an agent job to synchronize the pull subscription.
EXEC sp_addpullsubscription_agent 
  @publisher = @publisher, 
  @publisher_db = @publicationDB, 
  @publication = @publication, 
  @distributor = @publisher, 
  @job_login = $(Login), 
  @job_password = $(Password);
GO

请参阅

参考

sp_addpullsubscription_agent (Transact-SQL)
sp_change_subscription_properties (Transact-SQL)
sp_droppullsubscription (Transact-SQL)
sp_helppullsubscription (Transact-SQL)
sp_helpsubscription_properties (Transact-SQL)
系统存储过程 (Transact-SQL)

其他资源

如何创建请求订阅(复制 Transact-SQL 编程)
How to: Create an Updatable Subscription to a Transactional Publication (Replication Transact-SQL Programming)
订阅发布

帮助和信息

获取 SQL Server 2005 帮助

更改历史记录

发布日期 历史记录

2006 年 12 月 12 日

更改的内容:
  • 删除了有关不推荐使用匿名订阅的错误说明。