sp_addmergepushsubscription_agent (Transact-SQL)
添加一个新代理作业,用于制定合并发布推送订阅的同步计划。 此存储过程在发布服务器上对发布数据库执行。
安全说明 |
---|
使用远程分发服务器配置发布服务器时,为所有参数提供的值(包括 job_login 和 job_password)都会以纯文本方式发送到该分发服务器。 在执行此存储过程之前,应该对发布服务器及其远程分发服务器之间的连接进行加密。 有关详细信息,请参阅加密与 SQL Server 的连接。 |
语法
sp_addmergepushsubscription_agent [ @publication =] 'publication'
[ , [ @subscriber = ] 'subscriber' ]
[ , [ @subscriber_db = ] 'subscriber_db' ]
[ , [ @subscriber_security_mode = ] subscriber_security_mode ]
[ , [ @subscriber_login = ] 'subscriber_login' ]
[ , [ @subscriber_password = ] 'subscriber_password' ]
[ , [ @publisher_security_mode = ] publisher_security_mode ]
[ , [ @publisher_login = ] 'publisher_login' ]
[ , [ @publisher_password = ] 'publisher_password' ]
[ , [ @job_login = ] 'job_login' ]
[ , [ @job_password = ] 'job_password' ]
[ , [ @job_name = ] 'job_name' ]
[ , [ @frequency_type = ] frequency_type ]
[ , [ @frequency_interval = ] frequency_interval ]
[ , [ @frequency_relative_interval = ] frequency_relative_interval ]
[ , [ @frequency_recurrence_factor = ] frequency_recurrence_factor ]
[ , [ @frequency_subday = ] frequency_subday ]
[ , [ @frequency_subday_interval = ] frequency_subday_interval ]
[ , [ @active_start_time_of_day = ] active_start_time_of_day ]
[ , [ @active_end_time_of_day = ] active_end_time_of_day ]
[ , [ @active_start_date = ] active_start_date ]
[ , [ @active_end_date = ] active_end_date ]
[ , [ @enabled_for_syncmgr = ] 'enabled_for_syncmgr' ]
参数
[ @publication =] 'publication'
发布的名称。publication 的数据类型为 sysname,无默认值。[ @subscriber= ] 'subscriber'
订阅服务器的名称。subscriber 的数据类型为 sysname,默认值为 NULL。[ @subscriber_db=] 'subscriber_db'
订阅数据库的名称。subscriber_db 的数据类型为 sysname,默认值为 NULL。[ @subscriber_security_mode=] subscriber_security_mode
在同步时连接到订阅服务器所采用的安全模式。subscriber_security_mode 的数据类型为 int,默认值为 1。如果此值为 0,则指定 SQL Server 身份验证。 如果为 1,则指定了 Windows 身份验证。[ @subscriber_login =] 'subscriber_login'
同步时连接到订阅服务器所使用的订阅服务器登录名。如果将 subscriber_security_mode 设置为 0,则 subscriber_login 是必需的。subscriber_login 的数据类型为 sysname,默认值为 NULL。[ @subscriber_password=] 'subscriber_password'
用于 SQL Server 身份验证的订阅服务器密码。如果将 subscriber_security_mode 设置为 0,则 subscriber_password 是必需的。subscriber_password 的数据类型为 sysname,默认值为 NULL。 如果使用订阅服务器密码,将自动对密码进行加密。安全说明 如果可能,请在运行时提示用户输入安全凭据。 如果必须在脚本文件中存储凭据,则必须保护文件以防止未经授权的访问。
[ @publisher_security_mode = ] publisher_security_mode
在同步时连接到发布服务器所采用的安全模式。publisher_security_mode 的数据类型为 int,默认值为 1。如果此值为 0,则指定 SQL Server 身份验证。 如果为 1,则指定了 Windows 身份验证。[ @publisher_login = ] 'publisher_login'
在同步时用于连接到发布服务器的登录名。publisher_login 的数据类型为 sysname,默认值为 NULL。[ @publisher_password = ] 'publisher_password'
连接到发布服务器时所用的密码。publisher_password 的数据类型为 sysname,默认值为 NULL。安全说明 如果可能,请在运行时提示用户输入安全凭据。 如果必须在脚本文件中存储凭据,则必须保护文件以防止未经授权的访问。
[ @job_login = ] 'job_login'
用于运行代理的 Windows 帐户的密码。job_login 的数据类型为 nvarchar(257),默认值为 NULL。 此 Windows 帐户始终用于到分发服务器的代理连接,以及在使用 Windows 集成身份验证时用于到订阅服务器和发布服务器的连接。[ @job_password = ] 'job_password'
运行代理时所用的 Windows 帐户的密码。job_password 的数据类型为 sysname,无默认值。安全说明 如果可能,请在运行时提示用户输入安全凭据。 如果必须在脚本文件中存储凭据,则必须保护文件以防止未经授权的访问。
[ @job_name = ] 'job_name'
现有代理作业的名称。job_name 的数据类型为 sysname,默认值为 NULL。 仅当使用现有作业而不是(默认的)新创建的作业同步订阅时,才指定此参数。 如果不是 sysadmin 固定服务器角色的成员,则在指定 job_name 时,必须指定 job_login 和 job_password。[ @frequency_type=] frequency_type
安排合并代理的频率。frequency_type 的数据类型为 int,可以是下列值之一。值
说明
1
一次
2
按需
4
每天
8
每周
16
每月
32
“每月”选项相关
64
自动启动
128
重复执行
NULL(默认值)
注意 指定值 64 将使合并代理在连续模式下运行。 这相当于设置代理的 -Continuous 参数。 有关详细信息,请参阅复制合并代理。
[ @frequency_interval=] frequency_interval
合并代理运行的日子。frequency_interval 的数据类型为 int,可以是下列值之一。值
说明
1
星期日
2
星期一
3
星期二
4
星期三
5
星期四
6
星期五
7
星期六
8
天
9
工作日
10
周末
NULL(默认值)
[ @frequency_relative_interval = ]frequency_relative_interval
合并代理的日期。 当 frequency_type 设置为 32(与“每月”选项相关)时使用此参数。frequency_relative_interval 的数据类型为 int,可以是下列值之一。值
说明
1
第一个
2
第二个
4
第三个
8
第四个
16
最后一个
NULL(默认值)
[ @frequency_recurrence_factor=] frequency_recurrence_factor
frequency_type 使用的重复因子。frequency_recurrence_factor 的数据类型为 int,默认值为 NULL。[ @frequency_subday = ]frequency_subday
在指定期内重新安排计划的频率。frequency_subday 的数据类型为 int,可以是下列值之一。值
说明
1
一次
2
秒
4
分钟
8
小时
NULL(默认值)
[ @frequency_subday_interval = ]frequency_subday_interval
frequency_subday 的间隔。frequency_subday_interval 的数据类型为 int,默认值为 NULL。[ @active_start_time_of_day = ] active_start_time_of_day
第一次安排合并代理的时间,格式为 HHMMSS。active_start_time_of_day 的数据类型为 int,默认值为 NULL。[ @active_end_time_of_day=] active_end_time_of_day
停止安排合并代理的时间,格式为 HHMMSS。active_end_time_of_day 的数据类型为 int,默认值为 NULL。[ @active_start_date = ] active_start_date
第一次安排合并代理的日期,格式为 YYYYMMDD。active_start_date 的数据类型为 int,默认值为 NULL。[ @active_end_date = ] active_end_date
停止安排合并代理的日期,格式为 YYYYMMDD。active_end_date 的数据类型为 int,默认值为 NULL。[ @enabled_for_syncmgr=] 'enabled_for_syncmgr'
指定是否可以通过 Windows 同步管理器同步订阅。enabled_for_syncmgr 的数据类型为 nvarchar(5),默认值为 FALSE。 如果为 false,则表示该订阅没有向同步管理器注册。 如果为 true,则表示该订阅已向同步管理器注册,可以在不启动 SQL Server Management Studio 的情况下进行同步。
返回代码值
0(成功)或 1(失败)
示例
-- 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".
DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
DECLARE @hostname AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
SET @subscriber = $(SubServer);
SET @subscriptionDB = N'AdventureWorks2008R2Replica';
SET @hostname = N'adventure-works\david8'
-- Add a push subscription to a merge publication.
USE [AdventureWorks2008R2]
EXEC sp_addmergesubscription
@publication = @publication,
@subscriber = @subscriber,
@subscriber_db = @subscriptionDB,
@subscription_type = N'push',
@hostname = @hostname;
--Add an agent job to synchronize the push subscription.
EXEC sp_addmergepushsubscription_agent
@publication = @publication,
@subscriber = @subscriber,
@subscriber_db = @subscriptionDB,
@job_login = $(Login),
@job_password = $(Password);
GO
权限
只有 sysadmin 固定服务器角色的成员或 db_owner 固定数据库角色的成员才能执行 sp_addmergepushsubscription_agent。