アーティクルのプロパティは、レプリケーション管理オブジェクト (RMO) を使用してプログラムから変更できます。アーティクルのプロパティを表示または変更する際に使用する RMO のクラスは、アーティクルが属しているパブリケーションの種類によって異なります。
スナップショット パブリケーションまたはトランザクション パブリケーションに属しているアーティクルのプロパティを表示または変更するには
ServerConnection クラスを使用して、パブリッシャへの接続を作成します。
TransArticle クラスのインスタンスを作成します。
Name、PublicationName、DatabaseName の各プロパティを設定します。
手順 1. で作成した接続を ConnectionContext プロパティに設定します。
LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。このメソッドから false が返された場合、手順 3. で指定したアーティクルのプロパティが正しく定義されていないか、アーティクルが存在していません。
(省略可) プロパティを変更するには、TransArticle の設定可能なプロパティに新しい値を設定します。
(省略可) CachePropertyChanges に true を指定した場合、CommitPropertyChanges メソッドを呼び出してサーバーに変更をコミットします。CachePropertyChanges に false (既定値) を指定した場合、変更は直ちにサーバーに送られます。
マージ パブリケーションに属しているアーティクルのプロパティを表示または変更するには
ServerConnection クラスを使用して、パブリッシャへの接続を作成します。
MergeArticle クラスのインスタンスを作成します。
Name、PublicationName、DatabaseName の各プロパティを設定します。
手順 1. で作成した接続を ConnectionContext プロパティに設定します。
LoadProperties メソッドを呼び出して、オブジェクトのプロパティを取得します。このメソッドから false が返された場合、手順 3. で指定したアーティクルのプロパティが正しく定義されていないか、アーティクルが存在していません。
(省略可) プロパティを変更するには、MergeArticle の設定可能なプロパティに新しい値を設定します。
(省略可) CachePropertyChanges に true を指定した場合、CommitPropertyChanges メソッドを呼び出してサーバーに変更をコミットします。CachePropertyChanges に false (既定値) を指定した場合、変更は直ちにサーバーに送られます。
使用例
次の例では、マージ アーティクルに変更を加え、アーティクル用のビジネス ロジック ハンドラを指定しています。
// Define the Publisher, publication, and article names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks";
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 = "AdventureWorks"
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
参照
処理手順
アーティクルを定義する方法 (RMO プログラミング)
アーティクルを削除する方法 (RMO プログラミング)
アーティクルのプロパティを表示および変更する方法 (レプリケーション Transact-SQL プログラミング)
マージ アーティクルにビジネス ロジック ハンドラを実装する方法 (RMO プログラミング)