sp_addmergepushsubscription_agent (Transact-SQL)

新增一項新的代理程式作業,以便用來排程合併式發行集發送訂閱的同步處理。 這個預存程序執行於發行集資料庫的發行者端。

安全性注意事項安全性注意事項

當利用遠端散發者來設定發行者時,提供給所有參數的值 (包括 job_login 和 job_password) 都會以純文字的方式傳給散發者。 您應該先加密「發行者」及其遠端「散發者」之間的連接,再執行這個預存程序。 如需詳細資訊,請參閱<啟用 Database Engine 的加密連接 (SQL Server 組態管理員)>。

主題連結圖示 Transact-SQL 語法慣例

語法

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 整合式驗證來連接到訂閱者和發行者時,也一律使用這個 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 Synchronization Manager 來同步處理訂閱。 enabled_for_syncmgr 是 nvarchar(5),預設值是 FALSE。 如果是 false,便不用向 Synchronization Manager 註冊訂閱。 如果是 true,便要向 Synchronization Manager 註冊訂閱,且不需要啟動 SQL Server Management Studio,就可以同步處理。

傳回碼值

0 (成功) 或 1 (失敗)

備註

sp_addmergepushsubscription_agent 用於合併式複寫中,且會使用類似 sp_addpushsubscription_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".

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

-- Add a push subscription to a merge publication.
USE [AdventureWorks2012];
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

請參閱

參考

sp_addmergesubscription (Transact-SQL)

sp_changemergesubscription (Transact-SQL)

sp_dropmergesubscription (Transact-SQL)

sp_helpmergesubscription (Transact-SQL)

概念

建立發送訂閱

訂閱發行集