Any suggestions? Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

MergeSynchronizationAgent.PublisherSecurityMode Property


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

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

public virtual SecurityMode PublisherSecurityMode { get; set; }

Property Value

Type: Microsoft.SqlServer.Replication.SecurityMode

A SecurityMode value that represents the security mode.

When possible, use Windows Authentication.

If the value is Standard, the PublisherLogin and PublisherPassword properties must also be specified.

// 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;

	// Connect to the Subscriber.

	// 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.
		// 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);
Return to top
© 2015 Microsoft