Export (0) Print
Expand All

MergePullSubscription.SynchronizeWithJob Method

Starts the agent job asynchronously to synchronize the pull subscription.

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

public override void SynchronizeWithJob ()
public void SynchronizeWithJob ()
public override function SynchronizeWithJob ()

Use the MergeSynchronizationAgent object returned by the SynchronizationAgent property to start the Merge Agent synchronously.

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 Microsoft 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 MergePullSubscription, 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.

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

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

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

MergePullSubscription subscription;

    // Connect to the Subscriber.

    // Define subscription properties.
    subscription = new MergePullSubscription();
    subscription.ConnectionContext = conn;
    subscription.DatabaseName = subscriptionDbName;
    subscription.PublisherName = publisherName;
    subscription.PublicationDBName = publicationDbName;
    subscription.PublicationName = publicationName;

    // If the pull subscription and the job exists, start the agent job.
    if (subscription.LoadProperties() && subscription.AgentJobId != null)
        // 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)
    // Do 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

© 2014 Microsoft