Udostępnij za pośrednictwem


Właściwość TransPullSubscription.SynchronizationAgent

Pobiera obiekt, który reprezentuje wystąpienie agenta dystrybucji, używany do synchronizacji subskrypcja.

Przestrzeń nazw:  Microsoft.SqlServer.Replication
Zestaw:  Microsoft.SqlServer.Rmo (w Microsoft.SqlServer.Rmo.dll)

Składnia

'Deklaracja
Public ReadOnly Property SynchronizationAgent As TransSynchronizationAgent
    Get
'Użycie
Dim instance As TransPullSubscription
Dim value As TransSynchronizationAgent

value = instance.SynchronizationAgent
public TransSynchronizationAgent SynchronizationAgent { get; }
public:
property TransSynchronizationAgent^ SynchronizationAgent {
    TransSynchronizationAgent^ get ();
}
member SynchronizationAgent : TransSynchronizationAgent
function get SynchronizationAgent () : TransSynchronizationAgent

Uwagi

Wywołanie Synchronize Metoda zwracane TransSynchronizationAgent obiektu do synchronizacji subskrypcja.

Wywołanie CommitPropertyChanges zapisać wszelkie zmiany właściwość na serwerze przed pobraniem SynchronizationAgent do synchronizacji subskrypcja.

Jeśli subskrypcja wciągana jest tworzony z wartością FAŁSZ dla CreateSyncAgentByDefault, domyślnie zadanie agenta dystrybucji subskrypcji nie jest tworzony.Należy określić dodatkowe właściwości na zwracane TransSynchronizationAgent obiekt, zanim będzie można używać do synchronizacji subskrypcja.

SynchronizationAgent właściwość mogą być pobierane tylko przez członków sysadmin rolę stałej serwera Subskrybent lub przez członków db_owner ustaloną rola bazy danych na baza danych subskrypcja.

Pobieranie SynchronizationAgent właściwość jest równoważne wykonywanie sp_helppullsubscription.

Ten obszar nazw, klasy lub element członkowski jest obsługiwany tylko w wersja 2.0.NET Framework.

Przykłady

            // Define the server, publication, and database names.
            string subscriberName = subscriberInstance;
            string publisherName = publisherInstance;
            string publicationName = "AdvWorksProductTran";
            string subscriptionDbName = "AdventureWorks2008R2Replica";
            string publicationDbName = "AdventureWorks2008R2";

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

            TransPullSubscription subscription;

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

                // Define the pull subscription.
                subscription = new TransPullSubscription();
                subscription.ConnectionContext = conn;
                subscription.DatabaseName = subscriptionDbName;
                subscription.PublisherName = publisherName;
                subscription.PublicationDBName = publicationDbName;
                subscription.PublicationName = publicationName;

                // If the pull subscription exists, then start the synchronization.
                if (subscription.LoadProperties())
                {
                    // Check that we have enough metadata to start the agent.
                    if (subscription.PublisherSecurity != null)
                    {
                        // Synchronously start the Distribution Agent for the subscription.
                        subscription.SynchronizationAgent.Synchronize();
                    }
                    else
                    {
                        throw new ApplicationException("There is insufficent metadata to " +
                            "synchronize the subscription. Recreate the subscription with " +
                            "the agent job or supply the required agent properties at run time.");
                    }
                }
                else
                {
                    // Do something here if the pull subscription does not exist.
                    throw new ApplicationException(String.Format(
                        "A subscription to '{0}' does not exist on {1}",
                        publicationName, subscriberName));
                }
            }
            catch (Exception ex)
            {
                // Implement appropriate error handling here.
                throw new ApplicationException("The subscription could not be " +
                    "synchronized. Verify that the subscription has " +
                    "been defined correctly.", 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 = "AdventureWorks2008R2Replica"
Dim publicationDbName As String = "AdventureWorks2008R2"

' 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 the pull subscription.
    subscription = New TransPullSubscription()
    subscription.ConnectionContext = conn
    subscription.DatabaseName = subscriptionDbName
    subscription.PublisherName = publisherName
    subscription.PublicationDBName = publicationDbName
    subscription.PublicationName = publicationName

    ' If the pull subscription exists, then start the synchronization.
    If subscription.LoadProperties() Then
        ' Check that we have enough metadata to start the agent.
        If Not subscription.PublisherSecurity Is Nothing Then

            ' Write agent output to a log file.
            subscription.SynchronizationAgent.Output = "distagent.log"
            subscription.SynchronizationAgent.OutputVerboseLevel = 2

            ' Synchronously start the Distribution Agent for the subscription.
            subscription.SynchronizationAgent.Synchronize()
        Else
            Throw New ApplicationException("There is insufficent metadata to " + _
             "synchronize the subscription. Recreate the subscription with " + _
             "the agent job or supply the required agent properties at run time.")
        End If
    Else
        ' Do something here if the pull subscription does not exist.
        Throw New ApplicationException(String.Format( _
         "A subscription to '{0}' does not exist on {1}", _
         publicationName, subscriberName))
    End If
Catch ex As Exception
    ' Implement appropriate error handling here.
    Throw New ApplicationException("The subscription could not be " + _
     "synchronized. Verify that the subscription has " + _
     "been defined correctly.", ex)
Finally
    conn.Disconnect()
End Try