Compartir a través de


TransPullSubscription.SynchronizeWithJob Método

Definición

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

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

Ejemplos

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

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

TransPullSubscription subscription;

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

    // Define subscription properties.
    subscription = new TransPullSubscription();
    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 = "AdvWorksProductTran"
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 TransPullSubscription

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

    ' Define subscription properties.
    subscription = New TransPullSubscription()
    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

Comentarios

Utilice el TransSynchronizationAgent objeto devuelto por la SynchronizationAgent propiedad para iniciar el Agente de distribución sincrónicamente.

Si la suscripción de extracción se crea con un valor de false para CreateSyncAgentByDefault, el valor predeterminado es un trabajo de Agente de distribución para la suscripción y la llamada SynchronizeWithJob a provoca una excepción.

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

El trabajo no se puede iniciar si microsoft Agente SQL Server Service 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 adicionales en esta instancia de , llame CommitPropertyChanges a antes de TransPullSubscriptionllamar a SynchronizeWithJob.

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

Se aplica a

Consulte también