Export (0) Print
Expand All

MergeSubscription.SynchronizeWithJob Method ()


Applies To: SQL Server 2016 Preview

Starts the agent job to synchronize the subscription.

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

public void SynchronizeWithJob()

If the pull subscription is created with a value of false for CreateSyncAgentByDefault, the default, a Merge Agent job for the subscription is not created and calling SynchronizeWithJob will cause an exception.

Call the StopSynchronizationJob method to stop the job if it is currently running.

The job is not able to start if the SQL Server Agent Service is not running. Also if a snapshot is not generated, running the agent job may not synchronize the subscription.

If you have set additional properties on this instance of MergeSubscription, call CommitPropertyChanges before calling SynchronizeWithJob.

The SynchronizeWithJob method can only be called 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.

Legacy Code Example

			// Define the server, publication, and database names.
			string subscriberName = subscriberInstance;
			string publisherName = publisherInstance;
			string publicationName = "AdvWorksSalesOrdersMerge";
			string subscriptionDbName = "AdventureWorks2012Replica";
			string publicationDbName = "AdventureWorks2012";

			// Create a connection to the Publisher.
			ServerConnection conn = new ServerConnection(publisherName);

			MergeSubscription subscription;

				// Connect to the Publisher.

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

				// If the push subscription and the job exists, start the agent job.
				if (subscription.LoadProperties() && subscription.AgentJobId != null)
					// Start the Merge Agent asynchronously.
					// Do something here if the subscription does not exist.
					throw new ApplicationException(String.Format(
						"A subscription to '{0}' does not exists 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