events
3月31日 23時 - 4月2日 23時
最大の SQL、Fabric、Power BI 学習イベント。 3 月 31 日から 4 月 2 日。 コード FABINSIDER を使用して $400 を保存します。
今すぐ登録このブラウザーはサポートされなくなりました。
Microsoft Edge にアップグレードすると、最新の機能、セキュリティ更新プログラム、およびテクニカル サポートを利用できます。
適用対象: SQL Server
Azure SQL Managed Instance
このトピックでは、SQL Server Management Studio、Transact-SQL、またはレプリケーション管理オブジェクト (RMO) を使用して SQL Server のパブリケーション プロパティを表示および変更する方法について説明します。
このトピックの内容
作業を開始する準備:
パブリケーションのプロパティを表示または変更するために使用するもの:
[パブリケーションのプロパティ - <Publication>] ダイアログ ボックスで、パブリケーションのプロパティを表示および変更します。このダイアログ ボックスは、SQL Server Management Studio およびレプリケーション モニターで使用できます。 レプリケーション モニターの起動の詳細については、「Start the Replication Monitor」 (レプリケーション モニターの開始) を参照してください。
[パブリケーションのプロパティ - <Publication>] ダイアログ ボックスには、以下のページがあります。
[全般] ページ。パブリケーションの名前と説明、データベースの名前、パブリケーションの種類、およびサブスクリプションの有効期限の設定が含まれています。
[アーティクル] ページ。パブリケーションの新規作成ウィザードの [アーティクル] ページに相当します。 このページでは、アーティクルの追加や削除、およびアーティクルのプロパティや列のフィルター選択の変更を行うことができます。
[行のフィルター選択] ページ。パブリケーションの新規作成ウィザードの [テーブル行のフィルター選択] ページに相当します。 このページでは、すべての種類のパブリケーションの静的行フィルターや、マージ パブリケーションのパラメーター化された行フィルターと結合フィルターを追加、編集、および削除できます。
[スナップショット] ページ。このページでは、スナップショットの形式と場所、スナップショットを圧縮するかどうか、およびスナップショットの適用の前後に実行するスクリプトを指定できます。
[FTP スナップショット] ページ (スナップショット パブリケーション、トランザクション パブリケーション、および SQL Server 2005 より前のバージョンを実行しているパブリッシャーのマージ パブリケーションの場合)。このページでは、サブスクライバーがスナップショット ファイルをファイル転送プロトコル (FTP) でダウンロードできるかどうかを指定できます。
[FTP スナップショットとインターネット] ページ (SQL Server 2005 以降を実行しているパブリッシャーからのマージ パブリケーションの場合)。このページでは、サブスクライバーがスナップショット ファイルを FTP でダウンロードできるかどうか、および HTTPS でサブスクリプションを同期できるかどうかを指定できます。
[サブスクリプション オプション] ページ。このページでは、すべてのサブスクリプションに適用されるさまざまなオプションを設定できます。 利用できるオプションは、パブリケーションの種類によって異なります。
[パブリケーション アクセス リスト] ページ。このページでは、パブリケーションにアクセスできるログインやグループを指定できます。
[エージェント セキュリティ] ページ。このページでは、エージェントの実行やレプリケーション トポロジ内のコンピューターへの接続に使用されるアカウントの設定にアクセスできます。この設定を使用するエージェントは、すべてのパブリケーションのスナップショット エージェント、すべてのトランザクション パブリケーションのログ リーダー エージェント、およびキュー更新サブスクリプションを許可するトランザクション パブリケーションのキュー リーダー エージェントです。
[データ パーティション] ページ (SQL Server 2005 以降を実行しているパブリッシャーからのマージ パブリケーションの場合)。このページでは、パラメーター化されたフィルターを使用するパブリケーションのサブスクライバーが、スナップショットを利用できない場合にスナップショットを要求できるかどうかを指定できます。 また、1 つ以上のパーティションのスナップショットを 1 回生成したり、スケジュールによって定期的に生成したりすることもできます。
Management Studio でパブリッシャーに接続し、サーバー ノードを展開します。
[レプリケーション] フォルダーを展開し、 [ローカル パブリケーション] フォルダーを展開します。
パブリケーションを右クリックし、 [プロパティ]をクリックします。
必要に応じてプロパティを変更し、 [OK]をクリックします。
レプリケーション モニターの左ペインでパブリッシャー グループを展開し、パブリッシャーを展開します。
パブリケーションを右クリックし、 [プロパティ]をクリックします。
必要に応じてプロパティを変更し、 [OK]をクリックします。
パブリケーションのプロパティは、レプリケーションのストアド プロシージャを使用して、プログラムから変更および取得できます。 どのストアド プロシージャを使用するかは、パブリケーションの種類によって異なります。
sp_changepublicationを実行します。このとき、変更するパブリケーションのプロパティを @property パラメーターに指定し、このプロパティの新しい値を @value パラメーターに指定します。
注意
さらに、新しいスナップショットを生成する必要がある場合は、 @force_invalidate_snapshot に 1を、また、サブスクライバーを再初期化する必要がある場合は、 @force_reinit_subscription に 1を指定します。 変更時に新しいスナップショットの生成または再初期化が必要となるプロパティの詳細については、「Change Publication and Article Properties」(パブリケーションとアーティクルのプロパティの変更) を参照してください。
sp_changemergepublicationを実行します。このとき、変更するパブリケーションのプロパティを @property パラメーターに指定し、このプロパティの新しい値を @value パラメーターに指定します。
注意
変更する際に新しいスナップショットの生成が必要になる場合は、@force_invalidate_snapshot の値に 1 を、同様に、サブスクライバーの再初期化が必要になる場合は、@force_reinit_subscription の値に 1 を指定します。変更時に新しいスナップショットの生成または再初期化が必要となるプロパティの詳細については、「パブリケーションおよびアーティクルのプロパティの変更」を参照してください。
パブリケーションのプロパティを取得するトランザクション レプリケーションの例を、次に示します。
DECLARE @myTranPub AS sysname
SET @myTranPub = N'AdvWorksProductTran'
USE [AdventureWorks2022]
EXEC sp_helppublication @publication = @myTranPub
GO
パブリケーションのスキーマ レプリケーションを無効化するトランザクション レプリケーションの例を、次に示します。
DECLARE @publication AS sysname
SET @publication = N'AdvWorksProductTran'
-- Turn off DDL replication for the transactional publication.
USE [AdventureWorks2022]
EXEC sp_changepublication
@publication = @publication,
@property = N'replicate_ddl',
@value = 0
GO
パブリケーションのプロパティを取得するマージ レプリケーションの例を、次に示します。
DECLARE @publication AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
USE [AdventureWorks2022]
EXEC sp_helpmergepublication @publication = @publication;
GO
パブリケーションのスキーマ レプリケーションを無効化するマージ レプリケーションの例を、次に示します。
DECLARE @publication AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
-- Disable DDL replication for the publication.
USE [AdventureWorks2022]
EXEC sp_changemergepublication
@publication = @publication,
@property = N'replicate_ddl',
@value = 0,
@force_invalidate_snapshot = 0,
@force_reinit_subscription = 0;
GO
レプリケーション管理オブジェクト (RMO) を使用して、パブリケーションの変更とそのプロパティへのアクセスをプログラムから実行できます。 パブリケーション プロパティの表示と変更に使用する RMO クラスは、パブリケーションの種類によって異なります。
ServerConnection クラスを使用して、パブリッシャーへの接続を作成します。
TransPublication クラスのインスタンスを作成し、パブリケーションの Name プロパティと DatabaseName プロパティを設定して、手順 1. で作成した接続を ConnectionContext プロパティに設定します。
LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。 このメソッドが falseを返す場合、手順 2. でパブリケーション プロパティを不適切に設定したか、パブリケーションが存在していません。
(省略可) プロパティを変更するには、設定可能なプロパティに新しい値を設定します。 PublicationAttributes プロパティに特定の Attributes 値が設定されているかどうかを判断するには、論理積演算子 (Microsoft Visual C# では &、Microsoft Visual Basic では And) を使用します。 Attributes プロパティの PublicationAttributes 値を変更するには、包括的論理和演算子 (Visual C# では |、Visual Basic では Or) および排他的論理和演算子 (Visual C# では ^、Visual Basic では Xor) を使用します。
(省略可) P:Microsoft.SqlServer.Replication.ReplicationObject.CachePropertyChanges に CachePropertyChangesを指定した場合、 CommitPropertyChanges メソッドを呼び出してサーバーに変更をコミットします。 CachePropertyChanges に値 false (既定値) を指定した場合、変更は直ちにサーバーに送られます。
ServerConnection クラスを使用して、パブリッシャーへの接続を作成します。
MergePublication クラスのインスタンスを作成し、パブリケーションの Name プロパティと DatabaseName プロパティを設定して、手順 1. で作成した接続を ConnectionContext プロパティに設定します。
LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。 このメソッドが falseを返す場合、手順 2. でパブリケーション プロパティを不適切に設定したか、パブリケーションが存在していません。
(省略可) プロパティを変更するには、設定可能なプロパティに新しい値を設定します。 PublicationAttributes プロパティに特定の Attributes 値が設定されているかどうかを判断するには、論理積演算子 (Visual C# では &、Visual Basic では And) を使用します。 Attributes プロパティの PublicationAttributes 値を変更するには、包括的論理和演算子 (Visual C# では |、Visual Basic では Or) および排他的論理和演算子 (Visual C# では ^、Visual Basic では Xor) を使用します。
(省略可) P:Microsoft.SqlServer.Replication.ReplicationObject.CachePropertyChanges に CachePropertyChangesを指定した場合、 CommitPropertyChanges メソッドを呼び出してサーバーに変更をコミットします。 CachePropertyChanges に値 false (既定値) を指定した場合、変更は直ちにサーバーに送られます。
次の例では、トランザクション パブリケーションにパブリケーション属性を設定します。 変更は明示的にサーバーに送られるまでキャッシュされます。
// Define the server, database, and publication names
string publisherName = publisherInstance;
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks2022";
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 = "AdventureWorks2022"
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 = "AdventureWorks2022";
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 = "AdventureWorks2022"
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
events
3月31日 23時 - 4月2日 23時
最大の SQL、Fabric、Power BI 学習イベント。 3 月 31 日から 4 月 2 日。 コード FABINSIDER を使用して $400 を保存します。
今すぐ登録