Export (0) Print
Expand All

TransPullSubscription.SynchronizationAgent Property

Gets an object that represents an instance of the Distribution Agent that can be used to synchronize the subscription.

Namespace: Microsoft.SqlServer.Replication
Assembly: Microsoft.SqlServer.Rmo (in microsoft.sqlserver.rmo.dll)

public TransSynchronizationAgent SynchronizationAgent { get; }
/** @property */
public TransSynchronizationAgent get_SynchronizationAgent ()

public function get SynchronizationAgent () : TransSynchronizationAgent

Property Value

A TransSynchronizationAgent object.

Call the Synchronize method on the returned TransSynchronizationAgent object to synchronize the subscription.

Call CommitPropertyChanges to save any property changes on the server before retrieving SynchronizationAgent to synchronize the subscription.

If the pull subscription is created with a value of false for CreateSyncAgentByDefault, the default, a Distribution Agent job for the subscription is not created. You may need to specify additional properties on the returned TransSynchronizationAgent object before it can be used to synchronize the subscription.

The SynchronizationAgent property can only be retrieved by members of the sysadmin fixed server role at the Subscriber or by members of the db_owner fixed database role on the subscription database.

Retrieving the SynchronizationAgent property is equivalent to executing sp_helppullsubscription.

This namespace, class, or member is supported only in version 2.0 of the .NET Framework.


// Define the server, publication, and database names.
string subscriberName = subscriberInstance;
string publisherName = publisherInstance;
string publicationName = "AdvWorksProductTran";
string subscriptionDbName = "AdventureWorksReplica";
string publicationDbName = "AdventureWorks";

// Create a connection to the Subscriber.
ServerConnection conn = new ServerConnection(subscriberName);

TransPullSubscription subscription;

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

    // Define the pull subscription.
    subscription = new TransPullSubscription();
    subscription.ConnectionContext = conn;
    subscription.DatabaseName = subscriptionDbName;
    subscription.PublisherName = publisherName;
    subscription.PublicationDBName = publicationDbName;
    subscription.PublicationName = publicationName;

    // If the pull subscription exists, then start the synchronization.
    if (subscription.LoadProperties())
    {
        // Check that we have enough metadata to start the agent.
        if (subscription.PublisherSecurity != null)
        {
            // Synchronously start the Distribution Agent for the subscription.
            subscription.SynchronizationAgent.Synchronize();
        }
        else
        {
            throw new ApplicationException("There is insufficent metadata to " +
                "synchronize the subscription. Recreate the subscription with " +
                "the agent job or supply the required agent properties at run time.");
        }
    }
    else
    {
        // Do something here if the pull subscription does not exist.
        throw new ApplicationException(String.Format(
            "A subscription to '{0}' does not exist on {1}",
            publicationName, subscriberName));
    }
}
catch (Exception ex)
{
    // Implement appropriate error handling here.
    throw new ApplicationException("The subscription could not be " +
        "synchronized. Verify that the subscription has " +
        "been defined correctly.", ex);
}
finally
{
    conn.Disconnect();
}

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Development Platforms

For a list of the supported platforms, see Hardware and Software Requirements for Installing SQL Server 2005.

Target Platforms

Release

History

14 April 2006

Changed content:
  • Applications that use the TransSynchronizationAgent object are not restricted to use a single-threaded apartment threading model. The Remarks section was changed to remove this restriction.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft