Export (0) Print
Expand All

TransSynchronizationAgent Class

Topic Status: Some information in this topic is pre-release and subject to change in future releases. Pre-release information describes new features or changes to existing features in Microsoft SQL Server 2014.

Provides the functionality of the Replication Distribution Agent.

Object
  MarshalByRefObject
    Microsoft.SqlServer.Replication.TransSynchronizationAgent

Namespace:  Microsoft.SqlServer.Replication
Assembly:  Microsoft.SqlServer.Replication (in Microsoft.SqlServer.Replication.dll)

[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[GuidAttribute("adeda98a-bdfc-4029-b6fb-991d6b468395")]
[ComVisibleAttribute(true)]
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public class TransSynchronizationAgent : MarshalByRefObject, 
	IDisposable, ITransSynchronizationAgent

The TransSynchronizationAgent type exposes the following members.

  NameDescription
Public methodTransSynchronizationAgentCreates an instance of the TransSynchronizationAgent class.
Top

  NameDescription
Public propertyAltSnapshotFolderGets or sets the alternate snapshot folder for the subscription.
Public propertyComErrorCollectionGets a collection of errors that are generated by the replication agent.
Public propertyDistributorGets or sets the name of the instance of Microsoft SQL Server that is acting as the distributor for the subscription.
Public propertyDistributorAddressGets or sets the network address that is used to connect to the distributor when the DistributorNetwork property is specified.
Public propertyDistributorEncryptedPasswordInfrastructure. Gets or sets the encrypted password that is used when connecting to the distributor by using SQL Server Authentication.
Public propertyDistributorLoginGets or sets the login name that is used when connecting to the distributor by using SQL Server Authentication.
Public propertyDistributorNetworkGets or sets the client Net-Library that is used when connecting to the distributor.
Public propertyDistributorPasswordGets or sets the password that is used when connecting to the Distributor by using SQL Server Authentication.
Public propertyDistributorSecurityModeGets or sets the security mode that is used when connecting to the distributor.
Public propertyDtsPackageFileNameGets or sets the name and path of a Microsoft SQL Server 2000 Data Transformation Services (DTS) package that is used to transform command rowsets before they are applied to a Subscriber.
Public propertyDtsPackagePasswordGets or sets the owner password that used to access the Microsoft SQL Server 2000 Data Transformation Services (DTS) package specified by the DtsPackageFileName property.
Public propertyFileTransferTypeGets or sets how the initial snapshot files are transferred to the Subscriber.
Public propertyHostNameInfrastructure. Gets or sets the host name used.
Public propertyLastUpdatedTimeGets the timestamp of the last time that replication agent synchronized the subscription.
Public propertyLoginTimeoutGets or sets the maximum number of seconds to wait for connections to be established.
Public propertyMaxDeliveredTransactionsGets or sets the maximum number of transactions that are applied to the Subscriber during a single agent execution.
Public propertyOutputGets or sets the file name and path of the agent output file.
Public propertyOutputVerboseLevelGets or sets the amount of information that is logged by the Distribution Agent in the agent output file.
Public propertyProfileNameGets or sets the name of the profile that is used by the agent.
Public propertyPublicationGets or sets the name of the publication.
Public propertyPublisherGets or sets the name of the instance of Microsoft SQL Server that is the Publisher for the subscription.
Public propertyPublisherDatabaseGets or sets the name of the publication database.
Public propertyQueryTimeoutGets or sets the number of seconds that are allowed for internal queries to complete.
Public propertySecureDistributorEncryptedPasswordInfrastructure. Gets or sets the secure encrypted password for the distributor.
Public propertySecureSubscriberEncryptedPasswordInfrastructure. Gets or sets the secure encrypted password for the subscriber.
Public propertySkipErrorsGets or sets a colon-separated list of the error numbers that are to be skipped by this agent.
Public propertySubscriberGets or sets the name of the instance of Microsoft SQL Server that is the subscriber.
Public propertySubscriberDatabaseGets or sets the name of the subscription database.
Public propertySubscriberDatabasePathInfrastructure. Get or sets the database path for the subscriber.
Public propertySubscriberDataSourceTypeGets or sets the type of data source that is used as the subscriber.
Public propertySubscriberEncryptedPasswordInfrastructure. Gets or sets the encrypted password for the subscriber.
Public propertySubscriberLoginGets or sets the login name that is used when connecting to the subscriber by using SQL Server Authentication.
Public propertySubscriberPasswordGets or sets the password that is used when connecting to the subscriber by using SQL Server Authentication.
Public propertySubscriberSecurityModeGets or sets the security mode that is used when connecting to the publisher.
Public propertySubscriptionTypeGets or sets whether the subscription is a push or pull subscription.
Public propertyUndeliveredCommandsInfrastructure. Gets the number of undelivered commands.
Public propertyUndeliveredTransactionsInfrastructure. Gets the number of undelivered transactions.
Public propertyUseInProcLoaderGets or sets a value that indicates whether to use the BULK INSERT command when applying snapshot files at the subscriber.
Public propertyWorkingDirectoryGets or sets the working directory from which snapshot files are accessed when File Transfer Protocol (FTP) is used.
Top

  NameDescription
Public methodAbortInfrastructure. Aborts the TransSynchronizationAgent operation.
Public methodCreateObjRefSecurity Critical. (Inherited from MarshalByRefObject.)
Public methodDispose()Infrastructure. Releases all resources used by the current instance of the TransSynchronizationAgent class.
Protected methodDispose(Boolean)Releases all resources used by the TransSynchronizationAgent class.
Public methodEquals (Inherited from Object.)
Protected methodFinalizeInfrastructure. Finalizes the TransSynchronizationAgent. (Overrides ObjectFinalize.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetLifetimeServiceSecurity Critical. (Inherited from MarshalByRefObject.)
Public methodGetType (Inherited from Object.)
Public methodInitializeLifetimeServiceSecurity Critical. (Inherited from MarshalByRefObject.)
Public methodIsSnapshotRequiredConnects to the Distributor and the Subscriber to determine whether a new snapshot will be applied during the next agent synchronization.
Protected methodMemberwiseClone (Inherited from Object.)
Protected methodMemberwiseClone(Boolean) (Inherited from MarshalByRefObject.)
Public methodSynchronizeStarts the Distribution Agent to synchronize the subscription.
Public methodToString (Inherited from Object.)
Top

  NameDescription
Public eventComStatusInfrastructure. Occurs when the Distribution Agent returns synchronization Com status information.
Public eventStatusOccurs when the Distribution Agent returns synchronization status information.
Top

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.
			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();

				// 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())
				{
					// Check that we have enough metadata to start the agent.
					if (subscription.SubscriberSecurity != 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 push subscription does not exist.
					throw new ApplicationException(String.Format(
						"The 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.", 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()

    ' 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

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.

Community Additions

Show:
© 2014 Microsoft