Share via


アーティクルのプロパティを表示および変更する方法 (RMO プログラミング)

アーティクルのプロパティは、レプリケーション管理オブジェクト (RMO) を使用してプログラムから変更できます。アーティクルのプロパティを表示または変更する際に使用する RMO のクラスは、アーティクルが属しているパブリケーションの種類によって異なります。

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

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

  2. TransArticle クラスのインスタンスを作成します。

  3. NamePublicationNameDatabaseName の各プロパティを設定します。

  4. 手順 1. で作成した接続を ConnectionContext プロパティに設定します。

  5. LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。このメソッドから false が返された場合、手順 3. で指定したアーティクルのプロパティが正しく定義されていないか、アーティクルが存在していません。

  6. (省略可) プロパティを変更するには、TransArticle の設定可能なプロパティに新しい値を設定します。

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

マージ パブリケーションに属しているアーティクルのプロパティを表示または変更するには

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

  2. MergeArticle クラスのインスタンスを作成します。

  3. NamePublicationNameDatabaseName の各プロパティを設定します。

  4. 手順 1. で作成した接続を ConnectionContext プロパティに設定します。

  5. LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。このメソッドから false が返された場合、手順 3. で指定したアーティクルのプロパティが正しく定義されていないか、アーティクルが存在していません。

  6. (省略可) プロパティを変更するには、MergeArticle の設定可能なプロパティに新しい値を設定します。

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

使用例

次の例では、マージ アーティクルに変更を加え、アーティクル用のビジネス ロジック ハンドラを指定しています。

           // Define the Publisher, publication, and article names.
            string publisherName = publisherInstance;
            string publicationName = "AdvWorksSalesOrdersMerge";
            string publicationDbName = "AdventureWorks2008R2";
            string articleName = "SalesOrderHeader";
            
            // Set the friendly name of the business logic handler.
            string customLogic = "OrderEntryLogic";

            MergeArticle article = new MergeArticle();
            
            // Create a connection to the Publisher.
            ServerConnection conn = new ServerConnection(publisherName);

            try
            {
                // Connect to the Publisher.
                conn.Connect();

                // Set the required properties for the article.
                article.ConnectionContext = conn;
                article.Name = articleName;
                article.DatabaseName = publicationDbName;
                article.PublicationName = publicationName;

                // Load the article properties.
                if (article.LoadProperties())
                {
                    article.ArticleResolver = customLogic;
                }
                else
                {
                    // Throw an exception of the article does not exist.
                    throw new ApplicationException(String.Format(
                    "{0} is not published in {1}", articleName, publicationName));
                }
                
            }
            catch (Exception ex)
            {
                // Do error handling here and rollback the transaction.
                throw new ApplicationException(String.Format(
                    "The business logic handler {0} could not be associated with " +
                    " the {1} article.",customLogic,articleName), ex);
            }
            finally
            {
                conn.Disconnect();
            }
' Define the Publisher, publication, and article names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2008R2"
Dim articleName As String = "SalesOrderHeader"

' Set the friendly name of the business logic handler.
Dim customLogic As String = "OrderEntryLogic"

Dim article As MergeArticle = New MergeArticle()

' 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 article.
    article.ConnectionContext = conn
    article.Name = articleName
    article.DatabaseName = publicationDbName
    article.PublicationName = publicationName

    ' Load the article properties.
    If article.LoadProperties() Then
        article.ArticleResolver = customLogic
    Else
        ' Throw an exception of the article does not exist.
        Throw New ApplicationException(String.Format( _
         "{0} is not published in {1}", articleName, publicationName))
    End If

Catch ex As Exception
    ' Do error handling here and rollback the transaction.
    Throw New ApplicationException(String.Format( _
     "The business logic handler {0} could not be associated with " + _
     " the {1} article.", customLogic, articleName), ex)
Finally
    conn.Disconnect()
End Try