sp_adddistpublisher (Transact-SQL)
適用対象: SQL Server Azure SQL Managed Instance
指定されたディストリビューション データベースを使用するように、パブリッシャーを構成します。 このストアド プロシージャは、任意のデータベースのディストリビューターで実行されます。 ストアド プロシージャ sp_adddistributor (Transact-SQL) と sp_adddistributiondb (Transact-SQL) は、このストアド プロシージャを使用する前に実行されている必要があります。
構文
sp_adddistpublisher [ @publisher= ] 'publisher'
, [ @distribution_db= ] 'distribution_db'
[ , [ @security_mode= ] security_mode ]
[ , [ @login= ] 'login' ]
[ , [ @password= ] 'password' ]
[ , [ @working_directory= ] 'working_directory' ]
[ , [ @storage_connection_string= ] 'storage_connection_string']
[ , [ @trusted= ] 'trusted' ]
[ , [ @encrypted_password= ] encrypted_password ]
[ , [ @thirdparty_flag = ] thirdparty_flag ]
[ , [ @publisher_type = ] 'publisher_type' ]
引数
[ @publisher = ] 'publisher'
パブリッシャー名を指定します。 publisher は sysname で、既定値はありません。
注意
サーバー名は として <Hostname>,<PortNumber>
指定できます。 SQL Serverがカスタム ポートを使用して Linux または Windows にデプロイされ、ブラウザー サービスが無効になっている場合は、接続のポート番号を指定する必要がある場合があります。 リモート ディストリビューターのカスタム ポート番号の使用は、SQL Server 2019 にのみ適用されます。
[ @distribution_db = ] 'distribution_db'
ディストリビューション データベースの名前です。 distributor_db は sysname で、既定値はありません。 このパラメーターは、レプリケーション エージェントがパブリッシャーに接続するために使用します。
[ @security_mode = ] security_mode
実装されているセキュリティ モードです。 このパラメーターは、レプリケーション エージェントがキューに登録された更新サブスクリプションのパブリッシャーに接続するか、SQL Server以外のパブリッシャーで接続する場合にのみ使用されます。 security_mode は int であり、これらの値のいずれかになります。
値 | 説明 |
---|---|
0 | ディストリビューターのレプリケーション エージェントは、SQL Server認証を使用してパブリッシャーに接続します。 |
1 (既定値) | ディストリビューター側のレプリケーション エージェントは Windows 認証を使用してパブリッシャーに接続します。 |
[ @login = ] 'login'
ログインです。 このパラメーターは、 security_mode が 0 の場合に必要です。 login のデータ型は sysname で、既定値は NULL です。 このパラメーターは、レプリケーション エージェントがパブリッシャーに接続するために使用します。
[ @password = ] 'password']
パスワードです。 password は sysname で、既定値は NULL です。 このパラメーターは、レプリケーション エージェントがパブリッシャーに接続するために使用します。
重要
空白のパスワードは使用しないでください。 強力なパスワードを使用してください。
[ @working_directory = ] 'working_directory'
パブリケーションのデータ ファイルとスキーマ ファイルを格納するために使用される作業ディレクトリの名前です。 working_directoryは nvarchar(255)で、既定値は SQL Server のこのインスタンスの ReplData フォルダーです (例: C:\Program Files\Microsoft SQL Server\MSSQL\MSSQ.1\ReplData
)。 名前は UNC 形式で指定する必要があります。
Azure SQL Database の場合は、 を使用します\\<storage_account>.file.core.windows.net\<share>
。
[ @storage_connection_string = ] 'storage_connection_string'
SQL Databaseに必要です。 ストレージ > 設定で Azure Portal のアクセス キーを使用します。
Azure SQL Database のパブリッシャー データベースとディストリビューター データベースでは、Managed Instanceが必要です。詳細については、「Azure SQL Database を使用したレプリケーション」を参照してください。
[ @trusted = ] 'trusted'
このパラメーターは非推奨であり、下位互換性のためにのみ提供されています。 trusted は nvarchar(5)であり、 false 以外に設定するとエラーが発生します。
[ @encrypted_password = ] encrypted_password
encrypted_passwordの設定はサポートされなくなりました。 この ビット パラメーターを 1 に設定しようとすると、エラーが発生します。
[ @thirdparty_flag = ] thirdparty_flag
パブリッシャーがSQL Serverされたときです。 thirdparty_flag は ビットであり、次のいずれかの値を指定できます。
値 | 説明 |
---|---|
0 (既定値) | データベースSQL Server。 |
1 | SQL Server以外のデータベース。 |
[ @publisher_type = ] 'publisher_type'
パブリッシャーがSQL Serverされていない場合にパブリッシャーの種類を指定します。 publisher_type は sysname で、次のいずれかの値を指定できます。
値 | [説明] |
---|---|
Mssqlserver (既定値)。 |
SQL Serverパブリッシャーを指定します。 |
Oracle | 標準の Oracle パブリッシャーを指定します。 |
ORACLE GATEWAY | Oracle ゲートウェイ パブリッシャーを指定します。 |
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
アクセス許可
sp_adddistpublisherを実行できるのは、sysadmin 固定サーバー ロールのメンバーだけです。
参照
パブリッシングおよびディストリビューションの構成
sp_changedistpublisher (Transact-SQL)
sp_dropdistpublisher (Transact-SQL)
sp_helpdistpublisher (Transact-SQL)
システム ストアド プロシージャ (Transact-SQL)
[ディストリビューションの構成]