Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TransSubscription.SynchronizationAgent Property

Gets an instance of the TransSynchronizationAgent class 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.

You should call CommitPropertyChanges to save any property changes on the server before retrieving SynchronizationAgent to synchronize the subscription.

If the subscription is created with a value of false for CreateSyncAgentByDefault, 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 Publisher, members of the db_owner fixed database role on the publication database, or members of the publication access list (PAL) for the publication to which the subscription belongs.

Retrieving SynchronizationAgent is equivalent to executing sp_helpsubscription (Transact-SQL).

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 Publisher.
ServerConnection conn = new ServerConnection(publisherName);

TransSubscription subscription;

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

    // Define the push subscription.
    subscription = new TransSubscription();
    subscription.ConnectionContext = conn;
    subscription.DatabaseName = publicationDbName;
    subscription.PublicationName = publicationName;
    subscription.SubscriptionDBName = subscriptionDbName;
    subscription.SubscriberName = subscriberName;

    // If the push subscription exists, start the synchronization.
    if (subscription.LoadProperties())
    {
        // Check that we have enough metadata to start the agent.
        if (subscription.SubscriberSecurity != 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 push subscription does not exist.
        throw new ApplicationException(String.Format(
            "The 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.", 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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.