Compartilhar via


MergeSubscription.SynchronizeWithJob Método

Definição

Inicia o trabalho de agente para sincronizar a assinatura.

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

Exemplos

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

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

    // 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.
        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)
{
    // Implement appropriate error handling here.
    throw new ApplicationException("The subscription could not be synchronized.", ex);
}
finally
{
    conn.Disconnect();
}
' Define the server, publication, and database names.
Dim subscriberName As String = subscriberInstance
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"

' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)

Dim subscription As MergeSubscription

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

    ' 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() And Not subscription.AgentJobId Is Nothing Then
        ' Start the Merge Agent asynchronously.
        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
    ' Implement appropriate error handling here.
    Throw New ApplicationException("The subscription could not be synchronized.", ex)
Finally
    conn.Disconnect()
End Try

Comentários

Se a assinatura pull for criada com um valor false paraCreateSyncAgentByDefault, o padrão, um trabalho de Agente de Mesclagem para a assinatura não será criado e chamar SynchronizeWithJob causará uma exceção.

Chame o StopSynchronizationJob método para interromper o trabalho se ele estiver em execução no momento.

O trabalho não poderá ser iniciado se o Serviço SQL Server Agent não estiver em execução. Além disso, se um instantâneo não for gerado, a execução do trabalho do agente poderá não sincronizar a assinatura.

Se você tiver definido propriedades adicionais nesta instância do , chame CommitPropertyChanges antes de MergeSubscriptionchamar SynchronizeWithJob.

O SynchronizeWithJob método só pode ser chamado por membros da função de servidor fixa sysadmin no Assinante ou por membros do db_owner função de banco de dados fixa no banco de dados de assinatura.

Aplica-se a

Confira também