sp_addmergepushsubscription_agent (Transact-SQL)

更新: 2006 年 12 月 12 日

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

ms186780.security(zh-tw,SQL.90).gif安全性注意事項:
當利用遠端散發者來設定發行者時,提供給所有參數的值 (包括 job_loginjob_password) 都會以純文字的方式傳給散發者。您應該先加密「發行者」及其遠端「散發者」之間的連接,再執行這個預存程序。如需詳細資訊,請參閱<加密 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'
    這是發行集的名稱。publicationsysname,沒有預設值。
  • [ @subscriber = ] 'subscriber'
    這是訂閱者的名稱。subscribersysname,預設值是 NULL。
  • [ @subscriber_db = ] 'subscriber_db'
    這是訂閱資料庫的名稱。subscriber_dbsysname,預設值是 NULL。
  • [ @subscriber_security_mode = ] subscriber_security_mode
    這是進行同步處理時,連接到訂閱者時使用的安全性模式。subscriber_security_modeint,預設值是 1。如果為 0,則指定 SQL Server 驗證。如果是 1,便指定 Windows 驗證。
  • [ @subscriber_login = ] 'subscriber_login'
    這是在同步處理時,用來連接訂閱者的訂閱者登入。如果 subscriber_security_mode 設定為 0,則需要 subscriber_loginsubscriber_loginsysname,預設值是 NULL。
  • [ @subscriber_password = ] 'subscriber_password'
    這是 SQL Server 驗證的訂閱者密碼。如果 subscriber_security_mode 設為 0,則需要 subscriber_passwordsubscriber_passwordsysname,預設值是 NULL。如果使用訂閱者密碼,它會自動加密。

    ms186780.security(zh-tw,SQL.90).gif安全性注意事項:
    可能的話,會在執行階段提示使用者輸入安全性認證。如果您必須將認證儲存在指令碼檔案中,則必須維護這個檔案的安全性,使他人無法在未獲授權的情況下擅自存取。
  • [ @publisher_security_mode = ] publisher_security_mode
    這是進行同步處理時,連接到發行者時使用的安全性模式。publisher_security_modeint,預設值是 1。如果為 0,則指定 SQL Server 驗證。如果是 1,便指定 Windows 驗證。
  • [ @publisher_login = ] 'publisher_login'
    這是在同步處理時,用來連接發行者的登入。publisher_loginsysname,預設值是 NULL。
  • [ @publisher_password = ] 'publisher_password'
    這是連接到發行者時所用的密碼。publisher_passwordsysname,預設值是 NULL。

    ms186780.security(zh-tw,SQL.90).gif安全性注意事項:
    可能的話,會在執行階段提示使用者輸入安全性認證。如果您必須將認證儲存在指令碼檔案中,則必須維護這個檔案的安全性,使他人無法在未獲授權的情況下擅自存取。
  • [ @job_login = ] 'job_login'
    這是執行代理程式之 Windows 帳戶的登入。job_loginnvarchar(257),預設值是 NULL。代理程式連接到散發者時,一律使用這個 Windows 帳戶,當利用 Windows 整合式驗證來連接到訂閱者和發行者時,也一律使用這個 Windows 帳戶。
  • [ @job_password = ] 'job_password'
    這是執行代理程式之 Windows 帳戶的密碼。job_passwordsysname,沒有預設值。

    ms186780.security(zh-tw,SQL.90).gif安全性注意事項:
    可能的話,會在執行階段提示使用者輸入安全性認證。如果您必須將認證儲存在指令碼檔案中,則必須維護這個檔案的安全性,使他人無法在未獲授權的情況下擅自存取。
  • [ @job_name = ] 'job_name'
    這是現有代理程式作業的名稱。job_namesysname,預設值是 NULL。只有在利用現有的作業來建立同步處理訂閱,而不用新建立的作業 (預設值) 時,才指定這個參數。如果您不是系統管理員 (sysadmin) 固定伺服器角色的成員,當您指定 job_name 時,必須指定 job_loginjob_password
  • [ @frequency_type = ] frequency_type
    這是合併代理程式的排程頻率。frequency_typeint,它可以是下列值之一。

    描述

    1

    一次

    2

    視需要

    4 (預設值)

    每日

    8

    每週

    16

    每月

    32

    每月相對

    64

    自動啟動

    128

    重複執行

    NULL

     

    ms186780.note(zh-tw,SQL.90).gif附註:
    指定 64 的值會導致合併代理程式以連續模式執行。這就相當於設定代理程式的 -Continuous 參數。如需詳細資訊,請參閱<Replication Merge Agent>。
  • [ @frequency_interval = ] frequency_interval
    這是合併代理程式執行的天數。frequency_intervalint,它可以是下列值之一。

    描述

    1

    星期日

    2

    星期一

    3

    星期二

    4

    星期三

    5

    星期四

    6

    星期五

    7

    星期六

    8

    9

    工作日

    10

    週末

    NULL (預設值)

     

  • [ @frequency_relative_interval = ] frequency_relative_interval
    這是合併代理程式的日期。當 frequency_type 設為 32 (每月相對) 時,則使用這個參數。frequency_relative_intervalint,它可以是下列值之一。

    描述

    1

    第一個

    2

    第二個

    4

    第三個

    8

    第四個

    16

    最後一個

    NULL (預設值)

     

  • [ @frequency_recurrence_factor = ] frequency_recurrence_factor
    這是 frequency_type 所用的循環因數。frequency_recurrence_factorint,預設值是 NULL。
  • [ @frequency_subday = ] frequency_subday
    在定義的期間內,重新排程的頻率。frequency_subdayint,它可以是下列值之一。

    描述

    1

    一次

    2

    第二個

    4

    分鐘

    8

    小時

    NULL (預設值)

     

  • [ @frequency_subday_interval = ] frequency_subday_interval
    這是 frequency_subday 的間隔。frequency_subday_intervalint,預設值是 NULL。
  • [ @active_start_time_of_day = ] active_start_time_of_day
    這是第一次排程合併代理程式的當日時間,格式為 HHMMSS。active_start_time_of_dayint,預設值是 NULL
  • [ @active_end_time_of_day = ] active_end_time_of_day
    這是排程停止合併代理程式的當日時間,格式為 HHMMSS。active_end_time_of_dayint,預設值是 NULL。
  • [ @active_start_date = ] active_start_date
    這是第一次排程合併代理程式的日期,格式為 YYYYMMDD。active_start_dateint,預設值是 NULL。
  • [ @active_end_date = ] active_end_date
    這是排程停止合併代理程式的日期,格式為 YYYYMMDD。active_end_dateint,預設值是 NULL。
  • [ @enabled_for_syncmgr = ] 'enabled_for_syncmgr'
    指定是否能夠利用 Windows Synchronization Manager 同步處理訂閱。enabled_for_syncmgrnvarchar(5),預設值是 FALSE。如果是 false,便不用向 Synchronization Manager 註冊訂閱。如果是 true,便要向 Synchronization Manager 註冊訂閱,且不需要啟動 SQL Server Management Studio,就可以同步處理。

傳回碼值

0 (成功) 或 1 (失敗)

備註

sp_addmergepushsubscription_agent 用於合併式複寫中,且會使用類似 sp_addpushsubscription_agent 的功能。

權限

只有系統管理員 (sysadmin) 固定伺服器角色或 db_owner 固定資料庫角色的成員,才能夠執行 sp_addmergepushsubscription_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 [AdventureWorks]
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

請參閱

參考

sp_addmergesubscription (Transact-SQL)
sp_changemergesubscription (Transact-SQL)
sp_dropmergesubscription (Transact-SQL)
sp_helpmergesubscription (Transact-SQL)

其他資源

如何:建立發送訂閱 (複寫 Transact-SQL 程式設計)
訂閱發行集

說明及資訊

取得 SQL Server 2005 協助

變更歷程記錄

版本 歷程記錄

2006 年 12 月 12 日

新增內容:
  • 新增有關 64@frequency_type 會導致合併代理程式以連續模式執行的注意事項。
更新的內容:
  • 變更文件:@frequency_type 的預設值為 4