パブリケーション プロパティの表示および変更

適用対象: SQL ServerAzure SQL Managed Instance

このトピックでは、SQL Server Management Studio、Transact-SQL、またはレプリケーション管理オブジェクト (RMO) を使用して SQL Server のパブリケーション プロパティを表示および変更する方法について説明します。

このトピックの内容

始める前に

制限事項と制約事項

  • パブリケーションの作成後には変更できないプロパティや、パブリケーションへのサブスクリプションがある場合には変更できないプロパティもあります。 変更できないプロパティは、読み取り専用として表示されます。

推奨事項

SQL Server Management Studio を使用する

[パブリケーションのプロパティ - <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 でパブリケーションのプロパティを表示および変更するには

  1. Management Studio でパブリッシャーに接続し、サーバー ノードを展開します。

  2. [レプリケーション] フォルダーを展開し、 [ローカル パブリケーション] フォルダーを展開します。

  3. パブリケーションを右クリックし、 [プロパティ]をクリックします。

  4. 必要に応じてプロパティを変更し、 [OK]をクリックします。

レプリケーション モニターでパブリケーションのプロパティを表示および変更するには

  1. レプリケーション モニターの左ペインでパブリッシャー グループを展開し、パブリッシャーを展開します。

  2. パブリケーションを右クリックし、 [プロパティ]をクリックします。

  3. 必要に応じてプロパティを変更し、 [OK]をクリックします。

Transact-SQL の使用

パブリケーションのプロパティは、レプリケーションのストアド プロシージャを使用して、プログラムから変更および取得できます。 どのストアド プロシージャを使用するかは、パブリケーションの種類によって異なります。

スナップショット パブリケーションまたはトランザクション パブリケーションのプロパティを表示するには

  1. @publicationパラメーターにパブリケーション名を指定して、 sp_helppublication を実行します。 このパラメーターを指定しなかった場合、パブリッシャーのすべてのパブリケーションの情報が返されます。

スナップショット パブリケーションまたはトランザクション パブリケーションのプロパティを変更するには

  1. sp_changepublicationを実行します。このとき、変更するパブリケーションのプロパティを @property パラメーターに指定し、このプロパティの新しい値を @value パラメーターに指定します。

    Note

    さらに、新しいスナップショットを生成する必要がある場合は、 @force_invalidate_snapshot1を、また、サブスクライバーを再初期化する必要がある場合は、 @force_reinit_subscription1を指定します。 変更時に新しいスナップショットの生成または再初期化が必要となるプロパティの詳細については、「Change Publication and Article Properties」(パブリケーションとアーティクルのプロパティの変更) を参照してください。

マージ パブリケーションのプロパティを表示するには

  1. @publicationパラメーターにパブリケーション名を指定して、 sp_helpmergepublication を実行します。 このパラメーターを指定しなかった場合、パブリッシャーのすべてのパブリケーションの情報が返されます。

マージ パブリケーションのプロパティを変更するには

  1. sp_changemergepublicationを実行します。このとき、変更するパブリケーションのプロパティを @property パラメーターに指定し、このプロパティの新しい値を @value パラメーターに指定します。

    Note

    変更する際に新しいスナップショットの生成が必要になる場合は、@force_invalidate_snapshot の値に 1 を、同様に、サブスクライバーの再初期化が必要になる場合は、@force_reinit_subscription の値に 1 を指定します。変更時に新しいスナップショットの生成または再初期化が必要となるプロパティの詳細については、「パブリケーションおよびアーティクルのプロパティの変更」を参照してください。

スナップショットのプロパティを表示するには

  1. @publicationパラメーターにパブリケーション名を指定して、 sp_helppublication_snapshot を実行します。

スナップショットのプロパティを変更するには

  1. 変更対象のスナップショット パラメーターに新しいスナップショット プロパティを少なくとも 1 つ指定して、 sp_changepublication_snapshotを実行します。

例 (Transact-SQL)

パブリケーションのプロパティを取得するトランザクション レプリケーションの例を、次に示します。

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) を使用して、パブリケーションの変更とそのプロパティへのアクセスをプログラムから実行できます。 パブリケーション プロパティの表示と変更に使用する RMO クラスは、パブリケーションの種類によって異なります。

スナップショット パブリケーションまたはトランザクション パブリケーションのプロパティを表示または変更するには

  1. ServerConnection クラスを使用して、パブリッシャーへの接続を作成します。

  2. TransPublication クラスのインスタンスを作成し、パブリケーションの Name プロパティと DatabaseName プロパティを設定して、手順 1. で作成した接続を ConnectionContext プロパティに設定します。

  3. LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。 このメソッドが falseを返す場合、手順 2. でパブリケーション プロパティを不適切に設定したか、パブリケーションが存在していません。

  4. (省略可) プロパティを変更するには、設定可能なプロパティに新しい値を設定します。 PublicationAttributes プロパティに特定の Attributes 値が設定されているかどうかを判断するには、論理積演算子 (Microsoft Visual C# では &、Microsoft Visual Basic では And) を使用します。 Attributes プロパティの PublicationAttributes 値を変更するには、包括的論理和演算子 (Visual C# では |、Visual Basic では Or) および排他的論理和演算子 (Visual C# では ^、Visual Basic では Xor) を使用します。

  5. (省略可) P:Microsoft.SqlServer.Replication.ReplicationObject.CachePropertyChangesCachePropertyChangesを指定した場合、 CommitPropertyChanges メソッドを呼び出してサーバーに変更をコミットします。 CachePropertyChanges に値 false (既定値) を指定した場合、変更は直ちにサーバーに送られます。

マージ パブリケーションのプロパティを表示または変更するには

  1. ServerConnection クラスを使用して、パブリッシャーへの接続を作成します。

  2. MergePublication クラスのインスタンスを作成し、パブリケーションの Name プロパティと DatabaseName プロパティを設定して、手順 1. で作成した接続を ConnectionContext プロパティに設定します。

  3. LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。 このメソッドが falseを返す場合、手順 2. でパブリケーション プロパティを不適切に設定したか、パブリケーションが存在していません。

  4. (省略可) プロパティを変更するには、設定可能なプロパティに新しい値を設定します。 PublicationAttributes プロパティに特定の Attributes 値が設定されているかどうかを判断するには、論理積演算子 (Visual C# では &、Visual Basic では And) を使用します。 Attributes プロパティの PublicationAttributes 値を変更するには、包括的論理和演算子 (Visual C# では |、Visual Basic では Or) および排他的論理和演算子 (Visual C# では ^、Visual Basic では Xor) を使用します。

  5. (省略可) P:Microsoft.SqlServer.Replication.ReplicationObject.CachePropertyChangesCachePropertyChangesを指定した場合、 CommitPropertyChanges メソッドを呼び出してサーバーに変更をコミットします。 CachePropertyChanges に値 false (既定値) を指定した場合、変更は直ちにサーバーに送られます。

例 (RMO)

次の例では、トランザクション パブリケーションにパブリケーション属性を設定します。 変更は明示的にサーバーに送られるまでキャッシュされます。

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

参照

データとデータベース オブジェクトのパブリッシュ
パブリケーションおよびアーティクルのプロパティの変更
パブリケーション データベースでのスキーマの変更
Replication System Stored Procedures Concepts
パブリケーションでのアーティクルの追加または削除 (SQL Server Management Studio)
レプリケーション モニターを使用して情報を表示し、タスクを実行する
アーティクルのプロパティの表示と変更