Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Publication.Attributes Property


Gets or sets the publication attributes.

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

public PublicationAttributes Attributes { get; set; }

The PublicationAttributes enumeration supports the FlagsAttribute option, which allows a bitwise combination of enumeration values. See sp_addpublication (Transact-SQL) and sp_addmergepublication (Transact-SQL) for information about default attribute values for transactional or snapshot publications and merge publications respectively.

The Attributes property can only be retrieved by members of the sysadmin fixed server role at the Publisher, by members of the db_owner fixed database role on the publication database, or by users in the publication access list (PAL).

The Attributes property can only be set by members of the sysadmin fixed server role at the Publisher or by members of the db_owner fixed database role on the publication database. Users in the PAL can set the Attributes property of an existing publication.

Retrieving the Attributes property is equivalent to executing sp_helppublication or sp_helpmergepublication.

Setting the Attributes property is equivalent to executing sp_addpublication and sp_changepublication or sp_addmergepublication and sp_changemergepublication.

// Set the Publisher, publication database, and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks2012";

ReplicationDatabase publicationDb;
MergePublication publication;

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

	// Connect to the Publisher.

	// Enable the database for merge publication.				
	publicationDb = new ReplicationDatabase(publicationDbName, conn);
	if (publicationDb.LoadProperties())
		if (!publicationDb.EnabledMergePublishing)
			publicationDb.EnabledMergePublishing = true;
		// Do something here if the database does not exist. 
		throw new ApplicationException(String.Format(
			"The {0} database does not exist on {1}.",
			publicationDb, publisherName));

	// Set the required properties for the merge publication.
	publication = new MergePublication();
	publication.ConnectionContext = conn;
	publication.Name = publicationName;
	publication.DatabaseName = publicationDbName;

	// Enable Web synchronization, if not already enabled.
	if ((publication.Attributes & PublicationAttributes.AllowWebSynchronization) == 0)
		publication.Attributes |= PublicationAttributes.AllowWebSynchronization;

	// Enable pull subscriptions, if not already enabled.
	if ((publication.Attributes & PublicationAttributes.AllowPull) == 0)
		publication.Attributes |= PublicationAttributes.AllowPull;

	// Enable Subscriber requested snapshot generation. 
	publication.Attributes |= PublicationAttributes.AllowSubscriberInitiatedSnapshot;

             // Enable anonymous access for Subscribers that cannot make a direct connetion 
             // to the Publisher. 
             publication.Attributes |= PublicationAttributes.AllowAnonymous;

	// Specify the Windows account under which the Snapshot Agent job runs.
	// This account will be used for the local connection to the 
	// Distributor and all agent connections that use Windows Authentication.
	publication.SnapshotGenerationAgentProcessSecurity.Login = winLogin;
	publication.SnapshotGenerationAgentProcessSecurity.Password = winPassword;

	// Explicitly set the security mode for the Publisher connection
	// Windows Authentication (the default).
	publication.SnapshotGenerationAgentPublisherSecurity.WindowsAuthentication = true;

	if (!publication.IsExistingObject)
		// Create the merge publication and the Snapshot Agent job.
		throw new ApplicationException(String.Format(
			"The {0} publication already exists.", publicationName));

catch (Exception ex)
	// Implement custom application error handling here.
	throw new ApplicationException(String.Format(
		"The publication {0} could not be created.", publicationName), ex);
Return to top
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft