MergePublication 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表合併出版。
public ref class MergePublication sealed : Microsoft::SqlServer::Replication::Publication
public sealed class MergePublication : Microsoft.SqlServer.Replication.Publication
type MergePublication = class
inherit Publication
Public NotInheritable Class MergePublication
Inherits Publication
- 繼承
範例
此範例會產生合併出版。
// Set the Publisher, publication database, and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks2012";
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 precomputed partitions.
publication.PartitionGroupsOption = PartitionGroupsOption.True;
// 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;
// Enable Subscribers to request snapshot generation and filtering.
publication.Attributes |= PublicationAttributes.AllowSubscriberInitiatedSnapshot;
publication.Attributes |= PublicationAttributes.DynamicFilters;
// Enable pull and push subscriptions.
publication.Attributes |= PublicationAttributes.AllowPull;
publication.Attributes |= PublicationAttributes.AllowPush;
if (!publication.IsExistingObject)
{
// Create the merge publication.
publication.Create();
// Create a Snapshot Agent job for the publication.
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();
}
' Set the Publisher, publication database, and publication names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2012"
Dim publicationDb As ReplicationDatabase
Dim publication As MergePublication
' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
Try
' Connect to the Publisher.
conn.Connect()
' Enable the database for merge publication.
publicationDb = New ReplicationDatabase(publicationDbName, conn)
If publicationDb.LoadProperties() Then
If Not publicationDb.EnabledMergePublishing Then
publicationDb.EnabledMergePublishing = True
End If
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))
End If
' Set the required properties for the merge publication.
publication = New MergePublication()
publication.ConnectionContext = conn
publication.Name = publicationName
publication.DatabaseName = publicationDbName
' Enable precomputed partitions.
publication.PartitionGroupsOption = PartitionGroupsOption.True
' 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
' Enable Subscribers to request snapshot generation and filtering.
publication.Attributes = publication.Attributes Or _
PublicationAttributes.AllowSubscriberInitiatedSnapshot
publication.Attributes = publication.Attributes Or _
PublicationAttributes.DynamicFilters
' Enable pull and push subscriptions
publication.Attributes = publication.Attributes Or _
PublicationAttributes.AllowPull
publication.Attributes = publication.Attributes Or _
PublicationAttributes.AllowPush
If Not publication.IsExistingObject Then
' Create the merge publication.
publication.Create()
' Create a Snapshot Agent job for the publication.
publication.CreateSnapshotAgent()
Else
Throw New ApplicationException(String.Format( _
"The {0} publication already exists.", publicationName))
End If
Catch ex As Exception
' Implement custom application error handling here.
Throw New ApplicationException(String.Format( _
"The publication {0} could not be created.", publicationName), ex)
Finally
conn.Disconnect()
End Try
此範例改變合併出版的屬性。
// 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
此範例刪除合併出版品。
// Define the Publisher, publication database,
// and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks2012";
MergePublication publication;
ReplicationDatabase publicationDb;
// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
try
{
// Connect to the Publisher.
conn.Connect();
// Set the required properties for the merge publication.
publication = new MergePublication();
publication.ConnectionContext = conn;
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
// Delete the publication, if it exists and has no subscriptions.
if (publication.LoadProperties() && !publication.HasSubscription)
{
publication.Remove();
}
else
{
// Do something here if the publication does not exist
// or has subscriptions.
throw new ApplicationException(String.Format(
"The publication {0} could not be deleted. " +
"Ensure that the publication exists and that all " +
"subscriptions have been deleted.",
publicationName, publisherName));
}
// If no other merge publications exists,
// disable publishing on the database.
publicationDb = new ReplicationDatabase(publicationDbName, conn);
if (publicationDb.LoadProperties())
{
if (publicationDb.MergePublications.Count == 0 && publicationDb.EnabledMergePublishing)
{
publicationDb.EnabledMergePublishing = false;
}
}
else
{
// Do something here if the database does not exist.
throw new ApplicationException(String.Format(
"The database {0} does not exist on {1}.",
publicationDbName, publisherName));
}
}
catch (Exception ex)
{
// Implement application error handling here.
throw new ApplicationException(String.Format(
"The publication {0} could not be deleted.",
publicationName), ex);
}
finally
{
conn.Disconnect();
}
' Define the Publisher, publication database,
' and publication names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2012"
Dim publication As MergePublication
Dim publicationDb As ReplicationDatabase
' 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 merge publication.
publication = New MergePublication()
publication.ConnectionContext = conn
publication.Name = publicationName
publication.DatabaseName = publicationDbName
' Delete the publication, if it exists and has no subscriptions.
If (publication.LoadProperties() And Not publication.HasSubscription) Then
publication.Remove()
Else
' Do something here if the publication does not exist
' or has subscriptions.
Throw New ApplicationException(String.Format( _
"The publication {0} could not be deleted. " + _
"Ensure that the publication exists and that all " + _
"subscriptions have been deleted.", _
publicationName, publisherName))
End If
' If no other merge publications exists,
' disable publishing on the database.
publicationDb = New ReplicationDatabase(publicationDbName, conn)
If publicationDb.LoadProperties() Then
If publicationDb.MergePublications.Count = 0 _
And publicationDb.EnabledMergePublishing Then
publicationDb.EnabledMergePublishing = False
End If
Else
' Do something here if the database does not exist.
Throw New ApplicationException(String.Format( _
"The database {0} does not exist on {1}.", _
publicationDbName, publisherName))
End If
Catch ex As Exception
' Implement application error handling here.
Throw New ApplicationException(String.Format( _
"The publication {0} could not be deleted.", _
publicationName), ex)
Finally
conn.Disconnect()
End Try
備註
線程安全性
任何此類的公開靜態(SharedMicrosoft Visual Basic)成員對多執行緒操作都是安全的。 任何實例成員都不保證具有執行緒安全性。
建構函式
| 名稱 | Description |
|---|---|
| MergePublication() |
建立 MergePublication 類別的新實例。 |
| MergePublication(String, String, ServerConnection, Boolean) |
建立該MergePublication類別的實例,指定是否應該預設建立 快照集代理程式 工作。 |
| MergePublication(String, String, ServerConnection) |
初始化一個新的類別實例MergePublication,並以指定名稱、資料庫及與 Publisher 的連線。 |
屬性
| 名稱 | Description |
|---|---|
| AltSnapshotFolder |
取得或設定出版物的替代快照檔案位置。 (繼承來源 Publication) |
| Attributes |
取得或設定出版屬性。 (繼承來源 Publication) |
| AutomaticReinitializationPolicy |
當訂閱因出版變更而重新初始化時,Publisher的變更是否會上傳到Publisher。 |
| CachePropertyChanges |
取得或設定是快取複製屬性的變更,還是立即套用。 (繼承來源 ReplicationObject) |
| CompatibilityLevel |
取得或設定最早可訂閱合併發佈的 Microsoft SQL Server 版本。 |
| ConflictRetention |
取得或設定衝突資料列在衝突資料表中保留的天數。 (繼承來源 Publication) |
| ConnectionContext |
取得或設定連接到 Microsoft SQL Server 實例。 (繼承來源 ReplicationObject) |
| CreateSnapshotAgentByDefault |
如果 快照集代理程式 工作在建立發佈時自動加入,則會被設定或 get。 (繼承來源 Publication) |
| DatabaseName |
取得或設定出版資料庫名稱。 (繼承來源 Publication) |
| Description |
取得或設定出版物的文字描述。 (繼承來源 Publication) |
| FtpAddress |
取得或設定檔案傳輸協定(FTP)伺服器電腦的位址,以支援允許透過 FTP 訂閱初始化的出版品。 (繼承來源 Publication) |
| FtpLogin |
取得或設定登入帳號,用於連接檔案傳輸協定(FTP)伺服器,適用於允許透過 FTP 初始化訂閱的出版。 (繼承來源 Publication) |
| FtpPassword |
設定用於連接檔案傳輸協定(FTP)伺服器的登入密碼,適用於允許透過 FTP 初始化訂閱的出版品。 (繼承來源 Publication) |
| FtpPort |
取得或設定檔案傳輸協定(FTP)伺服器電腦的埠,以支援允許透過 FTP 訂閱初始化的發佈。 (繼承來源 Publication) |
| FtpSubdirectory |
在檔案傳輸協定(FTP)伺服器電腦上取得或設定允許透過 FTP 訂閱初始化的出版品子目錄。 (繼承來源 Publication) |
| HasSubscription |
查看該出版物是否有一個或多個訂閱。 (繼承來源 Publication) |
| IsExistingObject |
它會判斷該物件是否存在於伺服器上。 (繼承來源 ReplicationObject) |
| MaxConcurrentDynamicSnapshots |
當發佈有參數化列過濾器時,能取得或設定在產生資料快照時,最多同時支援的 快照集代理程式 會話數量。 |
| MaxConcurrentMerge |
取得或設定最多可與發佈同步的合併代理數量。 |
| MergeArticles |
取得合併出版物中現有的文章。 |
| MergeSubscriptions |
訂閱屬於合併出版物的訂閱。 |
| Name |
取得或設定出版品名稱。 (繼承來源 Publication) |
| PartitionGroupsOption |
取得或設定是否應使用預先計算的分割區來優化同步過程。 |
| PostSnapshotScript |
取得或設定初始快照套用後執行的 Transact-SQL 腳本檔案名稱及完整路徑。 (繼承來源 Publication) |
| PreSnapshotScript |
取得或設定一個 Transact-SQL 腳本檔案的名稱及完整路徑,該檔案在初始快照套用給訂閱者之前執行。 (繼承來源 Publication) |
| Priority |
獲得出版的優先權。 |
| PubId |
獲得唯一識別該出版品的價值。 (繼承來源 Publication) |
| ReplicateDdl |
取得或設定資料定義語言(DDL)的複寫選項,以判斷是否被複製DDL變更。 (繼承來源 Publication) |
| RetentionPeriod |
當訂閱未與出版品同步時,它會取得或設定訂閱到期前的期限。 (繼承來源 Publication) |
| RetentionPeriodUnit |
取得或設定該性質所表達 RetentionPeriodUnit 的單位。 |
| SecureFtpPassword |
為登入帳號設定密碼(作為 SecureString 物件),用於連接允許透過 FTP 初始化訂閱的發佈檔案傳輸協定(FTP)伺服器。 (繼承來源 Publication) |
| SnapshotAgentExists |
是否存在 SQL Server Agent 工作以產生本出版的初始快照。 (繼承來源 Publication) |
| SnapshotAvailable |
取得或設定一個值,指示本出版物的快照檔案是否已產生並可用以初始化訂閱者。 |
| SnapshotGenerationAgentProcessSecurity |
取得一個物件,設定 Windows 帳號,讓 快照集代理程式 工作執行。 (繼承來源 Publication) |
| SnapshotGenerationAgentPublisherSecurity |
取得 快照集代理程式 用來連接 Publisher 的安全上下文。 (繼承來源 Publication) |
| SnapshotJobId |
取得目前出版品的 快照集代理程式 工作 ID。 (繼承來源 Publication) |
| SnapshotMethod |
取得或設定初始快照的資料檔案格式。 (繼承來源 Publication) |
| SnapshotSchedule |
取得一個物件,設定當前發佈的 快照集代理程式 排程。 (繼承來源 Publication) |
| SqlServerName |
取得該物件所連接的 Microsoft SQL Server 實例名稱。 (繼承來源 ReplicationObject) |
| Status |
取得或設定出版品的狀態。 (繼承來源 Publication) |
| Type |
取得或決定出版類型。 (繼承來源 Publication) |
| UserData |
取得或設定一個物件屬性,讓使用者能將自己的資料附加到物件上。 (繼承來源 ReplicationObject) |
| UsesHostName |
會得到一個值,表示合併出版是否有參數化的列過濾器,該過濾器使用 HOST_NAME 函數來評估分割區。 |
| ValidateSubscriberInfo |
取得或設定用於定義已發佈資料訂閱者分割的函式,當使用參數化列過濾器時。 |
| WebSynchronizationUrl |
取得或設定與網頁同步時使用的網址。 |