共用方式為


檢視及修改出版物屬性

本主題描述如何使用 SQL Server Management Studio、Transact-SQL 或 Replication Management Objects (RMO) 在 SQL Server 2014 中檢視和修改發行集屬性。

本主題內容

開始之前

限制與制約

  • 某些屬性無法在建立發行集之後修改,如果發行集有訂閱,則無法修改其他屬性。 不可修改的屬性會顯示為唯讀。

建議

使用 SQL Server Management Studio

在 [ 發行集屬性 - <發行集> ] 對話框中檢視和修改發行集屬性,此對話框可在 SQL Server Management Studio 和復寫監視器中使用。 如需啟動複寫監視器的詳細資訊,請參閱啟動複寫監視器

在 [ 發行集屬性 - <發行集> ] 對話框中包含以下頁面:

  • [ 一般 ] 頁面包含發行集名稱和描述、資料庫名稱、發行集類型,以及訂閱到期設定。

  • [ 文章 ] 頁面對應於 [新增文章精靈] 中的 [ 文章 ] 頁面。 使用此頁面來新增和刪除文章,以及變更文章的屬性和列篩選。

  • [篩選列] 頁面會對應至 [新增發行集精靈] 中的 [篩選表格列] 頁面。 使用此頁面來新增、編輯和刪除所有類型的發行集的靜態數據列篩選,以及新增、編輯和刪除合併式發行集的參數化數據列篩選和聯結篩選。

  • [ 快照 集] 頁面可讓您指定快照集的格式和位置、是否應該壓縮快照集,以及套用快照集前後要執行的腳本。

  • FTP 快照頁面(適用於快照發行和交易發行,以及適用於運行 SQL Server 2005 之前版本的發行者的合併發行),可讓您指定訂閱者是否可以通過檔案傳輸通訊協定 (FTP) 下載快照檔案。

  • FTP 快照集和因特網頁面(適用於執行 SQL Server 2005 或更新版本的發行者合併式發行集),可讓您指定訂閱者是否可以透過 FTP 下載快照集檔案,以及訂閱者是否可以透過 HTTPS 同步處理訂閱。

  • [ 訂用帳戶選項 ] 頁面可讓您設定套用至所有訂用帳戶的一些選項。 選項會根據發行集的類型而有所不同。

  • [ 發行集存取清單] 頁面可讓您指定哪些登入和群組可以存取發行集。

  • [ 代理程式安全性 ] 頁面可讓您存取執行下列代理程式並聯機到複寫拓撲中計算機之帳戶的設定:所有發行集的快照集代理程式;所有交易式發行集的記錄讀取器代理程式;和允許佇列更新訂閱之交易式發行集的佇列讀取器代理程式。

  • [資料分割] 頁面(適用於執行 SQL Server 2005 或更新版本的發行者合併出版物),可讓您指定發行集中具有參數化過濾器的訂閱者在快照集不可用時是否可以提出要求。 它也可讓您針對一或多個分割區產生快照集,無論是一次還是週期性排程。

在 Management Studio 中檢視和修改發行集屬性

  1. 連線至 Microsoft SQL Server Management Studio 中的發行者,然後展開伺服器節點。

  2. 展開 複寫 資料夾,然後展開 本機發行集 資料夾。

  3. 對發行集按一下滑鼠右鍵,然後按一下 [屬性]。

  4. 必要時修改任何屬性,然後按一下 [確定]

在復寫監視器中檢視和修改發行集屬性

  1. 展開複寫監視器左窗格中的發行者群組,然後展開發行者。

  2. 以滑鼠右鍵按一下出版物,然後點選 屬性

  3. 必要時修改任何屬性,然後按一下 [確定]

使用 Transact-SQL

您可以使用資料庫複寫預存程序,程式化方式修改發行集並傳回其屬性。 您使用的預存程式將取決於發行集的類型。

檢視快照或交易發行項目的屬性

  1. 執行 sp_helppublication,指定出版物名稱作為 @publication 參數。 如果您未指定此參數,則會傳回出版商所有出版物的相關信息。

若要變更快照式或交易式發行集的屬性

  1. 執行 sp_changepublication,指定要在 @property 參數中變更的發行集屬性,並在 @value 參數中指定此屬性的新值。

    備註

    如果變更需要產生新的快照集,您也必須為 @force_invalidate_snapshot 指定 1 的值,而且如果變更需要重新初始化訂閱者,則必須為 @force_reinit_subscription 指定 1 的值。 如需變更時需要新快照集或重新初始化之屬性的詳細資訊,請參閱 變更發行集和發行項屬性

若要檢視合併式發行集的屬性

  1. 執行 sp_helpmergepublication,為 @publication 參數指定發行集的名稱。 如果您未指定此參數,則會傳回出版商所有出版品的相關資料。

變更合併式發行集的屬性

  1. 執行 sp_changemergepublication,指定 @property 參數中要變更的發行集屬性,以及在 @value 參數中指定此屬性的新值。

    備註

    如果變更需要產生新的快照集,您也必須針對@force_invalidate_snapshot指定 1 的值;如果變更需要重新初始化訂閱,則必須針對@force_reinit_subscription指定 1 的值。如需變更時需要新快照集或重新初始化的屬性詳細資訊,請參閱變更發行集和發行項屬性

檢視快照的屬性

  1. 執行 sp_helppublication_snapshot,指定 @publication 參數的發行集名稱。

變更快照的屬性

  1. 執行 sp_changepublication_snapshot,為適當的快照集參數指定一或多個新的快照集屬性。

範例 (Transact-SQL)

這個事務複製範例會傳回發行集的屬性。

DECLARE @myTranPub AS sysname
SET @myTranPub = N'AdvWorksProductTran' 

USE [AdventureWorks2012]
EXEC sp_helppublication @publication = @myTranPub
GO

這個事務複製範例會停用出版物的架構複寫。

DECLARE @publication AS sysname
SET @publication = N'AdvWorksProductTran' 

-- Turn off DDL replication for the transactional publication.
USE [AdventureWorks2012]
EXEC sp_changepublication 
  @publication = @publication, 
  @property = N'replicate_ddl', 
  @value = 0
GO

這個合併式複寫範例會傳回出版物的屬性。

DECLARE @publication AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';

USE [AdventureWorks2012]
EXEC sp_helpmergepublication @publication = @publication;
GO

這個合併複寫範例會停用發行集的結構複寫。

DECLARE @publication AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge'; 

-- Disable DDL replication for the publication.
USE [AdventureWorks2012]
EXEC sp_changemergepublication 
  @publication = @publication, 
  @property = N'replicate_ddl', 
  @value = 0,
  @force_invalidate_snapshot = 0, 
  @force_reinit_subscription = 0;
GO

使用 Replication Management Objects (RMO)

您可以使用複寫管理物件 (RMO) 以程式設計方式修改發行集並存取其屬性。 您用來檢視或修改發行集屬性的 RMO 類別取決於發行集的類型。

檢視或修改快照或交易型發布的屬性

  1. 使用 ServerConnection 類別建立與發行者的連接。

  2. 建立 TransPublication 類別的實例,設定發佈的 NameDatabaseName 屬性,並將 ConnectionContext 屬性設定為步驟 1 中建立的連接。

  3. 呼叫 LoadProperties 方法以取得物件的屬性。 如果此方法傳 false回 ,則表示步驟 2 中的發行集屬性定義不正確或發行集不存在。

  4. (選擇性)若要變更屬性,請為一或多個可設定的屬性設定新的值。 使用邏輯 AND 運算子(在 & Microsoft Visual C# 和 And Microsoft Visual Basic 中),判斷給定的 PublicationAttributes 值是否已設定為 Attributes 屬性。 使用內含邏輯 OR 運算符(在 Visual C# 中為 |,在 Visual Basic 中為 Or),以及專屬邏輯 OR 運算子 (在 Visual C# 中為 ^,在 Visual Basic 中為 Xor)來變更 Attributes 屬性的 PublicationAttributes 值。

  5. (選擇性)如果您為 指定的值trueCachePropertyChanges,請呼叫 CommitPropertyChanges 方法,以認可伺服器上的變更。 如果您為 指定的值 falseCachePropertyChanges (預設值),則會立即將變更傳送至伺服器。

檢視或修改合併式發行集的屬性

  1. 使用 ServerConnection 類別建立與發行者的連接。

  2. 建立 MergePublication 類別的實例,設定 NameDatabaseName 屬性以發行集,並將 ConnectionContext 屬性設定為步驟 1 中建立的連接。

  3. 呼叫 LoadProperties 方法以取得物件的屬性。 如果此方法傳 false回 ,則表示步驟 2 中的發行集屬性定義不正確或發行集不存在。

  4. (選擇性)若要變更屬性,請為一或多個可設定的屬性設定新的值。 使用邏輯 AND 運算子(在 Visual C# 中的 & 和在 Visual Basic 中的 And),判斷 Attributes 屬性是否已設定為指定的 PublicationAttributes 值。 使用內含邏輯 OR 運算符(| 在 Visual C# 中和 Or 在 Visual Basic 中),以及排他性邏輯 OR 運算符(^ 在 Visual C# 中和 Xor 在 Visual Basic 中)來變更 PublicationAttributes 屬性的 Attributes 值。

  5. (選擇性)如果您為 指定的值trueCachePropertyChanges,請呼叫 CommitPropertyChanges 方法,以認可伺服器上的變更。 如果您為 指定的值 falseCachePropertyChanges (預設值),則會立即將變更傳送至伺服器。

範例 (RMO)

本範例會設定交易式發行集的發行集屬性。 變更會被快取,直到使用者明確將其傳送至伺服器。

// Define the server, database, and publication names
string publisherName = publisherInstance;
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks2012";

TransPublication publication;

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

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

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

    // Explicitly enable caching of property changes on this object.
    publication.CachePropertyChanges = true;

    // If we can't get the properties for this publication, 
    // throw an application exception.
    if (publication.LoadProperties())
    {
        // Enable support for push subscriptions and disable support 
        // for pull subscriptions.
        if ((publication.Attributes & PublicationAttributes.AllowPull) != 0)
        {
            publication.Attributes ^= PublicationAttributes.AllowPull;
        }
        if ((publication.Attributes & PublicationAttributes.AllowPush) == 0)
        {
            publication.Attributes |= PublicationAttributes.AllowPush;
        }

        // Send changes to the server.
        publication.CommitPropertyChanges();
    }
    else
    {
        throw new ApplicationException(String.Format(
            "Settings could not be retrieved for the publication. " +
            "Ensure that the publication {0} exists on {1}.",
            publicationName, publisherName));
    }
}
catch (Exception ex)
{
    // Do error handling here.
    throw new ApplicationException(
        "The publication property could not be changed.", ex);
}
finally
{
    conn.Disconnect();
}
' Define the server, database, and publication names
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks2012"

Dim publication As TransPublication

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

Try
    ' Connect to the Publisher.
    conn.Connect()

    ' Set the required properties for the publication.
    publication = New TransPublication()
    publication.ConnectionContext = conn
    publication.Name = publicationName
    publication.DatabaseName = publicationDbName

    ' Explicitly enable caching of property changes on this object.
    publication.CachePropertyChanges = True

    ' If we can't get the properties for this publication, 
    ' throw an application exception.
    If publication.LoadProperties() Then
        ' Enable support for push subscriptions and disable support 
        ' for pull subscriptions.
        If (publication.Attributes And PublicationAttributes.AllowPull) <> 0 Then
            publication.Attributes = publication.Attributes _
            Xor PublicationAttributes.AllowPull
        End If
        If (publication.Attributes And PublicationAttributes.AllowPush) = 0 Then
            publication.Attributes = publication.Attributes _
            Or PublicationAttributes.AllowPush
        End If

        ' Send changes to the server.
        publication.CommitPropertyChanges()
    Else
        Throw New ApplicationException(String.Format( _
         "Settings could not be retrieved for the publication. " + _
         "Ensure that the publication {0} exists on {1}.", _
         publicationName, publisherName))
    End If
Catch ex As Exception
    ' Do error handling here.
    Throw New ApplicationException( _
        "The publication property could not be changed.", ex)
Finally
    conn.Disconnect()
End Try

此範例會停用合併發行的 DDL 複寫。

// Define the server, database, and publication names
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks2012";

MergePublication publication;

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

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

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


    // If we can't get the properties for this merge publication, then throw an application exception.
    if (publication.LoadProperties())
    {
        // If DDL replication is currently enabled, disable it.
        if (publication.ReplicateDdl == DdlReplicationOptions.All)
        {
            publication.ReplicateDdl = DdlReplicationOptions.None;
        }
        else
        {
            publication.ReplicateDdl = DdlReplicationOptions.All;
        }
    }
    else
    {
        throw new ApplicationException(String.Format(
            "Settings could not be retrieved for the publication. " +
            "Ensure that the publication {0} exists on {1}.",
            publicationName, publisherName));
    }
}
catch (Exception ex)
{
    // Do error handling here.
    throw new ApplicationException(
        "The publication property could not be changed.", ex);
}
finally
{
    conn.Disconnect();
}
' Define the server, database, and publication names
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2012"

Dim publication As MergePublication

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

Try
    ' Connect to the Publisher.
    conn.Connect()

    ' Set the required properties for the publication.
    publication = New MergePublication()
    publication.ConnectionContext = conn
    publication.Name = publicationName
    publication.DatabaseName = publicationDbName

    ' If we can't get the properties for this merge publication, then throw an application exception.
    If publication.LoadProperties() Then
        ' If DDL replication is currently enabled, disable it.
        If publication.ReplicateDdl = DdlReplicationOptions.All Then
            publication.ReplicateDdl = DdlReplicationOptions.None
        Else
            publication.ReplicateDdl = DdlReplicationOptions.All
        End If
    Else
        Throw New ApplicationException(String.Format( _
         "Settings could not be retrieved for the publication. " + _
         "Ensure that the publication {0} exists on {1}.", _
         publicationName, publisherName))
    End If
Catch ex As Exception
    ' Do error handling here.
    Throw New ApplicationException( _
        "The publication property could not be changed.", ex)
Finally
    conn.Disconnect()
End Try

另請參閱

發行資料和資料庫物件
變更出版物和文章屬性
對發行的資料庫進行資料庫結構變更
復寫系統預存程式概念
將文章新增至出版物並移除文章
使用複寫監視器檢視資訊和執行工作
檢視和修改發行項屬性