sp_addpullsubscription_agent (Transact-SQL)

更新: 2006 年 12 月 12 日

加入一項新排程的代理程式作業,以便用來同步處理提取訂閱與交易式發行集。這個預存程序執行於訂閱資料庫的訂閱者端。

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

語法

sp_addpullsubscription_agent [ @publisher = ] 'publisher'
    [ , [ @publisher_db = ] 'publisher_db' ]
        , [ @publication = ] 'publication'
    [ , [ @subscriber = ] 'subscriber' ]
    [ , [ @subscriber_db = ] 'subscriber_db' ]
    [ , [ @subscriber_security_mode = ] subscriber_security_mode ]
    [ , [ @subscriber_login = ] 'subscriber_login' ]
    [ , [ @subscriber_password = ] 'subscriber_password' ]
    [ , [ @distributor = ] 'distributor' ]
    [ , [ @distribution_db = ] 'distribution_db' ]
    [ , [ @distributor_security_mode = ] distributor_security_mode ]
    [ , [ @distributor_login = ] 'distributor_login' ]
    [ , [ @distributor_password = ] 'distributor_password' ]
    [ , [ @optional_command_line = ] 'optional_command_line' ]
    [ , [ @frequency_type = ] frequency_type ]
    [ , [ @frequency_interval = ] frequency_interval ]
    [ , [ @frequency_relative_interval = ] frequency_relative_interval ]
    [ , [ @frequency_recurrence_factor = ] frequency_recurrence_factor ]
    [ , [ @frequency_subda y= ] 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 ]
    [ , [ @distribution_jobid = ] distribution_jobid OUTPUT ]
    [ , [ @encrypted_distributor_password = ] encrypted_distributor_password ]
    [ , [ @enabled_for_syncmgr = ] 'enabled_for_syncmgr' ]
    [ , [ @ftp_address = ] 'ftp_address' ]
    [ , [ @ftp_port = ] ftp_port ]
    [ , [ @ftp_login = ] 'ftp_login' ]
    [ , [ @ftp_password = ] 'ftp_password' ]
    [ , [ @alt_snapshot_folder = ] 'alternate_snapshot_folder' ]
    [ , [ @working_directory = ] 'working_directory' ]
    [ , [ @use_ftp = ] 'use_ftp' ]
    [ , [ @publication_type = ] publication_type ]
    [ , [ @dts_package_name = ] 'dts_package_name' ]
    [ , [ @dts_package_password = ] 'dts_package_password' ]
    [ , [ @dts_package_location = ] 'dts_package_location' ]
    [ , [ @reserved = ] 'reserved' ]
    [ , [ @offloadagent = ] 'remote_agent_activation' ]
    [ , [ @offloadserver = ] 'remote_agent_server_name']
    [ , [ @job_name = ] 'job_name' ]
    [ , [ @job_login = ] 'job_login' ] 
    [ , [ @job_password = ] 'job_password' ] 

引數

  • [ @publisher=] 'publisher'
    這是發行者的名稱。publishersysname,沒有預設值。
  • [ @publisher_db=] **'**publisher_db'
    這是發行者資料庫的名稱。publisher_dbsysname,預設值是 NULL。Oracle 發行者會忽略 publisher_db
  • [ @publication=] 'publication'
    這是發行集的名稱。publicationsysname,沒有預設值。
  • [ @subscriber=] 'subscriber'
    這是訂閱者的名稱。subscribersysname,預設值是 NULL。

    ms188358.note(zh-tw,SQL.90).gif附註:
    這個參數已被取代,維護它的目的,只是為了與舊版的指令碼相容。
  • [ @subscriber_db=] 'subscriber_db'
    這是訂閱資料庫的名稱。subscriber_dbsysname,預設值是 NULL。

    ms188358.note(zh-tw,SQL.90).gif附註:
    這個參數已被取代,維護它的目的,只是為了與舊版的指令碼相容。
  • [ @subscriber_security_mode=] subscriber_security_mode
    這是進行同步處理時,連接到訂閱者時使用的安全性模式。subscriber_security_modeint,,預設值是 NULL。0 指定 SQL Server 驗證。1 指定 Windows 驗證。

    ms188358.note(zh-tw,SQL.90).gif附註:
    這個參數已被取代,維護它的目的,只是為了與舊版的指令碼相容。散發代理程式一律是利用 Windows 驗證來連接到本機訂閱者。如果這個參數指定了 NULL 或 1 以外的值,便會傳回警告訊息。
  • [ @subscriber_login =] 'subscriber_login'
    這是進行同步處理時,連接到訂閱者時使用的訂閱者登入。subscriber_loginsysname,預設值是 NULL。

    ms188358.note(zh-tw,SQL.90).gif附註:
    這個參數已被取代,維護它的目的,只是為了與舊版的指令碼相容。如果指定了這個參數值,便會傳回警告訊息,但會忽略這個值。
  • [ @subscriber_password=] 'subscriber_password'
    這是訂閱者密碼。如果 subscriber_security_mode 設為 0,則需要 subscriber_passwordsubscriber_passwordsysname,預設值是 NULL。如果使用訂閱者密碼,它會自動加密。

    ms188358.note(zh-tw,SQL.90).gif附註:
    這個參數已被取代,維護它的目的,只是為了與舊版的指令碼相容。如果指定了這個參數值,便會傳回警告訊息,但會忽略這個值。
  • [ @distributor=] 'distributor'
    這是散發者的名稱。distributorsysname,預設值是 publisher 所指定的值。
  • [ @distribution_db=] 'distribution_db'
    這是散發資料庫的名稱。distribution_dbsysname,預設值是 NULL。
  • [ @distributor_security_mode=] distributor_security_mode
    這是在同步處理時,用來連接散發者的安全性模式。distributor_security_modeint,預設值是 10 指定 SQL Server 驗證。1 指定 Windows 驗證。

    ms188358.security(zh-tw,SQL.90).gif安全性注意事項:
    可能的話,請使用「Windows 驗證」。
  • [ @distributor_login=] 'distributor_login'
    這是在同步處理時,用來連接散發者的散發者登入。如果 distributor_security_mode 設為 0,則需要 distributor_logindistributor_loginsysname,預設值是 NULL。
  • [ @distributor_password =] 'distributor_password'
    這是散發者密碼。如果 distributor_security_mode 設為 0,則需要 distributor_passworddistributor_passwordsysname,預設值是 NULL。

    ms188358.security(zh-tw,SQL.90).gif安全性注意事項:
    密碼不能空白。請使用增強式密碼。 可能的話,會在執行階段提示使用者輸入安全性認證。如果您必須將認證儲存在指令碼檔案中,則必須維護這個檔案的安全性,使他人無法在未獲授權的情況下擅自存取。
  • [ @optional_command_line=] 'optional_command_line'
    這是提供給散發代理程式的選擇性命令提示字元。例如,-DefinitionFile C:\Distdef.txt 或 -CommitBatchSize 10。optional_command_linenvarchar(4000),預設值是空字串。
  • [ @frequency_type=] frequency_type
    這是散發代理程式的排程頻率。frequency_typeint,它可以是下列值之一。

    描述

    1

    一次

    2 (預設值)

    視需要

    4

    每日

    8

    每週

    16

    每月

    32

    每月相對

    64

    自動啟動

    128

    重複執行

    ms188358.note(zh-tw,SQL.90).gif附註:
    指定 64 的值會導致散發代理程式以連續模式執行。這就相當於設定代理程式的 -Continuous 參數。如需詳細資訊,請參閱<Replication Distribution Agent>。
  • [ @frequency_interval=] frequency_interval
    這是 frequency_type 設定的頻率所套用的值。frequency_intervalint,預設值是 1。
  • [ @frequency_relative_interval=] frequency_relative_interval
    這是散發代理程式的日期。當 frequency_type 設為 32 (每月相對) 時,則使用這個參數。frequency_relative_intervalint,它可以是下列值之一。

    描述

    1 (預設值)

    第一個

    2

    第二個

    4

    第三個

    8

    第四個

    16

    最後一個

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

    描述

    1 (預設值)

    一次

    2

    第二個

    4

    分鐘

    8

    小時

  • [ @frequency_subday_interval=] frequency_subday_interval
    這是 frequency_subday 的間隔。frequency_subday_intervalint,預設值是 1
  • [ @active_start_time_of_day=] active_start_time_of_day
    這是第一次排程散發代理程式的當日時間,格式為 HHMMSS。active_start_time_of_dayint,預設值是 0
  • [ @active_end_time_of_day=] active_end_time_of_day
    這是停止對散發代理程式進行排程的當日時間,格式為 HHMMSS。active_end_time_of_dayint,預設值是 0
  • [ @active_start_date=] active_start_date
    這是第一次排程散發代理程式的日期,格式為 YYYYMMDD。active_start_dateint,預設值是 0
  • [ @active_end_date=] active_end_date
    這是停止對散發代理程式進行排程的日期,格式為 YYYYMMDD。active_end_dateint,預設值是 0
  • [ @distribution_jobid =] distribution_jobidOUTPUT
    這是這項作業之散發代理程式的識別碼。distribution_jobidbinary(16),預設值是 NULL,它是一個 OUTPUT 參數。
  • [ @encrypted_distributor_password=] encrypted_distributor_password
    已不再支援設定 encrypted_distributor_password。嘗試將這個 bit 參數設為 1 會產生錯誤。
  • [ @enabled_for_syncmgr=] 'enabled_for_syncmgr'
    這是指是否能夠利用 Microsoft Synchronization Manager 同步處理訂閱。enabled_for_syncmgrnvarchar(5),預設值是 FALSE。如果是 false,便不用向 Synchronization Manager 註冊訂閱。如果是 true,便要向 Synchronization Manager 註冊訂閱,且不需要啟動 SQL Server Management Studio,就可以同步處理。
  • [ @ftp_address=] 'ftp_address'
    只是為了與舊版相容。
  • [ @ftp_port=] ftp_port
    只是為了與舊版相容。
  • [ @ftp_login=] 'ftp_login'
    只是為了與舊版相容。
  • [ @ftp_password=] 'ftp_password'
    只是為了與舊版相容。
  • [ @alt_snapshot_folder= ] **'**alternate_snapshot_folder'
    指定快照集替代資料夾的位置。alternate_snapshot_foldernvarchar(255),預設值是 NULL。
  • [ @working_directory= ] 'working_director'
    這是用來儲存發行集的資料檔和結構描述檔之工作目錄的名稱。working_directorynvarchar(255),預設值是 NULL。這個名稱應該用 UNC 格式來指定。
  • [ @use_ftp= ] 'use_ftp'
    指定利用 FTP 而不是一般通訊協定來擷取快照集。use_ftpnvarchar(5),預設值是 FALSE。
  • [ @publication_type= ] publication_type
    指定發行集的複寫類型。publication_typetinyint,預設值是 0。如果是 0,發行集是交易類型。如果是 1,發行集是快照集類型。如果是 2,發行集便是合併類型。
  • [ @dts_package_name= ] 'dts_package_name'
    指定 DTS 封裝的名稱。dts_package_namesysname,預設值是 NULL。例如,若要指定 DTSPub_Package 封裝,這個參數便是 @dts_package_name = N'DTSPub_Package'
  • [ @dts_package_password= ] 'dts_package_password'
    指定封裝的密碼 (如果有的話)。dts_package_passwordsysname,預設值是 NULL,表示封裝沒有密碼。

    ms188358.note(zh-tw,SQL.90).gif附註:
    如果指定了 dts_package_name,則必須指定密碼。
  • [ @dts_package_location= ] 'dts_package_location'
    指定封裝位置。dts_package_locationnvarchar(12),預設值是 subscriber。封裝位置可以是散發者訂閱者
  • [ @reserved= ] 'reserved'
    僅供內部使用。
  • [ @offloadagent= ] 'remote_agent_activation'

    ms188358.note(zh-tw,SQL.90).gif附註:
    遠端代理程式啟動已被取代,不再受到支援。支援這個參數的目的,只是為了與舊版的指令碼相容。將 remote_agent_activation 設為 false 以外的值會產生錯誤。
  • [ @offloadserver= ] 'remote_agent_server_name'

    ms188358.note(zh-tw,SQL.90).gif附註:
    遠端代理程式啟動已被取代,不再受到支援。支援這個參數的目的,只是為了與舊版的指令碼相容。將 remote_agent_server_name 設為任何非 NULL 值,都會產生錯誤。
  • [ @job_name= ] 'job_name'
    這是現有代理程式作業的名稱。job_namesysname,預設值是 NULL。只有在訂閱將利用現有的作業來同步處理,而不用新建立的作業 (預設值) 時,才指定這個參數。如果您不是系統管理員 (sysadmin) 固定伺服器角色的成員,當您指定 job_name 時,必須指定 job_loginjob_password
  • [ @job_login= ] 'job_login'
    這是執行代理程式之 Windows 帳戶的登入。job_loginnvarchar(257),沒有預設值。通往訂閱者的代理程式連接一律使用這個 Windows 帳戶。
  • [ @job_password= ] 'job_password'
    這是執行代理程式之 Windows 帳戶的密碼。job_passwordsysname,沒有預設值。

    ms188358.security(zh-tw,SQL.90).gif安全性注意事項:
    可能的話,會在執行階段提示使用者輸入安全性認證。如果您必須將認證儲存在指令碼檔案中,則必須維護這個檔案的安全性,使他人無法在未獲授權的情況下擅自存取。

傳回碼值

0 (成功) 或 1 (失敗)

備註

sp_addpullsubscription_agent 用於快照式複寫和交易式複寫中。

權限

只有系統管理員 (sysadmin) 固定伺服器角色或 db_owner 固定資料庫角色的成員,才能夠執行 sp_addpullsubscription_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;
SET @publication = N'AdvWorksProductTran';
SET @publisher = $(PubServer);
SET @publicationDB = N'AdventureWorks';

-- At the subscription database, create a pull subscription 
-- to a transactional publication.
USE [AdventureWorksReplica]
EXEC sp_addpullsubscription 
  @publisher = @publisher, 
  @publication = @publication, 
  @publisher_db = @publicationDB;

-- Add an agent job to synchronize the pull subscription.
EXEC sp_addpullsubscription_agent 
  @publisher = @publisher, 
  @publisher_db = @publicationDB, 
  @publication = @publication, 
  @distributor = @publisher, 
  @job_login = $(Login), 
  @job_password = $(Password);
GO

請參閱

參考

sp_addpullsubscription (Transact-SQL)
sp_change_subscription_properties (Transact-SQL)
sp_droppullsubscription (Transact-SQL)
sp_helppullsubscription (Transact-SQL)
sp_helpsubscription_properties (Transact-SQL)

其他資源

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

說明及資訊

取得 SQL Server 2005 協助

變更歷程記錄

版本 歷程記錄

2006 年 12 月 12 日

新增內容:
  • 新增有關 64@frequency_type 會導致散發代理程式以連續模式執行的注意事項。