Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MSDN Library

MergeSynchronizationAgent Class

 

Applies To: SQL Server 2016 Preview

Provides the functionality of the Replication Merge Agent.

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

System.Object
  System.MarshalByRefObject
    Microsoft.SqlServer.Replication.MergeSynchronizationAgent

[ComVisibleAttribute(true)]
[GuidAttribute("ee5ee47e-6d29-448f-b2d2-f8e632db336a")]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public class MergeSynchronizationAgent : MarshalByRefObject, 
	IDisposable

NameDescription
System_CAPS_pubmethodMergeSynchronizationAgent()

Creates an instance of the MergeSynchronizationAgent class.

NameDescription
System_CAPS_pubpropertyAlternateSynchronizationPartnerCollection

Gets the alternate synchronization partners for a subscription.

System_CAPS_pubpropertyAltSnapshotFolder

Gets or sets the alternate snapshot folder for the subscription.

System_CAPS_pubpropertyComErrorCollection

Gets a collection of errors generated by the replication agent.

System_CAPS_pubpropertyDistributor

Gets or sets the name of the instance of Microsoft SQL Server that is acting as the Distributor for the subscription.

System_CAPS_pubpropertyDistributorAddress

Gets or sets the network address that is used to connect to the Distributor when the DistributorNetwork property is specified.

System_CAPS_pubpropertyDistributorEncryptedPassword

This API supports the product infrastructure and is not intended to be used directly from your code. Gets or sets the distributor encrypted password.

System_CAPS_pubpropertyDistributorLogin

Gets or sets the login name that is used when connecting to the Distributor using SQL Server Authentication.

System_CAPS_pubpropertyDistributorNetwork

Gets or sets the client Net-Library that is used when connecting to the Distributor.

System_CAPS_pubpropertyDistributorPassword

Sets the password that is used when connecting to the Distributor using SQL Server Authentication.

System_CAPS_pubpropertyDistributorSecurityMode

Gets or sets the security mode used when connecting to the Distributor.

System_CAPS_pubpropertyDownloadGenerationsPerBatch

Gets or sets the number of generations to be processed in a single batch while downloading changes from the Publisher to the Subscriber. A generation is defined as a logical group of changes per article.

System_CAPS_pubpropertyDynamicSnapshotLocation

Gets or sets the location of the partitioned snapshot for this Subscriber.

System_CAPS_pubpropertyExchangeType

Gets or sets how data is exchanged during synchronization.

System_CAPS_pubpropertyFileTransferType

Gets or sets how the initial snapshot files are transferred to the Subscriber.

System_CAPS_pubpropertyHostName

Gets or sets the value used by the Merge Agent when it evaluates a parameterized filter that uses the HOST_NAME function.

System_CAPS_pubpropertyInputMessageFile

This API supports the product infrastructure and is not intended to be used directly from your code. Gets or sets the input message file.

System_CAPS_pubpropertyInternetLogin

Gets or sets the login name that is used with Web synchronization when connecting to the Publisher by using Internet authentication.

System_CAPS_pubpropertyInternetPassword

Sets the password for the InternetLogin property that is used with Web synchronization when connecting to the Publisher by using Internet authentication.

System_CAPS_pubpropertyInternetProxyLogin

Gets or sets the login name that is used with Web synchronization when connecting to the Web server by using an Internet proxy server.

System_CAPS_pubpropertyInternetProxyPassword

Sets the password for the login that is used with Web synchronization when connecting to the Web server by using an Internet proxy server.

System_CAPS_pubpropertyInternetProxyServer

Gets or sets the name of the Internet proxy server that is used with Web synchronization when connecting to the Web server.

System_CAPS_pubpropertyInternetSecurityMode

Gets or sets the HTTP authentication method that is used when connecting to the Web server during Web synchronization.

System_CAPS_pubpropertyInternetTimeout

Gets or sets the HTTP time-out when connecting to the Web server.

System_CAPS_pubpropertyInternetUrl

Gets or sets the URL of the Web service that is configured for Web synchronization.

System_CAPS_pubpropertyLastUpdatedTime

Gets the timestamp of the last time that replication agent synchronized the subscription.

System_CAPS_pubpropertyLoginTimeout

Gets or sets the maximum number of seconds to wait for connections to be established.

System_CAPS_pubpropertyMetadataRetentionCleanup

Get or sets whether to clean up metadata.

System_CAPS_pubpropertyOutput

Gets or sets the agent output file.

System_CAPS_pubpropertyOutputMessageFile

This API supports the product infrastructure and is not intended to be used directly from your code. Gets or sets the input message file.

System_CAPS_pubpropertyOutputVerboseLevel

Gets or sets the level of detail of information that is written to the agent output file.

System_CAPS_pubpropertyProfileName

Gets or sets the name of the profile that is used by the agent.

System_CAPS_pubpropertyPublication

Gets or sets the name of the publication.

System_CAPS_pubpropertyPublisher

Gets or sets the name of the instance of Microsoft SQL Server that is the Publisher for the subscription.

System_CAPS_pubpropertyPublisherAddress

Gets or sets the network address that is used to connect to the Publisher when the PublisherNetwork property is specified.

System_CAPS_pubpropertyPublisherChanges

Gets the total number of Publisher changes that were applied at the Subscriber during the last synchronization.

System_CAPS_pubpropertyPublisherConflicts

Gets the total number of conflicts that occurred at the Publisher during the last synchronization.

System_CAPS_pubpropertyPublisherDatabase

Gets or sets the name of the publication database.

System_CAPS_pubpropertyPublisherEncryptedPassword

This API supports the product infrastructure and is not intended to be used directly from your code. Gets or sets the publisher encrypted password.

System_CAPS_pubpropertyPublisherFailoverPartner

Gets or sets the failover partner instance of SQL Server that is participating in a database mirroring session with the publication database.

System_CAPS_pubpropertyPublisherLogin

Gets or sets the login name that is used when connecting to the Publisher by using SQL Server Authentication.

System_CAPS_pubpropertyPublisherNetwork

Gets or sets the client Net-Library that is used when connecting to the Publisher.

System_CAPS_pubpropertyPublisherPassword

Sets the password that is used when connecting to the Publisher by using SQL Server Authentication.

System_CAPS_pubpropertyPublisherSecurityMode

Gets or sets the security mode that is used when connecting to the Publisher.

System_CAPS_pubpropertyQueryTimeout

Gets or sets the number of seconds that are allowed for internal queries to finish.

System_CAPS_pubpropertySecureDistributorEncryptedPassword

This API supports the product infrastructure and is not intended to be used directly from your code. Gets or sets the secure distributor encrypted password.

System_CAPS_pubpropertySecurePublisherEncryptedPassword

This API supports the product infrastructure and is not intended to be used directly from your code. Gets or sets the secure publisher encrypted password.

System_CAPS_pubpropertySecureSubscriberEncryptedPassword

This API supports the product infrastructure and is not intended to be used directly from your code. Gets or sets the secure subscriber encrypted password.

System_CAPS_pubpropertySubscriber

Gets or sets the name of the instance of Microsoft SQL Server that is the Subscriber.

System_CAPS_pubpropertySubscriberChanges

Gets the total number of Subscriber changes that were applied at the Publisher during the last synchronization.

System_CAPS_pubpropertySubscriberConflicts

Gets the total number of conflicts that occurred at the Publisher during the last synchronization.

System_CAPS_pubpropertySubscriberDatabase

Gets or sets the name of the subscription database.

System_CAPS_pubpropertySubscriberDatabasePath

This API supports the product infrastructure and is not intended to be used directly from your code. Gets or sets the subscriber database path.

System_CAPS_pubpropertySubscriberDataSourceType

Gets or sets the type of data source that is used as the Subscriber.

System_CAPS_pubpropertySubscriberEncryptedPassword

This API supports the product infrastructure and is not intended to be used directly from your code. Gets or sets the subscriber encrypted password.

System_CAPS_pubpropertySubscriberLogin

Gets or sets the login name used that is when connecting to the Subscriber by using SQL Server Authentication.

System_CAPS_pubpropertySubscriberPassword

Sets the password that is used when connecting to the Subscriber by using SQL Server Authentication.

System_CAPS_pubpropertySubscriberSecurityMode

Gets or sets the security mode used when connecting to the Subscriber.

System_CAPS_pubpropertySubscriptionType

Gets or sets whether the subscription is a push or pull subscription.

System_CAPS_pubpropertySyncToAlternate

Gets or sets whether the synchronization is to an alternate synchronization partner.

System_CAPS_pubpropertyUploadGenerationsPerBatch

Gets or sets the number of generations to be processed in a single batch while uploading changes from the Subscriber to the Publisher. A generation is defined as a logical group of changes per article.

System_CAPS_pubpropertyUseInteractiveResolver

Gets or sets whether the interactive resolver is used during reconciliation.

System_CAPS_pubpropertyUseWebSynchronization

Gets or sets whether Web synchronization is used.

System_CAPS_pubpropertyValidate

Gets or sets whether data validation is performed on the Subscriber data at the end of the synchronization.

System_CAPS_pubpropertyWorkingDirectory

Gets or sets the working directory from which snapshot files are accessed when FTP is used.

NameDescription
System_CAPS_pubmethodAbort()

This API supports the product infrastructure and is not intended to be used directly from your code. Aborts the synchronization.

System_CAPS_pubmethodClearAllTraceFlags()

This API supports the product infrastructure and is not intended to be used directly from your code. Clears all the trace flags used by the synchronization agent.

System_CAPS_pubmethodClearTraceFlag(Int32)

This API supports the product infrastructure and is not intended to be used directly from your code. Clears a trace flag.

System_CAPS_pubmethodCreateObjRef(Type)

(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodDispose()

This API supports the product infrastructure and is not intended to be used directly from your code. Releases the unmanaged resources that are used by MergeSynchronizationAgent.

System_CAPS_protmethodDispose(Boolean)

This API supports the product infrastructure and is not intended to be used directly from your code. Releases the unmanaged resources that are used by MergeSynchronizationAgent.

System_CAPS_pubmethodEnableTraceFlag(Int32)

This API supports the product infrastructure and is not intended to be used directly from your code. Enables the flag tracing.

System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_protmethodFinalize()

This API supports the product infrastructure and is not intended to be used directly from your code. Finalizes the agent.(Overrides Object.Finalize().)

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetLifetimeService()

(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodInitializeLifetimeService()

(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodIsSnapshotRequired()

Connects to the Publisher or Distributor and the Subscriber to determine whether a new snapshot will be applied during the next agent synchronization.

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone(Boolean)

(Inherited from MarshalByRefObject.)

System_CAPS_pubmethodProcessMessagesAtPublisher()

This API supports the product infrastructure and is not intended to be used directly from your code. Processes the messages at publisher.

System_CAPS_pubmethodProcessMessagesAtSubscriber()

This API supports the product infrastructure and is not intended to be used directly from your code. Processes the messages at subscriber.

System_CAPS_pubmethodSynchronize()

Starts the Merge Agent to synchronize the subscription.

System_CAPS_pubmethodToString()

(Inherited from Object.)

NameDescription
System_CAPS_pubeventComStatus

This API supports the product infrastructure and is not intended to be used directly from your code. Occurs when the Merge Agent returns synchronization Com status information.

System_CAPS_pubeventStatus

Occurs when the Merge Agent returns synchronization status information.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

The MergeSynchronizationAgent class supports the ability to do the following replication tasks:

  • Synchronize subscriptions.

  • Specify whether only the upload phase, only the download phase, or both phases are run during synchronization.

  • Validate that a subscription has the expected data.

  • Specify a different snapshot folder, from which the initial snapshot for a subscription can be applied.

Legacy Code Example

In the following example, the Synchronize method is called on the instance of the MergeSynchronizationAgent 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 = "AdvWorksSalesOrdersMerge";
			string subscriptionDbName = "AdventureWorks2012Replica";
			string publicationDbName = "AdventureWorks2012";

			// Create a connection to the Publisher.
			ServerConnection conn = new ServerConnection(publisherName);

			MergeSubscription subscription;

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

				// Define the subscription.
				subscription = new MergeSubscription();
				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 Merge 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();
			}

In the following example, an instance of the MergeSynchronizationAgent class is used to synchronize a merge subscription. Because the pull subscription was created by using a value of false for CreateSyncAgentByDefault, additional properties must be supplied.

			// Define the server, publication, and database names.
			string subscriberName = subscriberInstance;
			string publisherName = publisherInstance;
            string distributorName = distributorInstance;
            string publicationName = "AdvWorksSalesOrdersMerge";
			string subscriptionDbName = "AdventureWorks2012Replica";
			string publicationDbName = "AdventureWorks2012";
			string hostname = @"adventure-works\garrett1";
			string webSyncUrl = "https://" + publisherInstance + "/SalesOrders/replisapi.dll";

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

			MergePullSubscription subscription;
			MergeSynchronizationAgent agent;

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

				// Define the pull subscription.
				subscription = new MergePullSubscription();
				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())
				{
					// Get the agent for the subscription.
					agent = subscription.SynchronizationAgent;

					// Check that we have enough metadata to start the agent.
					if (agent.PublisherSecurityMode == null)
					{
						// Set the required properties that could not be returned
						// from the MSsubscription_properties table. 
						agent.PublisherSecurityMode = SecurityMode.Integrated;
						agent.DistributorSecurityMode = SecurityMode.Integrated;
                        agent.Distributor = publisherName;
                        agent.HostName = hostname;

						// Set optional Web synchronization properties.
						agent.UseWebSynchronization = true;
						agent.InternetUrl = webSyncUrl;
						agent.InternetSecurityMode = SecurityMode.Standard;
						agent.InternetLogin = winLogin;
						agent.InternetPassword = winPassword;
					}
					// Enable agent output to the console.
					agent.OutputVerboseLevel = 1;
					agent.Output = "";

					// Synchronously start the Merge Agent for the subscription.
					agent.Synchronize();
				}
				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();
			}
Return to top

Community Additions

Show:
© 2015 Microsoft