このトピックでは、SQL Server 2012 で SQL Server Management Studio、Transact-SQL、またはレプリケーション管理オブジェクト (RMO) を使用して、ディストリビューターとパブリッシャーのプロパティを表示および変更する方法について説明します。
このトピックの内容
作業を開始する準備:
推奨事項
セキュリティ
ディストリビューターとパブリッシャーのプロパティを表示または変更するために使用するもの:
SQL Server Management Studio
Transact-SQL
レプリケーション管理オブジェクト (RMO)
作業を開始する準備
推奨事項
- Microsoft SQL Server 2005 より前のバージョンのパブリッシャーでは、固定サーバー ロール sysadmin のユーザーが、[サブスクライバー] ページでサブスクライバーを登録できます。 SQL Server 2005 以降では、サブスクライバーをレプリケーションに明示的に登録する必要はありません。
セキュリティ
可能ならば、実行時にセキュリティ資格情報の入力を求めるメッセージをユーザーに対して表示します。
[Top]
SQL Server Management Studio の使用
ディストリビューターのプロパティを表示および変更するには
SQL Server Management Studio でディストリビューターに接続して、サーバー ノードを展開します。
[レプリケーション] フォルダーを右クリックし、[ディストリビューターのプロパティ] をクリックします。
[ディストリビューターのプロパティ - <Distributor>] ダイアログ ボックスで、プロパティを表示および変更します。
ディストリビューション データベースのプロパティを表示および変更するには、ダイアログ ボックスの [全般] ページのデータベースのプロパティ ボタン ([...]) をクリックします。
ディストリビューターと関連付けられたパブリッシャーのプロパティを表示および変更するには、ダイアログ ボックスの [パブリッシャー] ページでパブリッシャーのプロパティ ボタン ([...]) をクリックします。
レプリケーション エージェントのプロファイルにアクセスするには、ダイアログ ボックスの [全般] ページの [プロファイルの既定値] をクリックします。 詳細については、「レプリケーション エージェント プロファイル」を参照してください。
パブリッシャーで管理用のストアド プロシージャを実行したり、ディストリビューターで情報を更新したりするときに使用するアカウントのパスワードを変更するには、ダイアログ ボックスの [パブリッシャー] ページで [パスワード] ボックスおよび [パスワードの確認入力] ボックスに新しいパスワードを入力します。 詳細については、「ディストリビューターのセキュリティ保護」を参照してください。
必要に応じてプロパティを変更し、[OK] をクリックします。
パブリッシャーのプロパティを表示および変更するには
SQL Server Management Studio でパブリッシャーに接続し、サーバー ノードを展開します。
[レプリケーション] フォルダーを右クリックし、[パブリッシャーのプロパティ] をクリックします。
[パブリッシャーのプロパティ - < Publisher >] ダイアログ ボックスで、パブリッシャーのプロパティを表示および変更します。
- 固定サーバー ロール sysadmin のユーザーは、[パブリケーション データベース] のページでデータベースのレプリケーションを有効化できます。 データベースを有効化しても、そのデータベースがパブリッシュされるわけではありません。固定データベース ロール db_owner の任意のユーザーが、1 つ以上のパブリケーションをデータベースに作成できるようになります。
必要に応じてプロパティを変更し、[OK] をクリックします。
[Top]
Transact-SQL の使用
パブリッシャーとディストリビューターのプロパティは、プログラムからレプリケーション ストアド プロシージャを使用して表示できます。
ディストリビューターとディストリビューション データベースのプロパティを表示するには
sp_helpdistributor を実行すると、ディストリビューター、ディストリビューション データベース、作業ディレクトリに関する情報が返されます。
sp_helpdistributiondb を実行すると、指定されたディストリビューション データベースのプロパティが返されます。
ディストリビューターとディストリビューション データベースのプロパティを変更するには
ディストリビューターのプロパティを変更するには、ディストリビューターで sp_changedistributor_property を実行します。
ディストリビューション データベースのプロパティを変更するには、ディストリビューターで sp_changedistributiondb を実行します。
ディストリビューターのパスワードを変更するには、ディストリビューターで sp_changedistributor_password を実行します。
セキュリティに関する注意可能ならば、実行時にセキュリティ資格情報の入力を求めるメッセージをユーザーに対して表示します。 資格情報をスクリプト ファイルに含める必要がある場合は、不正なアクセスが行われないようにファイルをセキュリティで保護してください。
ディストリビューターを使用しているパブリッシャーのプロパティを変更するには、ディストリビューターで sp_changedistpublisher を実行します。
例 (Transact-SQL)
次の例では、Transact-SQL スクリプトによってディストリビューターおよびディストリビューション データベースに関する情報を返します。
-- View information about the Distributor, distribution database,
-- working directory, and SQL Server Agent user account.
USE master
EXEC sp_helpdistributor;
GO
-- View information about the specified distribution database.
USE distribution
EXEC sp_helpdistributiondb;
GO
次の例では、ディストリビューターの保有期間、ディストリビューターへの接続時に使用されるパスワード、およびディストリビューターが各種レプリケーション エージェントの状態を確認する間隔 (ハートビート間隔) を変更します。
セキュリティに関する注意 |
|---|
可能ならば、実行時にセキュリティ資格情報の入力を求めるメッセージをユーザーに対して表示します。 資格情報をスクリプト ファイルに含める必要がある場合は、不正なアクセスが行われないようにファイルをセキュリティで保護してください。 |
-- Change the heartbeat interval at the Distributor to 5 minutes.
USE master
exec sp_changedistributor_property
@property = N'heartbeat_interval',
@value = 5;
GO
DECLARE @distributionDB AS sysname;
SET @distributionDB = N'distribution';
-- Change the history retention period to 24 hours and the
-- maximum retention period to 48 hours.
USE distribution
EXEC sp_changedistributiondb @distributionDB, N'history_retention', 24
EXEC sp_changedistributiondb @distributionDB, N'max_distretention', 48
GO
-- Change the password on the Distributor.
-- To avoid storing the password in the script file, the value is passed
-- into SQLCMD as a scripting variable. 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".
USE master
EXEC sp_changedistributor_password $(Password)
GO
[Top]
レプリケーション管理オブジェクト (RMO) の使用
ディストリビューターのプロパティを表示および変更するには
ServerConnection クラスを使用して、ディストリビューターへの接続を作成します。
ReplicationServer クラスのインスタンスを作成します。 手順 1. の ServerConnection を渡します。
(省略可) IsDistributor プロパティをチェックして、現在接続されているサーバーがディストリビューターであることを確認します。
Load メソッドを呼び出して、サーバーからプロパティを取得します。
(省略可) プロパティを変更するには、ReplicationServer オブジェクトの設定可能なディストリビューター プロパティに新しい値を設定します。
(省略可) ReplicationServer オブジェクトの CachePropertyChanges プロパティが true に設定されている場合は、CommitPropertyChanges メソッドを呼び出して変更内容をサーバーにコミットします。
ディストリビューション データベースのプロパティを表示および変更するには
ServerConnection クラスを使用して、ディストリビューターへの接続を作成します。
DistributionDatabase クラスのインスタンスを作成します。 name プロパティを指定し、手順 1. の ServerConnection オブジェクトを渡します。
LoadProperties メソッドを呼び出して、サーバーからプロパティを取得します。 このメソッドから false が返された場合、指定した名前のデータベースはサーバー上に存在しません。
(省略可) プロパティを変更するには、DistributionDatabase の設定可能なプロパティに新しい値を設定します。
(省略可) DistributionDatabase オブジェクトの CachePropertyChanges プロパティが true に設定されている場合は、CommitPropertyChanges メソッドを呼び出して変更内容をサーバーにコミットします。
パブリッシャーのプロパティを表示および変更するには
ServerConnection クラスを使用して、パブリッシャーへの接続を作成します。
DistributionPublisher クラスのインスタンスを作成します。 Name プロパティを指定し、手順 1. の ServerConnection オブジェクトを渡します。
(省略可) プロパティを変更するには、DistributionPublisher の設定可能なプロパティに新しい値を設定します。
(省略可) DistributionPublisher オブジェクトの CachePropertyChanges プロパティが true に設定されている場合は、CommitPropertyChanges メソッドを呼び出して変更内容をサーバーにコミットします。
パブリッシャーからディストリビューターへの管理接続に使用されているパスワードを変更するには
ServerConnection クラスを使用して、ディストリビューターへの接続を作成します。
ReplicationServer クラスのインスタンスを作成します。
ConnectionContext プロパティに、手順 1. の接続を設定します。
Load メソッドを呼び出して、オブジェクトのプロパティを取得します。
ChangeDistributorPassword メソッドを呼び出します。 新しいパスワード値を password パラメーターに渡します。
セキュリティに関する注意可能であれば、実行時にセキュリティ資格情報の入力を求めるメッセージを表示します。 資格情報を保存する必要がある場合は、Microsoft Windows .NET Framework に用意されている暗号化サービスを使用します。
(省略可) このディストリビューターを使用している各リモート パブリッシャーでパスワードを変更するには、次の手順に従います。
ServerConnection クラスを使用して、パブリッシャーへの接続を作成します。
ReplicationServer クラスのインスタンスを作成します。
ConnectionContext プロパティに、手順 6a. で作成した接続を設定します。
Load メソッドを呼び出して、オブジェクトのプロパティを取得します。
ChangeDistributorPassword メソッドを呼び出します。 手順 5. の新しいパスワード値を password パラメーターに渡します。
例 (RMO)
次の例に、ディストリビューションのプロパティおよびディストリビューション データベースのプロパティを変更する方法を示します。
セキュリティに関する注意 |
|---|
資格情報をコードに記述するのを避けるため、新しいディストリビューター パスワードは実行時に指定するようにしています。 |
// Set the Distributor and distribution database names.
string distributionDbName = "distribution";
string distributorName = publisherInstance;
ReplicationServer distributor;
DistributionDatabase distributionDb;
// Create a connection to the Distributor using Windows Authentication.
ServerConnection conn = new ServerConnection(distributorName);
try
{
// Open the connection.
conn.Connect();
distributor = new ReplicationServer(conn);
// Load Distributor properties, if it is installed.
if (distributor.LoadProperties())
{
// Password supplied at runtime.
distributor.ChangeDistributorPassword(password);
distributor.AgentCheckupInterval = 5;
// Save changes to the Distributor properties.
distributor.CommitPropertyChanges();
}
else
{
throw new ApplicationException(
String.Format("{0} is not a Distributor.", publisherInstance));
}
// Create an object for the distribution database
// using the open Distributor connection.
distributionDb = new DistributionDatabase(distributionDbName, conn);
// Change distribution database properties.
if (distributionDb.LoadProperties())
{
// Change maximum retention period to 48 hours and history retention
// period to 24 hours.
distributionDb.MaxDistributionRetention = 48;
distributionDb.HistoryRetention = 24;
// Save changes to the distribution database properties.
distributionDb.CommitPropertyChanges();
}
else
{
// Do something here if the distribution database does not exist.
}
}
catch (Exception ex)
{
// Implement the appropriate error handling here.
throw new ApplicationException("An error occured when changing Distributor " +
" or distribution database properties.", ex);
}
finally
{
conn.Disconnect();
}
' Set the Distributor and distribution database names.
Dim distributionDbName As String = "distribution"
Dim distributorName As String = publisherInstance
Dim distributor As ReplicationServer
Dim distributionDb As DistributionDatabase
' Create a connection to the Distributor using Windows Authentication.
Dim conn As ServerConnection = New ServerConnection(distributorName)
Try
' Open the connection.
conn.Connect()
distributor = New ReplicationServer(conn)
' Load Distributor properties, if it is installed.
If distributor.LoadProperties() Then
' Password supplied at runtime.
distributor.ChangeDistributorPassword(password)
distributor.AgentCheckupInterval = 5
' Save changes to the Distributor properties.
distributor.CommitPropertyChanges()
Else
Throw New ApplicationException( _
String.Format("{0} is not a Distributor.", publisherInstance))
End If
' Create an object for the distribution database
' using the open Distributor connection.
distributionDb = New DistributionDatabase(distributionDbName, conn)
' Change distribution database properties.
If distributionDb.LoadProperties() Then
' Change maximum retention period to 48 hours and history retention
' period to 24 hours.
distributionDb.MaxDistributionRetention = 48
distributionDb.HistoryRetention = 24
' Save changes to the distribution database properties.
distributionDb.CommitPropertyChanges()
Else
' Do something here if the distribution database does not exist.
End If
Catch ex As Exception
' Implement the appropriate error handling here.
Throw New ApplicationException("An error occured when changing Distributor " + _
" or distribution database properties.", ex)
Finally
conn.Disconnect()
End Try
[Top]
関連項目
タスク
パブリッシャーの情報を表示し、タスクを実行する (レプリケーション モニター)