sp_addmergepullsubscription_agent (Transact-SQL)

適用於:SQL ServerAzure SQL 受控執行個體

將用來排程提取訂閱同步處理至合併式發行集的新代理程式作業。 這個預存程式會在訂閱資料庫的訂閱者端執行。

Transact-SQL 語法慣例

語法

sp_addmergepullsubscription_agent
    [ [ @name = ] N'name' ]
    , [ @publisher = ] N'publisher'
    , [ @publisher_db = ] N'publisher_db'
    , [ @publication = ] N'publication'
    [ , [ @publisher_security_mode = ] publisher_security_mode ]
    [ , [ @publisher_login = ] N'publisher_login' ]
    [ , [ @publisher_password = ] N'publisher_password' ]
    [ , [ @publisher_encrypted_password = ] publisher_encrypted_password ]
    [ , [ @subscriber = ] N'subscriber' ]
    [ , [ @subscriber_db = ] N'subscriber_db' ]
    [ , [ @subscriber_security_mode = ] subscriber_security_mode ]
    [ , [ @subscriber_login = ] N'subscriber_login' ]
    [ , [ @subscriber_password = ] N'subscriber_password' ]
    [ , [ @distributor = ] N'distributor' ]
    [ , [ @distributor_security_mode = ] distributor_security_mode ]
    [ , [ @distributor_login = ] N'distributor_login' ]
    [ , [ @distributor_password = ] N'distributor_password' ]
    [ , [ @encrypted_password = ] encrypted_password ]
    [ , [ @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 ]
    [ , [ @optional_command_line = ] N'optional_command_line' ]
    [ , [ @merge_jobid = ] merge_jobid OUTPUT ]
    [ , [ @enabled_for_syncmgr = ] N'enabled_for_syncmgr' ]
    [ , [ @ftp_address = ] N'ftp_address' ]
    [ , [ @ftp_port = ] ftp_port ]
    [ , [ @ftp_login = ] N'ftp_login' ]
    [ , [ @ftp_password = ] N'ftp_password' ]
    [ , [ @alt_snapshot_folder = ] N'alt_snapshot_folder' ]
    [ , [ @working_directory = ] N'working_directory' ]
    [ , [ @use_ftp = ] N'use_ftp' ]
    [ , [ @reserved = ] N'reserved' ]
    [ , [ @use_interactive_resolver = ] N'use_interactive_resolver' ]
    [ , [ @offloadagent = ] N'offloadagent' ]
    [ , [ @offloadserver = ] N'offloadserver' ]
    [ , [ @job_name = ] N'job_name' ]
    [ , [ @dynamic_snapshot_location = ] N'dynamic_snapshot_location' ]
    [ , [ @use_web_sync = ] use_web_sync ]
    [ , [ @internet_url = ] N'internet_url' ]
    [ , [ @internet_login = ] N'internet_login' ]
    [ , [ @internet_password = ] N'internet_password' ]
    [ , [ @internet_security_mode = ] internet_security_mode ]
    [ , [ @internet_timeout = ] internet_timeout ]
    [ , [ @hostname = ] N'hostname' ]
    [ , [ @job_login = ] N'job_login' ]
    [ , [ @job_password = ] N'job_password' ]
[ ; ]

引數

[ @name = ] N'name '

代理程式的名稱。 @name 為 sysname ,預設值為 NULL

[ @publisher = ] N'publisher '

發行者伺服器的名稱。 @publisher為 sysname ,沒有預設值。

[ @publisher_db = ] N'publisher_db '

發行者資料庫的名稱。 @publisher_db為 sysname ,沒有預設值。

[ @publication = ] N'publication '

發行集的名稱。 @publication為 sysname ,沒有預設值。

[ @publisher_security_mode = ] publisher_security_mode

同步處理時連接到發行者時要使用的安全性模式。 @publisher_security_mode 為 int ,預設值為 1 。 下列值會定義安全性模式:

  • 0 指定 SQL Server 驗證。
  • 1指定Windows 驗證。
  • 2 指定 Microsoft Entra 密碼驗證,從 SQL Server 2022 (16.x) CU 6 開始。
  • 3 指定 Microsoft Entra 整合式驗證,從 SQL Server 2022 (16.x) CU 6 開始。

重要

儘可能使用 Windows 驗證。

[ @publisher_login = ] N'publisher_login '

同步處理時連接到發行者時要使用的登入。 @publisher_login為 sysname ,預設值為 NULL

[ @publisher_password = ] N'publisher_password '

連接到發行者時所使用的密碼。 @publisher_password 為 sysname ,預設值為 NULL

重要

請勿使用空白密碼。 請使用增強式密碼。 可能的話,會在執行階段提示使用者輸入安全性認證。 如果您必須將認證儲存在指令碼檔案中,則必須維護這個檔案的安全性,使他人無法在未獲授權的情況下擅自存取。

[ @publisher_encrypted_password = ] publisher_encrypted_password

不再支援設定 @publisher_encrypted_password 。 嘗試設定這個 參數以 1 產生錯誤。

[ @subscriber = ] N'subscriber '

訂閱者的名稱。 @subscriber為 sysname ,預設值為 NULL

[ @subscriber_db = ] N'subscriber_db '

訂閱資料庫的名稱。 @subscriber_db 為 sysname ,預設值為 NULL

[ @subscriber_security_mode = ] subscriber_security_mode

同步處理時連接到訂閱者時要使用的安全性模式。 @subscriber_security_mode 為 int ,預設值為 1 。 如果 0 為 ,則指定 SQL Server 驗證。 如果 1 為 ,則指定 Windows 驗證。

注意

此參數已被取代,而且會維護腳本的回溯相容性。 如果為此參數指定值,則會傳回警告訊息,但會忽略該值。

[ @subscriber_login = ] N'subscriber_login '

同步處理時連接到訂閱者時要使用的訂閱者登入。 @subscriber_login為 sysname ,預設值為 NULL如果 subscriber_security_mode設定為 0 ,則需要@subscriber_login

注意

此參數已被取代,而且會維護腳本的回溯相容性。 如果為此參數指定值,則會傳回警告訊息,但會忽略該值。

[ @subscriber_password = ] N'subscriber_password '

SQL Server 驗證的訂閱者密碼。 @subscriber_password 為 sysname ,預設值為 NULL如果 @subscriber_security_mode設定為 0 ,則需要@subscriber_password

注意

此參數已被取代,而且會維護腳本的回溯相容性。 如果為此參數指定值,則會傳回警告訊息,但會忽略該值。

[ @distributor = ] N'distributor '

散發者的名稱。 @distributor為 sysname ,預設值 為 @publisher ;也就是說,發行者也是散發者。

[ @distributor_security_mode = ] distributor_security_mode

同步處理時連接到散發者時要使用的安全性模式。 @distributor_security_mode為 int ,預設值為 1 。 下列值會定義安全性模式:

  • 0 指定 SQL Server 驗證。
  • 1指定Windows 驗證。
  • 2 指定 Microsoft Entra 密碼驗證,從 SQL Server 2022 (16.x) CU 6 開始。
  • 3 指定 Microsoft Entra 整合式驗證,從 SQL Server 2022 (16.x) CU 6 開始。
  • 4 指定 Microsoft Entra 權杖驗證,從 SQL Server 2022 (16.x) CU 6 開始。

重要

儘可能使用 Windows 驗證。

[ @distributor_login = ] N'distributor_login '

在同步處理時連接到散發者時要使用的散發者登入。 @distributor_login 為 sysname ,預設值為 NULL如果 @distributor_security_mode設定為 0 ,則需要@distributor_login

[ @distributor_password = ] N'distributor_password '

散發者密碼。 @distributor_password為 sysname ,預設值為 NULL如果 @distributor_security_mode 設定為 0 ,則需要@distributor_password

重要

請勿使用空白密碼。 請使用增強式密碼。 可能的話,會在執行階段提示使用者輸入安全性認證。 如果您必須將認證儲存在指令碼檔案中,則必須維護這個檔案的安全性,使他人無法在未獲授權的情況下擅自存取。

[ @encrypted_password = ] encrypted_password

不再支援設定 @encrypted_password 。 嘗試設定這個 參數以 1 產生錯誤。

[ @frequency_type = ] frequency_type

值,指出合併代理程式何時執行。 @frequency_type為 int ,而且可以是下列其中一個值。

Description
1 一次性
2 [視需要]
4 每日
8 每週
16 每月
32 每月相對
64 自動啟動
128 重複執行
NULL (預設值)

注意

指定 的值 64 會導致合併代理程式以連續模式執行。 這會對應至設定 -Continuous 代理程式的參數。 如需詳細資訊,請參閱 Replication Merge Agent

[ @frequency_interval = ] frequency_interval

合併代理程式執行的日期。 @frequency_interval為 int ,預設值 NULL 為 ,而且可以是下列其中一個值。

Description
1 星期日
2 星期一
3 Tuesday
4 星期三
5 Thursday
6 星期五
7 星期六
8 Day
9 平日
10 週末日
NULL (預設值)

[ @frequency_relative_interval = ] frequency_relative_interval

合併代理程式的日期。 當@frequency_type 設定為 32 (每月相對) 時 ,會使用此參數。 @frequency_relative_interval為 int ,而且可以是下列其中一個值。

Description
1 第一個
2 Second
4 Third
8
16 姓氏
NULL (預設值)

[ @frequency_recurrence_factor = ] frequency_recurrence_factor

@frequency_type 所使用的 週期因數。 @frequency_recurrence_factor為 int ,預設值為 NULL

[ @frequency_subday = ] frequency_subday

在定義的期間重新排程的頻率。 @frequency_subday為 int,而且可以是下列其中一個值。

Description
1 一次
2 Second
4 Minute
8 Hour
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

[ @optional_command_line = ] N'optional_command_line'

提供給 合併代理程式 的選擇性命令提示字元。 @optional_command_line為 nvarchar(255),預設值為空字串。

可用來提供其他參數給 合併代理程式,例如在下列範例中,將預設查詢逾時增加為600秒:

@optional_command_line = N'-QueryTimeOut 600'

[ @merge_jobid = ] merge_jobid OUTPUT

作業標識碼的輸出參數。 @merge_jobid是 binary(16)類型的 OUTPUT 參數,預設值為 NULL

[ @enabled_for_syncmgr = ] N'enabled_for_syncmgr'

指定是否可以透過 Windows Synchronization Manager 同步處理訂閱。 @enabled_for_syncmgr為 nvarchar(5),預設值為 false。 如果 false為 ,則訂閱未向 Synchronization Manager 註冊。 如果 true為 ,則訂閱會向 Synchronization Manager 註冊,而且不需要啟動 SQL Server Management Studio 即可進行同步處理。

[ @ftp_address = ] N'ftp_address'

只是為了與舊版相容。

[ @ftp_port = ] ftp_port

只是為了與舊版相容。

[ @ftp_login = ] N'ftp_login'

只是為了與舊版相容。

[ @ftp_password = ] N'ftp_password'

只是為了與舊版相容。

[ @alt_snapshot_folder = ] N'alt_snapshot_folder'

指定要從中挑選快照集檔案的位置。 @alt_snapshot_folder為 nvarchar(255),預設值為 NULL。 如果 NULL為 ,則會從發行者指定的預設位置挑選快照集檔案。

[ @working_directory = ] N'working_directory'

當 FTP 用來傳輸快照集檔案時,用來暫時儲存發行集數據和架構檔案的工作目錄名稱。 @working_directory為 nvarchar(255),預設值為 NULL

[ @use_ftp = ] N'use_ftp'

指定使用 FTP 而不是一般通訊協議來擷取快照集。 @use_ftp為 nvarchar(5),預設值為 false

[ @reserved = ] N'reserved'

僅供參考之用。 不支援。 我們無法保證未來的相容性。

[ @use_interactive_resolver = ] N'use_interactive_resolver'

使用互動式解決器來解決允許互動式解決之所有發行項的衝突。 @use_interactive_resolver為 nvarchar(5),預設值為 false

[ @offloadagent = ] N'offloadagent'

注意

此參數已被取代,而且會維護腳本的回溯相容性。 將remote_agent_activation設定為產生錯誤以外的false值。

[ @offloadserver = ] N'offloadserver'

注意

此參數已被取代,而且會維護腳本的回溯相容性。 將remote_agent_server_name設定為任何非 NULL 值將會產生錯誤。

[ @job_name = ] N'job_name'

現有代理程式作業的名稱。 @job_name為 sysname,預設值為 NULL。 只有當訂用帳戶使用現有作業進行同步處理,而不是新建立的作業時,才會指定此參數(預設值)。 如果您不是系統管理員固定伺服器角色的成員,則必須在指定 @job_name 時指定@job_login@job_password

[ @dynamic_snapshot_location = ] N'dynamic_snapshot_location'

如果要使用篩選的數據快照集,則會從中讀取快照集檔案的資料夾路徑。 @dynamic_snapshot_location為 nvarchar(260),預設值為 NULL。 如需詳細資訊,請參閱 參數化篩選 - 參數化數據列篩選

[ @use_web_sync = ] use_web_sync

表示已啟用 Web 同步處理。 @use_web_sync為 bit,預設值為 01 指定提取訂閱可以使用 HTTP 透過因特網進行同步處理。

[ @internet_url = ] N'internet_url'

Web 同步處理之復寫接聽程式的位置(REPLISAPI.DLL)。 @internet_url為 nvarchar(260),預設值為 NULL@internet_url格式為 的完整 URLhttp://server.domain.com/directory/replisapi.dll。 如果伺服器設定為接聽埠 80 以外的埠,則埠號碼也必須以 格式 http://server.domain.com:<portnumber>/directory/replisapi.dll提供,其中 <portnumber> 代表埠。

[ @internet_login = ] N'internet_login'

當連接到使用 HTTP 基本身份驗證裝載 Web 同步處理的 Web 伺服器時,合併代理程式 所使用的登入。 @internet_login為 sysname 預設值為 NULL

[ @internet_password = ] N'internet_password'

合併代理程式 使用 HTTP 基本身份驗證連接到裝載 Web 同步處理的 Web 伺服器時所使用的密碼。 @internet_password為 nvarchar(524),預設值為 NULL

重要

請勿使用空白密碼。 請使用增強式密碼。

[ @internet_security_mode = ] internet_security_mode

使用 HTTPS 在 Web 同步處理期間連線到 Web 伺服器時,合併代理程式 所使用的驗證方法。 @internet_security_mode為 int,而且可以是下列其中一個值。

Description
0 使用基本身份驗證。
1 (預設值) 使用 Windows 整合式驗證。

注意

建議您搭配 Web 同步處理使用基本身份驗證。 若要使用 Web 同步處理,您必須建立 Web 伺服器的 TLS 連線。 如需詳細資訊,請參閱 Configure Web Synchronization

[ @internet_timeout = ] internet_timeout

Web 同步處理要求到期前,以秒為單位的時間長度。 @internet_timeout為 int,預設值為300秒數。

[ @hostname = ] N'hostname'

在參數化篩選的 子句中使用WHERE這個函式時,覆寫 的值HOST_NAME()@hostname為 sysname,預設值為 NULL

[ @job_login = ] N'job_login'

代理程序執行所在的 Windows 帳戶登入。 @job_login為 nvarchar(257),預設值為 NULL。 使用 Windows 整合式驗證時,此 Windows 帳戶一律用於代理程式連線到訂閱者,以及連接到散發者和發行者。

[ @job_password = ] N'job_password'

代理程序執行所在的 Windows 帳戶密碼。 @job_password為 sysname 預設值為 NULL

警告

請勿將驗證資訊儲存在腳本檔案中。 為了獲得最佳安全性,應在運行時間提供登入名稱和密碼。

傳回碼值

0 (成功)或 1 (失敗)。

備註

sp_addmergepullsubscription_agent 用於合併式複寫,並使用類似 sp_addpullsubscription_agent 的功能。

如需如何在執行 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

權限

只有系統管理員 固定伺服器角色或 db_owner 固定資料庫角色的成員 才能執行 sp_addmergepullsubscription_agent