このトピックでは、SQL Server Management Studio、Transact-SQL、またはレプリケーション管理オブジェクト (RMO) を使用して、SQL Server 2014 のパブリケーション プロパティを表示および変更する方法について説明します。
このトピックについて
作業を開始する準備:
パブリケーションのプロパティを表示および変更するには、次を使用します。
開始する前に
制限事項と制約条件
- パブリケーションの作成後に変更できないプロパティや、パブリケーションのサブスクリプションがある場合は変更できないプロパティがあります。 変更できないプロパティは、読み取り専用として表示されます。
推奨事項
- パブリケーションを作成した後、一部のプロパティの変更には新しいスナップショットが必要になります。 パブリケーションにサブスクリプションがある場合、一部の変更では、すべてのサブスクリプションを再初期化する必要もあります。 詳細については、「 パブリケーションとアーティクルのプロパティの変更 」および「 既存のパブリケーションにアーティクルを追加および削除する」を参照してください。
SQL Server Management Studio の使用
SQL Server Management Studio とレプリケーション モニターで使用できる [ パブリケーションのプロパティ - <Publication> ] ダイアログ ボックスでパブリケーションのプロパティを表示および変更します。 レプリケーション モニターの起動については、「レプリケーション モニターの起動」を参照してください。
[ パブリケーションのプロパティ - <発行> ] ダイアログ ボックスには、次のページがあります。
[ 全般] ページには、パブリケーション名と説明、データベース名、パブリケーションの種類、サブスクリプションの有効期限の設定が含まれます。
[ アーティクル] ページは、パブリケーションの新規作成ウィザードの [ アーティクル ] ページに対応します。 このページを使用して、アーティクルを追加および削除したり、アーティクルのプロパティと列のフィルター処理を変更したりできます。
[ 行のフィルター] ページは、パブリケーションの新規作成ウィザードの [ テーブル行のフィルター] ページに対応します。 このページを使用して、すべての種類のパブリケーションの静的行フィルターを追加、編集、削除したり、パラメーター化された行フィルターとマージ パブリケーションの結合フィルターを追加、編集、削除したりできます。
[ スナップショット] ページでは、スナップショットの形式と場所、スナップショットを圧縮するかどうか、スナップショットを適用する前と後に実行するスクリプトを指定できます。
FTP スナップショット ページ (スナップショット パブリケーションとトランザクション パブリケーションの場合、および SQL Server 2005 より前のバージョンを実行しているパブリッシャーのマージ パブリケーション) では、サブスクライバーがファイル転送プロトコル (FTP) を使用してスナップショット ファイルをダウンロードできるかどうかを指定できます。
[FTP スナップショットとインターネット] ページ (SQL Server 2005 以降を実行しているパブリッシャーからのマージ パブリケーションの場合) では、サブスクライバーが FTP 経由でスナップショット ファイルをダウンロードできるかどうか、およびサブスクライバーが HTTPS 経由でサブスクリプションを同期できるかどうかを指定できます。
[ サブスクリプション オプション] ページでは、すべてのサブスクリプションに適用されるオプションを多数設定できます。 オプションは、パブリケーションの種類によって異なります。
[ パブリケーション アクセス リスト] ページでは、パブリケーションにアクセスできるログインとグループを指定できます。
[エージェントのセキュリティ] ページでは、次のエージェントを実行するアカウントの設定にアクセスし、レプリケーション トポロジ内のコンピューター (すべてのパブリケーションのスナップショット エージェント) に接続できます。すべてのトランザクション パブリケーションのログ リーダー エージェント。キュー更新サブスクリプションを許可するトランザクション パブリケーション用のキュー リーダー エージェント。
[ データ パーティション] ページ (SQL Server 2005 以降を実行しているパブリッシャーからのマージ パブリケーションの場合) では、パラメーター化されたフィルターを持つパブリケーションのサブスクライバーがスナップショットを要求できるかどうかを指定できます (使用できない場合)。 また、1 回または定期的なスケジュールで、1 つ以上のパーティションのスナップショットを生成することもできます。
Management Studio でパブリケーションのプロパティを表示および変更するには
Management Studio でパブリッシャーに接続し、サーバー ノードを展開します。
[レプリケーション] フォルダーを展開し、[ローカル パブリケーション] フォルダーを展開します。
文書を右クリックし、[ プロパティ] をクリックします。
必要に応じてプロパティを変更し、[ OK] をクリックします。
レプリケーション モニターでパブリケーションのプロパティを表示および変更するには
レプリケーション モニターの左側のウィンドウでパブリッシャー グループを展開し、パブリッシャーを展開します。
文書を右クリックし、[ プロパティ] をクリックします。
必要に応じてプロパティを変更し、[ OK] をクリックします。
Transact-SQL の使用
パブリケーションは、レプリケーション ストアド プロシージャを使用してプログラムで変更し、そのプロパティを返すことができます。 使用するストアド プロシージャは、パブリケーションの種類によって異なります。
スナップショットまたはトランザクションパブリケーションのプロパティを表示するには
- @publication パラメーターのパブリケーションの名前を指定して、sp_helppublicationを実行します。 このパラメーターを指定しない場合は、パブリッシャーのすべてのパブリケーションに関する情報が返されます。
スナップショット パブリケーションまたはトランザクション パブリケーションのプロパティを変更するには
sp_changepublicationを実行し、変更するパブリケーション プロパティを@propertyパラメーターで指定し、このプロパティの新しい値を@valueパラメーターに入力します。
注
変更で新しいスナップショットの生成が必要になる場合は、@force_invalidate_snapshotに値 1 も指定する必要があります。また、変更でサブスクライバーを再初期化する必要がある場合は、@force_reinit_subscriptionに値 1 を指定する必要があります。 変更時に新しいスナップショットまたは再初期化が必要なプロパティの詳細については、「 パブリケーションとアーティクルのプロパティの変更」を参照してください。
マージ パブリケーションのプロパティを表示するには
- @publication パラメーターのパブリケーションの名前を指定して、sp_helpmergepublicationを実行します。 このパラメーターを指定しない場合は、パブリッシャーのすべてのパブリケーションに関する情報が返されます。
マージ パブリケーションのプロパティを変更するには
sp_changemergepublicationを実行 します。 @property パラメーターで変更するパブリケーション プロパティと、このプロパティの新しい値 を @value パラメーターで指定します。
注
変更で新しいスナップショットの生成が必要になる場合は、@force_invalidate_snapshotに値 1 も指定する必要があります。また、変更でサブスクライバーを再初期化する必要がある場合は、@force_reinit_subscriptionに値 1 を指定する必要があります。変更時に新しいスナップショットまたは再初期化が必要なプロパティの詳細については、 「パブリケーションとアーティクルのプロパティの変更」を参照してください。
スナップショットのプロパティを表示するには
- @publication パラメーターのパブリケーションの名前を指定して、sp_helppublication_snapshotを実行します。
スナップショットのプロパティを変更するには
- 適切なスナップショット パラメーターに対して 1 つ以上の新しいスナップショット プロパティを指定して、 sp_changepublication_snapshotを実行します。
例 (Transact-SQL)
このトランザクション レプリケーションの例では、パブリケーションのプロパティを返します。
DECLARE @myTranPub AS sysname
SET @myTranPub = N'AdvWorksProductTran'
USE [AdventureWorks2012]
EXEC sp_helppublication @publication = @myTranPub
GO
このトランザクション レプリケーションの例では、パブリケーションのスキーマ レプリケーションを無効にします。
DECLARE @publication AS sysname
SET @publication = N'AdvWorksProductTran'
-- Turn off DDL replication for the transactional publication.
USE [AdventureWorks2012]
EXEC sp_changepublication
@publication = @publication,
@property = N'replicate_ddl',
@value = 0
GO
このマージ レプリケーションの例では、パブリケーションのプロパティを返します。
DECLARE @publication AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
USE [AdventureWorks2012]
EXEC sp_helpmergepublication @publication = @publication;
GO
このマージ レプリケーションの例では、パブリケーションのスキーマ レプリケーションを無効にします。
DECLARE @publication AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
-- Disable DDL replication for the publication.
USE [AdventureWorks2012]
EXEC sp_changemergepublication
@publication = @publication,
@property = N'replicate_ddl',
@value = 0,
@force_invalidate_snapshot = 0,
@force_reinit_subscription = 0;
GO
レプリケーション管理オブジェクト (RMO) の使用
レプリケーション管理オブジェクト (RMO) を使用して、パブリケーションを変更し、そのプロパティにプログラムでアクセスできます。 パブリケーションのプロパティを表示または変更するために使用する RMO クラスは、パブリケーションの種類によって異なります。
スナップショット パブリケーションまたはトランザクション パブリケーションのプロパティを表示または変更するには
ServerConnection クラスを使用してパブリッシャーへの接続を作成します。
TransPublication クラスのインスタンスを作成し、パブリケーションのNameプロパティとDatabaseNameプロパティを設定し、ConnectionContext プロパティを手順 1 で作成した接続に設定します。
LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。 このメソッドが
false
を返す場合、手順 2 のパブリケーション プロパティが正しく定義されていないか、パブリケーションが存在しません。(省略可能)プロパティを変更するには、1 つ以上の設定可能なプロパティに新しい値を設定します。 論理 AND 演算子 (Microsoft Visual C# の
&
と Microsoft Visual Basic のAnd
) を使用して、指定された PublicationAttributes 値が Attributes プロパティに設定されているかどうかを判断します。 包括的な論理 OR 演算子 (Visual C# と Visual Basic のOr
で|
) と排他的論理 OR 演算子 (Visual C# では^
、Visual Basic ではXor
) を使用して、Attributes プロパティのPublicationAttributes値を変更します。(省略可能)
true
に CachePropertyChanges の値を指定した場合は、CommitPropertyChanges メソッドを呼び出してサーバー上の変更をコミットします。false
に CachePropertyChanges の値を指定した場合 (既定値)、変更はすぐにサーバーに送信されます。
マージ パブリケーションのプロパティを表示または変更するには
ServerConnection クラスを使用してパブリッシャーへの接続を作成します。
MergePublication クラスのインスタンスを作成し、パブリケーションのNameプロパティとDatabaseNameプロパティを設定し、ConnectionContext プロパティを手順 1 で作成した接続に設定します。
LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。 このメソッドが
false
を返す場合、手順 2 のパブリケーション プロパティが正しく定義されていないか、パブリケーションが存在しません。(省略可能)プロパティを変更するには、1 つ以上の設定可能なプロパティに新しい値を設定します。 論理 AND 演算子 (Visual C# では
&
、Visual Basic ではAnd
) を使用して、指定された PublicationAttributes 値が Attributes プロパティに設定されているかどうかを判断します。 包括的な論理 OR 演算子 (Visual C# と Visual Basic のOr
で|
) と排他的論理 OR 演算子 (Visual C# では^
、Visual Basic ではXor
) を使用して、Attributes プロパティのPublicationAttributes値を変更します。(省略可能)
true
に CachePropertyChanges の値を指定した場合は、CommitPropertyChanges メソッドを呼び出してサーバー上の変更をコミットします。false
に CachePropertyChanges の値を指定した場合 (既定値)、変更はすぐにサーバーに送信されます。
例 (RMO)
次の使用例は、トランザクション パブリケーションのパブリケーション属性を設定します。 変更は、サーバーに明示的に送信されるまでキャッシュされます。
// Define the server, database, and publication names
string publisherName = publisherInstance;
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks2012";
TransPublication publication;
// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
try
{
// Connect to the Publisher.
conn.Connect();
// Set the required properties for the publication.
publication = new TransPublication();
publication.ConnectionContext = conn;
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
// Explicitly enable caching of property changes on this object.
publication.CachePropertyChanges = true;
// If we can't get the properties for this publication,
// throw an application exception.
if (publication.LoadProperties())
{
// Enable support for push subscriptions and disable support
// for pull subscriptions.
if ((publication.Attributes & PublicationAttributes.AllowPull) != 0)
{
publication.Attributes ^= PublicationAttributes.AllowPull;
}
if ((publication.Attributes & PublicationAttributes.AllowPush) == 0)
{
publication.Attributes |= PublicationAttributes.AllowPush;
}
// Send changes to the server.
publication.CommitPropertyChanges();
}
else
{
throw new ApplicationException(String.Format(
"Settings could not be retrieved for the publication. " +
"Ensure that the publication {0} exists on {1}.",
publicationName, publisherName));
}
}
catch (Exception ex)
{
// Do error handling here.
throw new ApplicationException(
"The publication property could not be changed.", ex);
}
finally
{
conn.Disconnect();
}
' Define the server, database, and publication names
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks2012"
Dim publication As TransPublication
' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
Try
' Connect to the Publisher.
conn.Connect()
' Set the required properties for the publication.
publication = New TransPublication()
publication.ConnectionContext = conn
publication.Name = publicationName
publication.DatabaseName = publicationDbName
' Explicitly enable caching of property changes on this object.
publication.CachePropertyChanges = True
' If we can't get the properties for this publication,
' throw an application exception.
If publication.LoadProperties() Then
' Enable support for push subscriptions and disable support
' for pull subscriptions.
If (publication.Attributes And PublicationAttributes.AllowPull) <> 0 Then
publication.Attributes = publication.Attributes _
Xor PublicationAttributes.AllowPull
End If
If (publication.Attributes And PublicationAttributes.AllowPush) = 0 Then
publication.Attributes = publication.Attributes _
Or PublicationAttributes.AllowPush
End If
' Send changes to the server.
publication.CommitPropertyChanges()
Else
Throw New ApplicationException(String.Format( _
"Settings could not be retrieved for the publication. " + _
"Ensure that the publication {0} exists on {1}.", _
publicationName, publisherName))
End If
Catch ex As Exception
' Do error handling here.
Throw New ApplicationException( _
"The publication property could not be changed.", ex)
Finally
conn.Disconnect()
End Try
次の使用例は、マージ パブリケーションの DDL レプリケーションを無効にします。
// Define the server, database, and publication names
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks2012";
MergePublication publication;
// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
try
{
// Connect to the Publisher.
conn.Connect();
// Set the required properties for the publication.
publication = new MergePublication();
publication.ConnectionContext = conn;
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
// If we can't get the properties for this merge publication, then throw an application exception.
if (publication.LoadProperties())
{
// If DDL replication is currently enabled, disable it.
if (publication.ReplicateDdl == DdlReplicationOptions.All)
{
publication.ReplicateDdl = DdlReplicationOptions.None;
}
else
{
publication.ReplicateDdl = DdlReplicationOptions.All;
}
}
else
{
throw new ApplicationException(String.Format(
"Settings could not be retrieved for the publication. " +
"Ensure that the publication {0} exists on {1}.",
publicationName, publisherName));
}
}
catch (Exception ex)
{
// Do error handling here.
throw new ApplicationException(
"The publication property could not be changed.", ex);
}
finally
{
conn.Disconnect();
}
' Define the server, database, and publication names
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2012"
Dim publication As MergePublication
' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
Try
' Connect to the Publisher.
conn.Connect()
' Set the required properties for the publication.
publication = New MergePublication()
publication.ConnectionContext = conn
publication.Name = publicationName
publication.DatabaseName = publicationDbName
' If we can't get the properties for this merge publication, then throw an application exception.
If publication.LoadProperties() Then
' If DDL replication is currently enabled, disable it.
If publication.ReplicateDdl = DdlReplicationOptions.All Then
publication.ReplicateDdl = DdlReplicationOptions.None
Else
publication.ReplicateDdl = DdlReplicationOptions.All
End If
Else
Throw New ApplicationException(String.Format( _
"Settings could not be retrieved for the publication. " + _
"Ensure that the publication {0} exists on {1}.", _
publicationName, publisherName))
End If
Catch ex As Exception
' Do error handling here.
Throw New ApplicationException( _
"The publication property could not be changed.", ex)
Finally
conn.Disconnect()
End Try
こちらもご覧ください
データ オブジェクトとデータベース オブジェクトをパブリッシュする
パブリケーションとアーティクルのプロパティを変更する
パブリケーション データベースでのスキーマの変更
レプリケーション システム ストアド プロシージャの概念
パブリケーションに記事を追加または削除する
レプリケーション モニターを使用した情報の表示とタスクの実行
アーティクルのプロパティの表示と変更