共用方式為


如何:檢視及修改發行項屬性 (RMO 程式設計)

您可以使用「複寫管理物件」(RMO) 以程式設計的方式修改發行項及存取其屬性。用來檢視或修改發行項屬性的 RMO 類別,將取決於發行項所屬的發行集類型而定。

檢視或修改屬於快照式或交易式發行集之發行項的屬性

  1. 使用 ServerConnection 類別建立與發行者的連接。

  2. 建立 TransArticle 類別的執行個體。

  3. 設定 NamePublicationNameDatabaseName 屬性。

  4. 針對 ConnectionContext 屬性設定步驟 1 中的連接。

  5. 呼叫 LoadProperties 方法以取得物件的屬性。如果此方法傳回 false,則表示步驟 3 中的發行項屬性定義不正確,或者該發行項不存在。

  6. (選擇性) 若要變更屬性,請針對其中一個可設定的 TransArticle 屬性設定新的值。

  7. (選擇性) 如果您已針對 CachePropertyChanges 指定 true 的值,請呼叫 CommitPropertyChanges 方法來認可伺服器上的變更。如果您已針對 CachePropertyChanges 指定 false 的值 (預設值),則會立即將變更傳送到伺服器。

檢視或修改屬於合併式發行集之發行項的屬性

  1. 使用 ServerConnection 類別建立與發行者的連接。

  2. 建立 MergeArticle 類別的執行個體。

  3. 設定 NamePublicationNameDatabaseName 屬性。

  4. 針對 ConnectionContext 屬性設定步驟 1 中的連接。

  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 = "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