Export (0) Print
Expand All

How to: View and Modify Article Properties (RMO Programming)

You can modify articles and access their properties programmatically by using Replication Management Objects (RMO). The RMO classes you use to view or modify article properties depend on the type of publication to which the article belongs.

  1. Create a connection to the Publisher by using the ServerConnection class.

  2. Create an instance of the TransArticle class.

  3. Set the Name, PublicationName, and DatabaseName properties.

  4. Set the connection from step 1 for the ConnectionContext property.

  5. Call the LoadProperties method to get the properties of the object. If this method returns false, either the article properties in step 3 were defined incorrectly or the article does not exist.

  6. (Optional) To change properties, set a new value for one of the TransArticle properties that can be set.

  7. (Optional) If you specified a value of true for CachePropertyChanges, call the CommitPropertyChanges method to commit changes on the server. If you specified a value of false for CachePropertyChanges (the default), changes are sent to the server immediately.

  1. Create a connection to the Publisher by using the ServerConnection class.

  2. Create an instance of the MergeArticle class.

  3. Set the Name, PublicationName, and DatabaseName properties.

  4. Set the connection from step 1 for the ConnectionContext property.

  5. Call the LoadProperties method to get the properties of the object. If this method returns false, either the article properties in step 3 were defined incorrectly or the article does not exist.

  6. (Optional) To change properties, set a new value for one of the MergeArticle properties that can be set.

  7. (Optional) If you specified a value of true for CachePropertyChanges, call the CommitPropertyChanges method to commit changes on the server. If you specified a value of false for CachePropertyChanges (the default), changes are sent to the server immediately.

This example changes a merge article to specify the business logic handler used by the article.

// 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();
}

Community Additions

ADD
Show:
© 2014 Microsoft