MergeSubscriberType Enumeration


Enumeration additional types of subscriptions supported by merge replication.

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

public enum MergeSubscriberType

Member nameDescription

The pull subscription is not explicitly registered at the Publisher by using MakePullSubscriptionWellKnown. Anonymous subscriptions are required if you want to create a subscription without registering the subscription at the Publisher. This is necessary for cases such as Web synchronization, in which you cannot establish a SQL Server connection to the Publisher during subscription configuration.


The subscription is a server subscription. This type is typically used for Subscribers that republish data to other Subscribers.


The subscription is a client subscription. This type of subscription is appropriate for most Subscribers.

This namespace, class, or member is supported only in version 2.0 of the Microsoft .NET Framework.

// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksSalesOrdersMerge";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";
string hostname = @"adventure-works\garrett1";

//Create connections to the Publisher and Subscriber.
ServerConnection subscriberConn = new ServerConnection(subscriberName);
ServerConnection publisherConn = new ServerConnection(publisherName);

// Create the objects that we need.
MergePublication publication;
MergePullSubscription subscription;

	// Connect to the Subscriber.

	// Ensure that the publication exists and that 
	// it supports pull subscriptions.
	publication = new MergePublication();
	publication.Name = publicationName;
	publication.DatabaseName = publicationDbName;
	publication.ConnectionContext = publisherConn;

	if (publication.LoadProperties())
		if ((publication.Attributes & PublicationAttributes.AllowPull) == 0)
			publication.Attributes |= PublicationAttributes.AllowPull;

		// Define the pull subscription.
		subscription = new MergePullSubscription();
		subscription.ConnectionContext = subscriberConn;
		subscription.PublisherName = publisherName;
		subscription.PublicationName = publicationName;
		subscription.PublicationDBName = publicationDbName;
		subscription.DatabaseName = subscriptionDbName;
		subscription.HostName = hostname;

		// Specify the Windows login credentials for the Merge Agent job.
		subscription.SynchronizationAgentProcessSecurity.Login = winLogin;
		subscription.SynchronizationAgentProcessSecurity.Password = winPassword;

		// Make sure that the agent job for the subscription is created.
		subscription.CreateSyncAgentByDefault = true;

		// Create the pull subscription at the Subscriber.

		Boolean registered = false;

		// Verify that the subscription is not already registered.
		foreach (MergeSubscription existing
			in publication.EnumSubscriptions())
			if (existing.SubscriberName == subscriberName
				&& existing.SubscriptionDBName == subscriptionDbName
				&& existing.SubscriptionType == SubscriptionOption.Pull)
				registered = true;
		if (!registered)
			// Register the local subscription with the Publisher.
				subscriberName, subscriptionDbName,
				MergeSubscriberType.Local, 0);
		// Do something here if the publication does not exist.
		throw new ApplicationException(String.Format(
			"The publication '{0}' does not exist on {1}.",
			publicationName, publisherName));
catch (Exception ex)
	// Implement the appropriate error handling here.
	throw new ApplicationException(String.Format(
		"The subscription to {0} could not be created.", publicationName), ex);
Return to top