Article.PublicationName 属性

定义

获取或设置项目所属于的发布的名称。

public:
 property System::String ^ PublicationName { System::String ^ get(); void set(System::String ^ value); };
public string PublicationName { get; set; }
member this.PublicationName : string with get, set
Public Property PublicationName As String

属性值

发布的名称。

例外

尝试设置 PublicationName 现有项目的属性时。

将属性设置为 PublicationNamenull 、具有 null 字符的值或大于 128-Unicode 字符的值。

示例

// Define the Publisher, publication, and article names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks2012";
string articleName = "Product";
string schemaOwner = "Production";

TransArticle article;

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

// Create a filtered transactional articles in the following steps:
// 1) Create the  article with a horizontal filter clause.
// 2) Add columns to or remove columns from the article.
try
{
    // Connect to the Publisher.
    conn.Connect();

    // Define a horizontally filtered, log-based table article.
    article = new TransArticle();
    article.ConnectionContext = conn;
    article.Name = articleName;
    article.DatabaseName = publicationDbName;
    article.SourceObjectName = articleName;
    article.SourceObjectOwner = schemaOwner;
    article.PublicationName = publicationName;
    article.Type = ArticleOptions.LogBased;
    article.FilterClause = "DiscontinuedDate IS NULL";

    // Ensure that we create the schema owner at the Subscriber.
    article.SchemaOption |= CreationScriptOptions.Schema;

    if (!article.IsExistingObject)
    {
        // Create the article.
        article.Create();
    }
    else
    {
        throw new ApplicationException(String.Format(
            "The article {0} already exists in publication {1}.",
            articleName, publicationName));
    }

    // Create an array of column names to remove from the article.
    String[] columns = new String[1];
    columns[0] = "DaysToManufacture";

    // Remove the column from the article.
    article.RemoveReplicatedColumns(columns);
}
catch (Exception ex)
{
    // Implement appropriate error handling here.
    throw new ApplicationException("The article could not be created.", ex);
}
finally
{
    conn.Disconnect();
}
' Define the Publisher, publication, and article names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks2012"
Dim articleName As String = "Product"
Dim schemaOwner As String = "Production"

Dim article As TransArticle

' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)

' Create a filtered transactional articles in the following steps:
' 1) Create the  article with a horizontal filter clause.
' 2) Add columns to or remove columns from the article.
Try
    ' Connect to the Publisher.
    conn.Connect()

    ' Define a horizontally filtered, log-based table article.
    article = New TransArticle()
    article.ConnectionContext = conn
    article.Name = articleName
    article.DatabaseName = publicationDbName
    article.SourceObjectName = articleName
    article.SourceObjectOwner = schemaOwner
    article.PublicationName = publicationName
    article.Type = ArticleOptions.LogBased
    article.FilterClause = "DiscontinuedDate IS NULL"

    ' Ensure that we create the schema owner at the Subscriber.
    article.SchemaOption = article.SchemaOption Or _
    CreationScriptOptions.Schema

    If Not article.IsExistingObject Then
        ' Create the article.
        article.Create()
    Else
        Throw New ApplicationException(String.Format( _
         "The article {0} already exists in publication {1}.", _
         articleName, publicationName))
    End If

    ' Create an array of column names to remove from the article.
    Dim columns() As String = New String(0) {}
    columns(0) = "DaysToManufacture"

    ' Remove the column from the article.
    article.RemoveReplicatedColumns(columns)
Catch ex As Exception
    ' Implement appropriate error handling here.
    Throw New ApplicationException("The article could not be created.", ex)
Finally
    conn.Disconnect()
End Try

注解

PublicationName 属性是读/写属性,因此需要在创建对象之前对其进行设置。

PublicationName在调用该方法以在服务器上创建项目之前Create,必须设置该属性。 尝试为现有项目设置此属性会生成异常。

PublicationName该属性可由发布服务器和订阅服务器 (的固定服务器角色的成员sysadmin检索,以便重新发布订阅服务器) 。 也可以由发布数据库上的固定数据库角色的成员 db_owner 以及属于 PAL 成员的用户检索它。 对于对象 MergeArticle ,也可以由分发服务器上的固定数据库角色的成员 replmonitor 检索此属性。

属性 PublicationName 可由发布服务器上的固定服务器角色的成员 sysadmin 设置。 也可以由发布数据库上的固定数据库角色的成员 db_owner 设置。

检索 PublicationName 相当于执行事务复制或快照复制 的 Transact-SQL) sp_helparticle ( ,或者执行用于合并复制 的 Transact-SQL) sp_helpmergearticle (

设置 PublicationName 相当于执行事务复制或快照复制 的 Transact-SQL) sp_addarticle ( ,或者执行用于合并复制 的 Transact-SQL) sp_addmergearticle (

适用于