Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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()

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.

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 = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";

// 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);
Return to top
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft