sp_adddistpublisher (Transact-SQL)

設定發行者來使用指定的散發資料庫。 這個預存程序執行於任何資料庫中的散發者端。 請注意,您必須已執行 sp_adddistributor (Transact-SQL)sp_adddistributiondb (Transact-SQL) 這兩個預存程序,才能使用這個預存程序。

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

語法

sp_adddistpublisher [ @publisher= ] 'publisher'  
        , [ @distribution_db= ] 'distribution_db' 
    [ , [ @security_mode= ] security_mode ] 
    [ , [ @login= ] 'login' ] 
    [ , [ @password= ] 'password' ] 
    [ , [ @working_directory= ] 'working_directory' ] 
    [ , [ @trusted= ] 'trusted' ] 
    [ , [ @encrypted_password= ] encrypted_password ] 
    [ , [ @thirdparty_flag = ] thirdparty_flag ]
    [ , [ @publisher_type = ] 'publisher_type' ]

引數

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

  • [ @distribution_db=] 'distribution_db'
    這是散發資料庫的名稱。 distributor_dbsysname,沒有預設值。 複寫代理程式利用這個參數來連接發行者。

  • [ @security_mode=] security_mode
    這是實作的安全性模式。 此參數只供複寫代理程式用來連接佇列更新訂閱的發行者,或連接非 SQL Server 發行者。 security_modeint,而且可以是下列其中一個值。

    說明

    0

    散發者的複寫代理程式利用 SQL Server 驗證來連接到發行者。

    1 (預設值)

    散發者的複寫代理程式利用 Windows 驗證來連接到發行者。

  • [ @login=] 'login'
    這是登入。 如果 security_mode0,則此參數是必要的。 loginsysname,預設值是 NULL。 複寫代理程式利用這個參數來連接發行者。

  • [ @password=] 'password']
    這是密碼。 passwordsysname,預設值是 NULL。 複寫代理程式利用這個參數來連接發行者。

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

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

  • [ @working_directory=] 'working_directory'
    這是用來儲存發行集資料和結構描述檔案的工作目錄名稱。 working_directorynvarchar(255),這個 SQL Server 執行個體的預設值是 ReplData 資料夾,例如,'C:\Program Files\Microsoft SQL Server\MSSQL\MSSQ.1\ReplData'。 這個名稱應該用 UNC 格式來指定。

  • [ @trusted=] 'trusted'
    這個參數已被取代,而且僅供回溯相容性之用。 trustednvarchar(5),將它設為 false 以外的任何項目都會產生錯誤。

  • [ @encrypted_password=] encrypted_password
    已不再支援設定 encrypted_password。 嘗試將這個 bit 參數設為 1 會產生錯誤。

  • [ @thirdparty_flag =] thirdparty_flag
    這是指發行者是 SQL Server 的情況。 thirdparty_flagbit,它可以是下列其中一個值。

    說明

    0 (預設值)

    SQL Server 資料庫。

    1

    SQL Server 以外的資料庫。

  • [ @publisher_type= ] 'publisher_type'
    指定當發行者不是 SQL Server 時的發行者類型。 publisher_type 是 sysname,而且可以是下列其中一個值。

    說明

    MSSQLSERVER 

    (預設值)

    指定 SQL Server 發行者。

    ORACLE

    指定標準 Oracle 發行者。

    ORACLE GATEWAY

    指定 Oracle Gateway 發行者。

    如需有關 Oracle 發行者和 Oracle Gateway 發行者之差異的詳細資訊,請參閱<設定 Oracle 發行者>。

傳回碼值

0 (成功) 或 1 (失敗)

備註

sp_adddistpublisher 供快照式複寫、異動複寫和合併式複寫使用。

範例

-- 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".

-- Install the Distributor and the distribution database.
DECLARE @distributor AS sysname;
DECLARE @distributionDB AS sysname;
DECLARE @publisher AS sysname;
DECLARE @directory AS nvarchar(500);
DECLARE @publicationDB AS sysname;
-- Specify the Distributor name.
SET @distributor = $(DistPubServer);
-- Specify the distribution database.
SET @distributionDB = N'distribution';
-- Specify the Publisher name.
SET @publisher = $(DistPubServer);
-- Specify the replication working directory.
SET @directory = N'\\' + $(DistPubServer) + '\repldata';
-- Specify the publication database.
SET @publicationDB = N'AdventureWorks2012'; 

-- Install the server MYDISTPUB as a Distributor using the defaults,
-- including autogenerating the distributor password.
USE master
EXEC sp_adddistributor @distributor = @distributor;

-- Create a new distribution database using the defaults, including
-- using Windows Authentication.
USE master
EXEC sp_adddistributiondb @database = @distributionDB, 
    @security_mode = 1;
GO

-- Create a Publisher and enable AdventureWorks2012 for replication.
-- Add MYDISTPUB as a publisher with MYDISTPUB as a local distributor
-- and use Windows Authentication.
DECLARE @distributionDB AS sysname;
DECLARE @publisher AS sysname;
-- Specify the distribution database.
SET @distributionDB = N'distribution';
-- Specify the Publisher name.
SET @publisher = $(DistPubServer);

USE [distribution]
EXEC sp_adddistpublisher @publisher=@publisher, 
    @distribution_db=@distributionDB, 
    @security_mode = 1;
GO 

權限

只有系統管理員 (sysadmin) 固定伺服器角色的成員,才能夠執行 sp_adddistpublisher

請參閱

參考

sp_changedistpublisher (Transact-SQL)

sp_dropdistpublisher (Transact-SQL)

sp_helpdistpublisher (Transact-SQL)

系統預存程序 (Transact-SQL)

概念

設定發行和散發

設定散發