sp_addmergepullsubscription (Transact-SQL)

添加对合并发布的请求订阅。此存储过程在订阅服务器的订阅数据库中执行。

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

语法

sp_addmergepullsubscription [ @publication= ] 'publication' 
    [ , [ @publisher= ] 'publisher' ] 
    [ , [ @publisher_db = ] 'publisher_db' ] 
    [ , [ @subscriber_type= ] 'subscriber_type' ] 
    [ , [ @subscription_priority= ] subscription_priority ] 
    [ , [ @sync_type= ] 'sync_type' ] 
    [ , [ @description= ] 'description' ]

参数

  • [ @publication = ] 'publication'
    发布的名称。publication 的数据类型为 sysname,无默认值。

  • [ @publisher = ] 'publisher'
    发布服务器的名称。Publisher 的数据类型为 sysname,默认值为本地服务器名称。发布服务器必须为有效服务器。

  • [ @publisher_db=] 'publisher_db'
    发布服务器数据库的名称。publisher_db 的数据类型为 sysname,默认值为 NULL。

  • [ @subscriber_type=] 'subscriber_type'
    订阅服务器的类型。subscriber_type 的数据类型为 nvarchar(15),且可以是 globallocalanonymous。在 SQL Server 2005 及更高版本中,本地订阅称为客户端订阅,全局订阅称为服务器订阅。有关详细信息,请参阅合并复制如何检测和解决冲突中的“订阅类型”部分。

  • [ @subscription_priority=] subscription_priority
    订阅优先级。subscription_priority的数据类型为 real,默认值为 NULL。对于本地订阅和匿名订阅,优先级为 0.0。在检测到冲突时,默认冲突解决程序将使用该优先级来选取入选方。全局订阅服务器的订阅优先级必须低于 100,因为 100 是发布服务器的优先级。

  • [ @sync_type=] 'sync_type'
    订阅的同步类型。sync_type的数据类型为 nvarchar(15),默认值为 automatic。可以为 automaticnone。如果为 automatic,则表示已发布表的架构和初始数据将首先传输到订阅服务器。如果为 none,则假定订阅服务器已拥有已发布表的架构和初始数据。始终会传输系统表和数据。

    注意注意

    建议不要将值指定为 none。有关详细信息,请参阅初始化合并订阅(不使用快照)

  • [ @description =] 'description'
    对该请求订阅的简短说明。description的数据类型为 nvarchar(255),默认值为 NULL。此值由复制监视器显示在“友好名称”列中,该列可以用来对所监视发布的订阅进行排序。

返回代码值

0(成功)或 1(失败)

注释

sp_addmergepullsubscription 用于合并复制。

如果使用 SQL Server 代理对订阅进行同步处理,则 sp_addmergepullsubscription_agent 存储过程必须在订阅服务器上运行,才能创建与发布同步的代理和作业。

示例

-- 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;
DECLARE @hostname AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
SET @publisher = $(PubServer);
SET @publicationDB = N'AdventureWorks2008R2';
SET @hostname = N'adventure-works\david8';

-- At the subscription database, create a pull subscription 
-- to a merge publication.
USE [AdventureWorks2008R2Replica]
EXEC sp_addmergepullsubscription 
  @publisher = @publisher, 
  @publication = @publication, 
  @publisher_db = @publicationDB;

-- Add an agent job to synchronize the pull subscription. 
EXEC sp_addmergepullsubscription_agent 
  @publisher = @publisher, 
  @publisher_db = @publicationDB, 
  @publication = @publication, 
  @distributor = @publisher, 
  @job_login = $(Login), 
  @job_password = $(Password),
  @hostname = @hostname;
GO
-- 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".

-- Publication must support anonymous Subscribers.
-- Execute this batch at the Subscriber.
DECLARE @publication AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB AS sysname;
DECLARE @websyncurl AS sysname;
DECLARE @security_mode AS int;
DECLARE @login AS sysname;
DECLARE @password AS nvarchar(512);
SET @publication = N'AdvWorksSalesOrdersMergeWebSync';
SET @publisher = $(PubServer);
SET @publicationDB = N'AdventureWorks2008R2';
SET @websyncurl = 'https://' + $(WebServer) + '/WebSync';
SET @security_mode = 0; -- Basic Authentication for IIS
SET @login = $(Login);
SET @password = $(Password);

-- At the subscription database, create a pull subscription 
-- to a merge publication.
USE [AdventureWorks2008R2Replica]
EXEC sp_addmergepullsubscription 
    @publisher = @publisher, 
    @publication = @publication, 
    @publisher_db = @publicationDB,
    @subscriber_type = N'anonymous';

-- Add an agent job to synchronize the pull subscription. 
EXEC sp_addmergepullsubscription_agent 
    @publisher = @publisher, 
    @publisher_db = @publicationDB, 
    @publication = @publication, 
    @distributor = @publisher, 
    @job_login = @login, 
    @job_password = @password,
    @use_web_sync = 1,
    @internet_security_mode = @security_mode,
    @internet_url = @websyncurl,
    @internet_login = @login,
    @internet_password = @password;
GO

权限

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