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; }
/** @property */
public PublicationAttributes get_Attributes ()

/** @property */
public void set_Attributes (PublicationAttributes value)

public function get Attributes () : PublicationAttributes

public function set Attributes (value : PublicationAttributes)

Property Value

A PublicationAttributes enumeration value.

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.

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


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

ReplicationDatabase publicationDb;
MergePublication publication;

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

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

    // Enable the database for merge publication.                
    publicationDb = new ReplicationDatabase(publicationDbName, conn);
    if (publicationDb.LoadProperties())
    {
        if (!publicationDb.EnabledMergePublishing)
        {
            publicationDb.EnabledMergePublishing = true;
        }
    }
    else
    {
        // 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.
        publication.Create();
        publication.CreateSnapshotAgent();
    }
    else
    {
        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);
}
finally
{
    conn.Disconnect();
}

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

Development Platforms

For a list of the supported platforms, see Hardware and Software Requirements for Installing SQL Server 2005.

Target Platforms

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft