语言

Article.DatabaseName 属性

定义

获取或设置包含文章中数据和对象的数据库名称。

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

属性值

发布数据库的名称。

例外

当你尝试为现有文章设置 DatabaseName 属性时。

当你将属性null设置为DatabaseName一个值、一个带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

注解

DatabaseName 属性是读写属性。

在调用该方法以创建服务器文章之前,必须先设置CreateDatabaseName属性。 尝试为现有条目设置该属性时会产生异常。

对于非 SQL Server 发布,该DatabaseName属性必须设置为分发数据库的名称。

DatabaseName该属性可由固定sysadmin服务器角色的成员在Publisher和Subscriber(用于重新发布Subscribers)处检索。 该文件也可以由出版物 db_owner 数据库中固定数据库角色的成员以及PAL成员用户检索。 对于对象 MergeArticle ,该属性也可以被分发器上固定数据库角色的成员 replmonitor 检索。

DatabaseName属性可以由 Publisher 固定服务器角色的成员sysadmin设置。 也可以由发表 db_owner 数据库中固定数据库角色的成员设置。

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

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

适用于

另请参阅