Share via


sp_addpullsubscription (Transact-SQL)

新增快照式或交易式發行集的提取訂閱。 這個預存程序執行於將建立提取訂閱之資料庫的發行者端。

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

語法

sp_addpullsubscription [ @publisher= ] 'publisher'
    [ , [ @publisher_db= ] 'publisher_db' ]
        , [ @publication= ] 'publication'
    [ , [ @independent_agent= ] 'independent_agent' ]
    [ , [ @subscription_type= ] 'subscription_type' ]
    [ , [ @description= ] 'description' ]
    [ , [ @update_mode= ] 'update_mode' ]
    [ , [ @immediate_sync = ] immediate_sync ]

引數

  • [ @publisher=] 'publisher'
    這是發行者的名稱。 publisher 是 sysname,沒有預設值。

  • [ @publisher_db=] 'publisher_db'
    這是發行者資料庫的名稱。 publisher_db 是 sysname,預設值是 NULL。 Oracle 發行者會忽略 publisher_db。

  • [ @publication=] 'publication'
    這是發行集的名稱。 publication 是 sysname,沒有預設值。

  • [ @independent_agent=] 'independent_agent'
    指定這個發行集是否有獨立的散發代理程式。 independent_agent 是 nvarchar(5),預設值是 TRUE。 如果是 true,就表示這個發行集有獨立的散發代理程式。 如果是 false,每一組發行者資料庫/訂閱者資料庫配對都有一個散發代理程式。 independent_agent 是發行集的屬性,在這裡的值必須與在發行者上的值相同。

  • [ @subscription_type=] 'subscription_type'
    這是訂閱的類型。 subscription_type 是 nvarchar(9),預設值為 anonymous。 除非您想要建立訂閱但不要在發行者端註冊訂閱,否則您就必須針對 subscription_type 指定 pull 值。 在此情況下,您必須指定 anonymous 值。 在訂閱組態期間,無法建立與發行者的 SQL Server 連接時,則這是必要的。

  • [ @description=] 'description'
    這是發行集的描述。 description 是 nvarchar(100),預設值是 NULL。

  • [ @update_mode=] 'update_mode'
    這是更新的類型。 update_mode 是 nvarchar(30),而且可以是下列其中一個值。

    說明

    read-only (預設值)

    訂閱是唯讀的。 訂閱者的任何變更都不會傳回發行者。 當訂閱者不要更新時,便應該使用這個項目。

    sync tran

    啟用立即更新訂閱的支援。

    queued tran

    啟用佇列更新的訂閱。 資料修改可以在訂閱者端進行、儲存在佇列中,再傳播給發行者。

    failover

    啟用立即更新的訂閱,且利用佇列更新來作為容錯移轉。 資料修改可以在訂閱者端進行,再立即傳播給發行者。 如果發行者和訂閱者並未連接,在訂閱者端進行的資料修改可以儲存在佇列中,直到發行者和訂閱者重新連接為止。

    queued failover

    將訂閱啟用成能夠改成立即更新模式的佇列更新訂閱。 資料修改可以在訂閱者端進行,儲存在佇列中,直到重建訂閱者和發行者之間的連接為止。 當建立連續連接時,更新模式可以改成立即更新。 不支援 Oracle 發行者使用這個值

  • [ @immediate_sync =] immediate_sync
    每次執行快照集代理程式時,是否要建立或重新建立同步處理檔案。 immediate_sync 是 bit (預設值是 1),且必須設定為與 sp_addpublication 中的 immediate_sync 相同的值。immediate_sync 是發行集的屬性,而且在這裡的值必須與在發行者端的值相同。

傳回碼值

0 (成功) 或 1 (失敗)

備註

sp_addpullsubscription 用於快照式複寫和異動複寫中。

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

對於佇列更新訂閱,請利用 SQL Server 驗證來連接訂閱者,以及指定不同的連接帳戶給每個訂閱者。 當建立支援佇列更新的提取訂閱時,複寫一律會將連接設定成使用 Windows 驗證 (對於提取訂閱而言,複寫無法在訂閱者端存取使用 SQL Server 驗證所需要的中繼資料)。 在這種情況下,您應該在設定好訂閱之後,執行 sp_changesubscription,將連接改成使用 SQL Server 驗證。

如果訂閱者沒有 MSreplication_subscriptions (Transact-SQL) 資料表,sp_addpullsubscription 會建立它。 它也會在 MSreplication_subscriptions (Transact-SQL) 資料表中加入一個資料列。 如果是提取訂閱,便應該先在發行者端呼叫 sp_addsubscription (Transact-SQL)

範例

-- 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'AdventureWorks2012';

-- At the subscription database, create a pull subscription 
-- to a transactional publication.
USE [AdventureWorks2012Replica]
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

權限

只有系統管理員 (sysadmin) 固定伺服器角色或 db_owner 固定資料庫角色的成員,才能夠執行 sp_addpullsubscription

請參閱

參考

sp_addpullsubscription_agent (Transact-SQL)

sp_change_subscription_properties (Transact-SQL)

sp_droppullsubscription (Transact-SQL)

sp_helppullsubscription (Transact-SQL)

sp_helpsubscription_properties (Transact-SQL)

系統預存程序 (Transact-SQL)

概念

建立提取訂閱

建立交易式發行集的可更新訂閱

訂閱發行集