次の方法で共有


Article.PublicationName プロパティ

アーティクルが属するパブリケーションの名前を取得します。値の設定も可能です。

名前空間:  Microsoft.SqlServer.Replication
アセンブリ:  Microsoft.SqlServer.Rmo (Microsoft.SqlServer.Rmo.dll)

構文

'宣言
Public Property PublicationName As String 
    Get 
    Set
'使用
Dim instance As Article 
Dim value As String 

value = instance.PublicationName

instance.PublicationName = value
public string PublicationName { get; set; }
public:
property String^ PublicationName {
    String^ get ();
    void set (String^ value);
}
member PublicationName : string with get, set
function get PublicationName () : String 
function set PublicationName (value : String)

プロパティ値

型: System.String
パブリケーションの名前です。

例外

例外 条件
ApplicationException

既存のアーティクルに PublicationName プロパティを設定しようとすると発生します。

ArgumentException

PublicationName プロパティに nullNULL 参照 (Visual Basic では Nothing) 値、nullNULL 参照 (Visual Basic では Nothing) 文字を含む値、または 128 Unicode 文字より長い値を設定すると発生します。

説明

PublicationName プロパティは、読み取り/書き込みプロパティです。よって、オブジェクトの作成前にこのプロパティを設定する必要があります。

Create メソッドを呼び出してサーバー上にアーティクルを作成する前に、PublicationName プロパティを設定する必要があります。 既存のアーティクルにこのプロパティを設定しようとすると、例外が生成されます。

PublicationName プロパティを取得できるのは、パブリッシャー側およびサブスクライバー側 (サブスクライバーを再パブリッシュする場合) の固定サーバー ロール sysadmin のメンバーです。 また、パブリケーション データベースの固定データベース ロール db_owner のメンバー、および PAL のメンバーも取得できます。 MergeArticle オブジェクトの場合は、ディストリビューター側の固定データベース ロール replmonitor のメンバーも取得できます。

PublicationName プロパティを設定できるのは、パブリッシャー側の固定サーバー ロール sysadmin のメンバーです。 また、パブリケーション データベースの固定データベース ロール db_owner のメンバーも設定できます。

PublicationName を取得すると、sp_helparticle (Transact-SQL) (トランザクション レプリケーションまたはスナップショット レプリケーションの場合) または sp_helpmergearticle (Transact-SQL) (マージ レプリケーションの場合) を実行したのと同じことになります。

PublicationName を設定すると、sp_addarticle (Transact-SQL) (トランザクション レプリケーションまたはスナップショット レプリケーションの場合) または sp_addmergearticle (Transact-SQL) (マージ レプリケーションの場合) を実行したのと同じことになります。

使用例

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

関連項目

参照

Article クラス

Microsoft.SqlServer.Replication 名前空間