
Provides the functionality of the Replication Distribution Agent.
Assembly: Microsoft.SqlServer.Replication (in Microsoft.SqlServer.Replication.dll)
'Declaration <GuidAttribute("adeda98a-bdfc-4029-b6fb-991d6b468395")> _ <ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _ <ComVisibleAttribute(True)> _ <PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _ Public Class TransSynchronizationAgent _ Inherits MarshalByRefObject _ Implements IDisposable, ITransSynchronizationAgent
'Usage Dim instance As TransSynchronizationAgent
The TransSynchronizationAgent class supports the ability to programmatically synchronize subscriptions to transactional or snapshot publications.
In the following example, the Synchronize method is called on the instance of the TransSynchronizationAgent class that is accessed from the SynchronizationAgent property to synchronize the push subscription.
' 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 Publisher. Dim conn As ServerConnection = New ServerConnection(publisherName) Dim subscription As TransSubscription Try ' Connect to the Publisher. conn.Connect() ' Define 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 exists, start the synchronization. If subscription.LoadProperties() Then ' Check that we have enough metadata to start the agent. If Not subscription.SubscriberSecurity Is Nothing Then ' 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 push subscription does not exist. Throw New ApplicationException(String.Format( _ "The 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.", ex) Finally conn.Disconnect() End Try
System.MarshalByRefObject
Microsoft.SqlServer.Replication.TransSynchronizationAgent
The TransSynchronizationAgent class does not support multithreaded apartments. You can specify a single-threaded apartment by declaring the [STAThread] attribute on the method that is the main entry point for the application. This is the default for Microsoft Windows-based applications that are created by using Microsoft Visual Studio.
