sp_addmergepullsubscription (Transact-SQL)

适用于SQL Server Azure SQL 托管实例

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

Transact-SQL 语法约定

语法

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

参数

[ @publication = ] N'publication'

发布的名称。 @publicationsysname,无默认值。

[ @publisher = ] N'publisher'

发布服务器的名称。 @publishersysname,默认为本地服务器名称。 发布服务器必须为有效服务器。

[ @publisher_db = ] N'publisher_db'

发布服务器数据库的名称。 @publisher_db为 sysname,默认值为 NULL.

[ @subscriber_type = ] N'subscriber_type'

订阅服务器的类型。 @subscriber_typenvarchar(15),默认值 local为 ,可以是其中一个 globallocal也可以 anonymous。 在 SQL Server 2005(9.x)及更高版本中,本地订阅称为客户端订阅,全局订阅称为服务器订阅。

[ @subscription_priority = ] subscription_priority

订阅优先级。 @subscription_priority真实的,默认值为 NULL. 对于本地和匿名订阅,优先级为 0.0。 在检测到冲突时,默认冲突解决程序将使用该优先级来选取入选方。 对于全局订阅者,订阅优先级必须小于 100,这是发布服务器的优先级。

[ @sync_type = ] N'sync_type'

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

建议指定值 automatic

[ @description = ] N'description'

此请求订阅的简要说明。 @descriptionnvarchar(255),默认值为 NULL. 此值由列中的复制监视器 Friendly Name 显示,该列可用于对受监视发布的订阅进行排序。

返回代码值

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'AdventureWorks2022';
SET @hostname = N'adventure-works\david8';

-- At the subscription database, create a pull subscription 
-- to a merge publication.
USE [AdventureWorks2022Replica]
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'AdventureWorks2022';
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 [AdventureWorks2022Replica]
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