Compartir a través de


TransSubscription.SynchronizeWithJob Método

Definición

Inicia el trabajo del agente para sincronizar la suscripción.

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

Ejemplos

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

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

    // Instantiate 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 and the job exists, start the agent job.
    if (subscription.LoadProperties() && subscription.AgentJobId != null)
    {
        // Start the Distribution 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 = "AdvWorksProductTran"
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 TransSubscription

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

    ' Instantiate 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 and the job exists, start the agent job.
    If subscription.LoadProperties() And Not subscription.AgentJobId Is Nothing Then
        ' Start the Distribution 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

Comentarios

Si la suscripción de extracción se crea con un valor de false para CreateSyncAgentByDefault, el valor predeterminado es que no se cree un trabajo de Agente de distribución para la suscripción. Llamar SynchronizeWithJob a hará que se produzca una excepción.

Llame al StopSynchronizationJob método para detener el trabajo si se está ejecutando actualmente.

El trabajo no se puede iniciar si el servicio Agente SQL Server no se está ejecutando. Además, si no se genera una instantánea, es posible que la ejecución del trabajo del agente no sincronice la suscripción.

Si ha establecido propiedades en esta instancia de , llame CommitPropertyChanges a antes de TransSubscriptionllamar a SynchronizeWithJob.

Los SynchronizeWithJob miembros del rol fijo de servidor solo pueden llamar al sysadmin método en el suscriptor o por miembros del db_owner rol fijo de base de datos en la base de datos de suscripciones.

Se aplica a

Consulte también