MergePullSubscription.SynchronizeWithJob Metodo

Definizione

Avvia in modo asincrono il processo dell'agente per sincronizzare la sottoscrizione pull.

public:
 override void SynchronizeWithJob();
public override void SynchronizeWithJob ();
override this.SynchronizeWithJob : unit -> unit
Public Overrides Sub SynchronizeWithJob ()

Esempio

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

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

MergePullSubscription subscription;

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

    // 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)
    {
        subscription.SynchronizeWithJob();
    }
    else
    {
        // 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);
}
finally
{
    conn.Disconnect();
}
' Define server, publication, and database names.
Dim subscriberName As String = subscriberInstance
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2012"
Dim subscriptionDbName As String = "AdventureWorks2012Replica"

' Create a connection to the Subscriber.
Dim conn As ServerConnection = New ServerConnection(subscriberName)

Dim subscription As MergePullSubscription

Try
    ' Connect to the Subscriber.
    conn.Connect()

    ' 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() And Not subscription.AgentJobId Is Nothing Then
        subscription.SynchronizeWithJob()
    Else
        ' 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))
    End If
Catch ex As Exception
    ' Do appropriate error handling here.
    Throw New ApplicationException("The subscription could not be synchronized.", ex)
Finally
    conn.Disconnect()
End Try

Commenti

Utilizzare l'oggetto MergeSynchronizationAgent restituito dalla SynchronizationAgent proprietà per avviare il agente di merge in modo sincrono.

Se la sottoscrizione pull viene creata con il valore false per CreateSyncAgentByDefault, l'impostazione predefinita è che non viene creato un processo agente di merge per la sottoscrizione e la chiamata SynchronizeWithJob provocherà un'eccezione.

Chiamare il StopSynchronizationJob metodo per arrestare il processo se è attualmente in esecuzione.

Il processo non è in grado di avviare se il servizio Microsoft SQL Server Agent non è in esecuzione. Inoltre, se non viene generato uno snapshot, l'esecuzione del processo dell'agente potrebbe non sincronizzare la sottoscrizione.

Se sono state impostate proprietà aggiuntive in questa istanza di , chiamare prima di MergePullSubscriptionchiamare CommitPropertyChangesSynchronizeWithJob.

Il SynchronizeWithJob metodo può essere chiamato solo dai membri del ruolo predefinito del server sysadmin nel Sottoscrittore o dai membri del db_owner ruolo predefinito del database nel database di sottoscrizione.

Si applica a

Vedi anche