Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Synchronize Method
Collapse the table of content
Expand the table of content

TransSynchronizationAgent.Synchronize Method

Starts the Distribution Agent to synchronize the subscription.

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

public virtual void Synchronize ()
public void Synchronize ()
public function Synchronize ()

This method synchronously starts the Distribution Agent. To start the Distribution Agent asynchronously, call SynchronizeWithJob for a pull subscription or SynchronizeWithJob for a push subscription.

Calling Synchronize is the same as calling the Initialize, Run, and Terminate methods on the SQLDistribution Object (Replication ActiveX).

In the following example, the Synchronize method is called on the instance of the TransSynchronizationAgent class that is accessed from the SynchronizationAgent property to synchronize the push subscription.

// 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;

    // Connect to the Publisher.

    // 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.
            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.");
        // 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);

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

Community Additions

© 2015 Microsoft