sp_adddistpublisher (Transact-SQL)

適用於:SQL ServerAzure SQL 受控執行個體

設定發行者使用指定的散發資料庫。 此預存程式會在任何資料庫的散發者端執行。 預存程式 sp_adddistributor (Transact-SQL)sp_adddistributiondb (Transact-SQL) 必須先執行,才能使用此預存程式。

Transact-SQL 語法慣例

語法

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

引數

[ @publisher = ] N'publisher'

發行者名稱。 @publisher為 sysname,沒有預設值。

注意

伺服器名稱可以指定為 <Hostname>,<PortNumber>。 使用自定義埠在Linux或 Windows 上部署 SQL Server,並停用瀏覽器服務時,請指定連線的埠號碼。 遠端散發者的自定義埠號碼使用適用於 SQL Server 2019 (15.x) 和更新版本。

[ @distribution_db = ] N'distribution_db'

散發資料庫的名稱。 @distribution_db為 sysname,沒有預設值。 復寫代理程式會使用此參數來連線到發行者。

[ @security_mode = ] security_mode

實作的安全性模式。 只有復寫代理程式會使用此參數來連線到發行者以進行佇列更新訂閱,或是使用非 SQL Server 發行者。 @security_mode為 int,而且可以是下列其中一個值。

Description
0 散發者端的復寫代理程式會使用 SQL Server 驗證來連線到發行者。
1 (預設值) 散發者端的復寫代理程式會使用 Windows 驗證來連線到發行者。

[ @login = ] N'login'

登入。 如果 security_mode0,則需要此參數。 @login為 sysname,預設值為 NULL。 復寫代理程式會使用此參數來連線到發行者。

[ @password = ] N'password'

密碼。 @password為 sysname,預設值為 NULL。 復寫代理程式會使用此參數來連線到發行者。

重要

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

[ @working_directory = ] N'working_directory'

用來儲存發行集數據和架構檔案的工作目錄名稱。 @working_directory為 nvarchar(255),預設為ReplData這個 SQL Server 實例的資料夾。 例如: C:\Program Files\Microsoft SQL Server\MSSQL\MSSQL.1\ReplData 。 名稱應以 UNC 格式指定。

針對 Azure SQL 資料庫,請使用 \\<storage_account>.file.core.windows.net\<share>

[ @trusted = ] N'trusted'

@trusted已被取代,而且僅供回溯兼容性使用。 @trusted為 nvarchar(5),預設值為 false。 將此參數設定為任何專案,但 false 會產生錯誤。

[ @encrypted_password = ] encrypted_password

不再支援設定此參數。 @encrypted_password為 bit,預設值為 0。 將此參數設定為 1 會導致錯誤。

[ @thirdparty_flag = ] thirdparty_flag

指定發行者為 SQL Server 的時機。 @thirdparty_flag為,而且可以是下列其中一個值。

Description
0 (預設值) SQL Server 資料庫。
1 SQL Server 以外的資料庫。

[ @publisher_type = ] N'publisher_type'

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

Description
MSSQLSERVER (預設值) 指定 SQL Server 發行者。
ORACLE 指定標準 Oracle 發行者。
ORACLE GATEWAY 指定 Oracle 閘道發行者。

如需 Oracle 發行者與 Oracle 閘道發行者之間差異的詳細資訊,請參閱 設定 Oracle 發行者

[ @storage_connection_string = ] N'storage_connection_string'

Azure SQL 資料庫 的必要專案。 @storage_connection_string為 nvarchar(255),預設值為 NULL。 在 儲存體 設定 底下>,使用來自 Azure 入口網站 的存取金鑰。

注意

Azure SQL 資料庫 上的發行者和散發者資料庫需要 SQL 受管理執行個體。 如需詳細資訊,請參閱使用 Azure SQL 資料庫 進行複寫。

傳回碼值

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

-- 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 AdventureWorks2022 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

權限

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