방법: 아티클 속성 보기 및 수정(RMO 프로그래밍)

RMO(복제 관리 개체)를 사용하여 프로그래밍 방식으로 아티클을 수정하고 해당 속성에 액세스할 수 있습니다. 아티클 속성을 보거나 수정하는 데 사용되는 RMO 클래스는 아티클이 속한 게시 유형에 따라 달라집니다.

스냅숏 또는 트랜잭션 게시에 속하는 아티클의 속성을 보거나 수정하려면

  1. ServerConnection 클래스를 사용하여 게시자 연결을 만듭니다.

  2. TransArticle 클래스의 인스턴스를 만듭니다.

  3. Name, PublicationNameDatabaseName 속성을 설정합니다.

  4. ConnectionContext 속성에 대해 1단계에서 만든 연결을 설정합니다.

  5. LoadProperties 메서드를 호출하여 개체 속성을 가져옵니다. 이 메서드가 false를 반환하는 경우 3단계에서 아티클 속성이 올바르게 정의되지 않았거나 아티클이 없습니다.

  6. (옵션) 속성을 변경하려면 설정할 수 있는 TransArticle 속성 중 하나에 대해 새 값을 설정합니다.

  7. (옵션) CachePropertyChanges에 대해 true 값을 지정했으면 CommitPropertyChanges 메서드를 호출하여 서버의 변경 내용을 커밋합니다. CachePropertyChanges에 대해 false 값을 지정했으면(기본값) 변경 내용이 즉시 서버로 전송됩니다.

병합 게시에 속하는 아티클의 속성을 보거나 수정하려면

  1. ServerConnection 클래스를 사용하여 게시자 연결을 만듭니다.

  2. MergeArticle 클래스의 인스턴스를 만듭니다.

  3. Name, PublicationNameDatabaseName 속성을 설정합니다.

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