sp_addmergepullsubscription (Transact-SQL)
更新日期: 2007 年 9 月 15 日
添加对合并发布的请求订阅。 此存储过程在订阅服务器的订阅数据库中执行。
语法
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),且可以是 global、local 或 anonymous。 在 SQL Server 2005 中,本地订阅被称为客户端订阅,而全局订阅被称为服务器订阅。 有关详细信息,请参阅合并复制如何检测和解决冲突中的“订阅类型”部分。 如果要创建订阅而不在发布服务器上注册订阅,则需要使用值 anonymous。 这对于 Web 同步之类的情况很有必要,在这些情况下,您不能在订阅配置过程中建立到发布服务器的 SQL Server 连接。
- [ @subscription_priority=] subscription_priority
订阅优先级。subscription_priority的数据类型为 real,默认值为 NULL。 对于本地订阅和匿名订阅,优先级为 0.0。 在检测到冲突时,默认冲突解决程序将使用该优先级来选取入选方。 全局订阅服务器的订阅优先级必须低于 100,因为 100 是发布服务器的优先级。
[ @sync_type=] 'sync_type'
订阅同步类型。sync_type的数据类型为 nvarchar(15),默认值为 automatic。 可以为 automatic 或 none。 如果为 automatic,已发布表的架构和初始数据将首先传输到订阅服务器。 如果为 none,将假定订阅服务器已经拥有已发布表的架构和初始数据。 始终会传输系统表和数据。注意: 不建议指定 none 值。 有关详细信息,请参阅初始化合并订阅(不使用快照)。
- [ @description =] 'description'
对该请求订阅的简短说明。description的数据类型为 nvarchar(255),默认值为 NULL。 此值由复制监视器显示在“友好名称”列中,该列可以用来对所监视发布的订阅进行排序。
返回代码值
0(成功)或 1(失败)
备注
sp_addmergepullsubscription 用于合并复制。
如果使用 SQL Server 代理对订阅进行同步处理,则 sp_addmergepullsubscription_agent 存储过程必须在订阅服务器上运行,才能创建与发布同步的代理和作业。
权限
只有 sysadmin 固定服务器角色或 db_owner 固定数据库角色的成员才能执行 sp_addmergepullsubscription。
示例
-- 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'AdventureWorks';
SET @hostname = N'adventure-works\david8';
-- At the subscription database, create a pull subscription
-- to a merge publication.
USE [AdventureWorksReplica]
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'AdventureWorks';
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 [AdventureWorksReplica]
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
请参阅
参考
sp_addmergepullsubscription_agent (Transact-SQL)
sp_changemergepullsubscription (Transact-SQL)
sp_dropmergepullsubscription (Transact-SQL)
sp_helpmergepullsubscription (Transact-SQL)
sp_helpsubscription_properties (Transact-SQL)
其他资源
如何创建请求订阅(复制 Transact-SQL 编程)
订阅发布
帮助和信息
更改历史记录
发布日期 | 历史记录 |
---|---|
2007 年 9 月 15 日 |
|
2006 年 12 月 12 日 |
|