MergeSynchronizationAgent 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供 Replication 合併代理程式 的功能。
public ref class MergeSynchronizationAgent : MarshalByRefObject, IDisposable, Microsoft::SqlServer::Replication::IMergeSynchronizationAgent
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComSourceInterfaces(typeof(Microsoft.SqlServer.Replication.IComStatusEvent))]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.Guid("ee5ee47e-6d29-448f-b2d2-f8e632db336a")]
public class MergeSynchronizationAgent : MarshalByRefObject, IDisposable, Microsoft.SqlServer.Replication.IMergeSynchronizationAgent
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComSourceInterfaces(typeof(Microsoft.SqlServer.Replication.IComStatusEvent))>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Runtime.InteropServices.Guid("ee5ee47e-6d29-448f-b2d2-f8e632db336a")>]
type MergeSynchronizationAgent = class
inherit MarshalByRefObject
interface IDisposable
interface IMergeSynchronizationAgent
Public Class MergeSynchronizationAgent
Inherits MarshalByRefObject
Implements IDisposable, IMergeSynchronizationAgent
- 繼承
-
MergeSynchronizationAgent
- 屬性
- 實作
範例
在以下範例中,Synchronize該方法在從屬性存取SynchronizationAgent的類別實例MergeSynchronizationAgent中被呼叫,以同步推送訂閱。
// Define the server, publication, and database names.
string subscriberName = subscriberInstance;
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";
// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
MergeSubscription subscription;
try
{
// Connect to the Publisher
conn.Connect();
// Define the subscription.
subscription = new MergeSubscription();
subscription.ConnectionContext = conn;
subscription.DatabaseName = publicationDbName;
subscription.PublicationName = publicationName;
subscription.SubscriptionDBName = subscriptionDbName;
subscription.SubscriberName = subscriberName;
// If the push subscription exists, start the synchronization.
if (subscription.LoadProperties())
{
// Check that we have enough metadata to start the agent.
if (subscription.SubscriberSecurity != null)
{
// Synchronously start the Merge Agent for the subscription.
subscription.SynchronizationAgent.Synchronize();
}
else
{
throw new ApplicationException("There is insufficent metadata to " +
"synchronize the subscription. Recreate the subscription with " +
"the agent job or supply the required agent properties at run time.");
}
}
else
{
// Do something here if the push subscription does not exist.
throw new ApplicationException(String.Format(
"The subscription to '{0}' does not exist on {1}",
publicationName, subscriberName));
}
}
catch (Exception ex)
{
// Implement appropriate error handling here.
throw new ApplicationException("The subscription could not be synchronized.", ex);
}
finally
{
conn.Disconnect();
}
' Define the server, publication, and database names.
Dim subscriberName As String = subscriberInstance
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"
' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
Dim subscription As MergeSubscription
Try
' Connect to the Publisher
conn.Connect()
' Define the subscription.
subscription = New MergeSubscription()
subscription.ConnectionContext = conn
subscription.DatabaseName = publicationDbName
subscription.PublicationName = publicationName
subscription.SubscriptionDBName = subscriptionDbName
subscription.SubscriberName = subscriberName
' If the push subscription exists, start the synchronization.
If subscription.LoadProperties() Then
' Check that we have enough metadata to start the agent.
If Not subscription.SubscriberSecurity Is Nothing Then
' Synchronously start the Merge Agent for the subscription.
' Log agent messages to an output file.
subscription.SynchronizationAgent.Output = "mergeagent.log"
subscription.SynchronizationAgent.OutputVerboseLevel = 2
subscription.SynchronizationAgent.Synchronize()
Else
Throw New ApplicationException("There is insufficent metadata to " + _
"synchronize the subscription. Recreate the subscription with " + _
"the agent job or supply the required agent properties at run time.")
End If
Else
' Do something here if the push subscription does not exist.
Throw New ApplicationException(String.Format( _
"The subscription to '{0}' does not exist on {1}", _
publicationName, subscriberName))
End If
Catch ex As Exception
' Implement appropriate error handling here.
Throw New ApplicationException("The subscription could not be synchronized.", ex)
Finally
conn.Disconnect()
End Try
在以下範例中,該類別的實例 MergeSynchronizationAgent 用於同步合併訂閱。 由於拉取訂閱是以 為 的值falseCreateSyncAgentByDefault創建,因此必須提供額外的屬性。
// Define the server, publication, and database names.
string subscriberName = subscriberInstance;
string publisherName = publisherInstance;
string distributorName = distributorInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";
string hostname = @"adventure-works\garrett1";
string webSyncUrl = "https://" + publisherInstance + "/SalesOrders/replisapi.dll";
// Create a connection to the Subscriber.
ServerConnection conn = new ServerConnection(subscriberName);
MergePullSubscription subscription;
MergeSynchronizationAgent agent;
try
{
// Connect to the Subscriber.
conn.Connect();
// Define the pull subscription.
subscription = new MergePullSubscription();
subscription.ConnectionContext = conn;
subscription.DatabaseName = subscriptionDbName;
subscription.PublisherName = publisherName;
subscription.PublicationDBName = publicationDbName;
subscription.PublicationName = publicationName;
// If the pull subscription exists, then start the synchronization.
if (subscription.LoadProperties())
{
// Get the agent for the subscription.
agent = subscription.SynchronizationAgent;
// Check that we have enough metadata to start the agent.
if (agent.PublisherSecurityMode == null)
{
// Set the required properties that could not be returned
// from the MSsubscription_properties table.
agent.PublisherSecurityMode = SecurityMode.Integrated;
agent.DistributorSecurityMode = SecurityMode.Integrated;
agent.Distributor = publisherName;
agent.HostName = hostname;
// Set optional Web synchronization properties.
agent.UseWebSynchronization = true;
agent.InternetUrl = webSyncUrl;
agent.InternetSecurityMode = SecurityMode.Standard;
agent.InternetLogin = winLogin;
agent.InternetPassword = winPassword;
}
// Enable agent output to the console.
agent.OutputVerboseLevel = 1;
agent.Output = "";
// Synchronously start the Merge Agent for the subscription.
agent.Synchronize();
}
else
{
// Do something here if the pull subscription does not exist.
throw new ApplicationException(String.Format(
"A subscription to '{0}' does not exist on {1}",
publicationName, subscriberName));
}
}
catch (Exception ex)
{
// Implement appropriate error handling here.
throw new ApplicationException("The subscription could not be " +
"synchronized. Verify that the subscription has " +
"been defined correctly.", ex);
}
finally
{
conn.Disconnect();
}
' Define the server, publication, and database names.
Dim subscriberName As String = subscriberInstance
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"
Dim hostname As String = "adventure-works\garrett1"
Dim webSyncUrl As String = "https://" + publisherInstance + "/SalesOrders/replisapi.dll"
' Create a connection to the Subscriber.
Dim conn As ServerConnection = New ServerConnection(subscriberName)
Dim subscription As MergePullSubscription
Dim agent As MergeSynchronizationAgent
Try
' Connect to the Subscriber.
conn.Connect()
' Define the pull subscription.
subscription = New MergePullSubscription()
subscription.ConnectionContext = conn
subscription.DatabaseName = subscriptionDbName
subscription.PublisherName = publisherName
subscription.PublicationDBName = publicationDbName
subscription.PublicationName = publicationName
' If the pull subscription exists, then start the synchronization.
If subscription.LoadProperties() Then
' Get the agent for the subscription.
agent = subscription.SynchronizationAgent
' Check that we have enough metadata to start the agent.
If agent.PublisherSecurityMode = Nothing Then
' Set the required properties that could not be returned
' from the MSsubscription_properties table.
agent.PublisherSecurityMode = SecurityMode.Integrated
agent.Distributor = publisherInstance
agent.DistributorSecurityMode = SecurityMode.Integrated
agent.HostName = hostname
' Set optional Web synchronization properties.
agent.UseWebSynchronization = True
agent.InternetUrl = webSyncUrl
agent.InternetSecurityMode = SecurityMode.Standard
agent.InternetLogin = winLogin
agent.InternetPassword = winPassword
End If
' Enable agent logging to the console.
agent.OutputVerboseLevel = 1
agent.Output = ""
' Synchronously start the Merge Agent for the subscription.
agent.Synchronize()
Else
' Do something here if the pull subscription does not exist.
Throw New ApplicationException(String.Format( _
"A subscription to '{0}' does not exist on {1}", _
publicationName, subscriberName))
End If
Catch ex As Exception
' Implement appropriate error handling here.
Throw New ApplicationException("The subscription could not be " + _
"synchronized. Verify that the subscription has " + _
"been defined correctly.", ex)
Finally
conn.Disconnect()
End Try
備註
該 MergeSynchronizationAgent 類別支援執行以下複製任務的能力:
同步訂閱。
在同步時,請指定僅執行上傳階段、下載階段,或同時執行兩個階段。
確認訂閱是否包含預期資料。
指定一個不同的快照資料夾,從中套用訂閱的初始快照。
建構函式
| 名稱 | Description |
|---|---|
| MergeSynchronizationAgent() |
建立 MergeSynchronizationAgent 類別的執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| AlternateSynchronizationPartnerCollection |
訂閱時會取得替代同步夥伴。 |
| AltSnapshotFolder |
取得或設定訂閱的備用快照資料夾。 |
| ComErrorCollection |
會收到一組由複製代理產生的錯誤。 |
| Distributor |
取得或設定作為訂閱分發者的 Microsoft SQL Server 實例名稱。 |
| DistributorAddress |
當指定屬性時 DistributorNetwork ,取得或設定用於連接分配器的網路位址。 |
| DistributorEncryptedPassword |
取得或設定經銷商加密密碼。 |
| DistributorLogin |
取得或設定使用 SQL Server 認證連接分發器時使用的登入名稱。 |
| DistributorNetwork |
取得或設定連接分發器時使用的用戶端 Net-Library。 |
| DistributorPassword |
設定使用 SQL Server 認證連接分發器時使用的密碼。 |
| DistributorSecurityMode |
取得或設定連接分電器時使用的安全模式。 |
| DownloadGenerationsPerBatch |
在從 Publisher 下載變更給訂閱者時,會取得或設定單一批次處理的世代數。 層代會定義為每個發行項的邏輯變更群組。 |
| DynamicSnapshotLocation |
取得或設定該訂閱者分割快照的位置。 |
| ExchangeType |
設定同步期間資料交換的方式。 |
| FileTransferType |
接收或設定初始快照檔案如何傳送給訂閱者。 |
| HostName |
取得或設定合併代理程式在評估參數化濾波器時所使用的值,該濾波器使用 HOST_NAME 函數。 |
| InputMessageFile |
取得或設定輸入訊息檔案。 |
| InternetLogin |
透過網際網路驗證連接Publisher時,取得或設定登入名稱,用於網頁同步。 |
| InternetPassword |
設定與網頁同步時所使用的屬性密碼InternetLogin,並透過網際網路驗證連接 Publisher。 |
| InternetProxyLogin |
透過網際網路代理伺服器連接網頁伺服器時,取得或設定用於網頁同步的登入名稱。 |
| InternetProxyPassword |
設定登入密碼,並用於透過網際網路代理伺服器連接網頁伺服器時的網頁同步。 |
| InternetProxyServer |
取得或設定連接網頁伺服器時所使用的網際網路代理伺服器名稱。 |
| InternetSecurityMode |
取得或設定在網頁同步時連接網頁伺服器時所使用的 HTTP 認證方法。 |
| InternetTimeout |
連接網頁伺服器時會接收或設定 HTTP 逾時。 |
| InternetUrl |
取得或設定已設定用於網頁同步的 Web 服務 URL。 |
| LastUpdatedTime |
取得複製代理程式最後一次同步訂閱的時間戳。 |
| LoginTimeout |
取得或設定等待連線建立的最大秒數。 |
| MetadataRetentionCleanup |
取得或設定是否要清理元資料。 |
| Output |
取得或設定代理輸出檔案。 |
| OutputMessageFile |
取得或設定輸入訊息檔案。 |
| OutputVerboseLevel |
取得或設定寫入代理輸出檔案的資訊細節層級。 |
| ProfileName |
取得或設定代理人所使用的設定檔名稱。 |
| Publication |
取得或設定出版品名稱。 |
| Publisher |
取得或設定訂閱的Microsoft SQL Server實例名稱,該實例是訂閱Publisher。 |
| PublisherAddress |
當指定屬性時,取得或設定用於連接 Publisher PublisherNetwork 的網路位址。 |
| PublisherChanges |
取得上次同步時,訂閱者所被套用的 Publisher 變更總數。 |
| PublisherConflicts |
取得上次同步時 Publisher 發生的衝突總數。 |
| PublisherDatabase |
取得或設定出版資料庫名稱。 |
| PublisherEncryptedPassword |
取得或設定出版商加密密碼。 |
| PublisherFailoverPartner |
取得或設定參與與發佈資料庫鏡像會話的 SQL Server 合作夥伴實例。 |
| PublisherLogin |
透過 SQL Server 認證取得或設定連接 Publisher 時使用的登入名稱。 |
| PublisherNetwork |
取得或設定連接Publisher時使用的客戶端 Net-Library。 |
| PublisherPassword |
透過 SQL Server 認證設定連接 Publisher 時使用的密碼。 |
| PublisherSecurityMode |
取得或設定連接 Publisher 時所用的安全模式。 |
| QueryTimeout |
取得或設定允許內部查詢完成的秒數。 |
| SecureDistributorEncryptedPassword |
取得或設定安全分發商加密密碼。 |
| SecurePublisherEncryptedPassword |
取得或設定安全的發佈者加密密碼。 |
| SecureSubscriberEncryptedPassword |
取得或設定安全用戶加密密碼。 |
| Subscriber |
取得或設定 Microsoft SQL Server 的 Subscriber 實例名稱。 |
| SubscriberChanges |
取得上次同步時,在 Publisher 套用的訂閱者變更總數。 |
| SubscriberConflicts |
取得上次同步時 Publisher 發生的衝突總數。 |
| SubscriberDatabase |
取得或設定訂閱資料庫名稱。 |
| SubscriberDatabasePath |
取得或設定訂閱者資料庫路徑。 |
| SubscriberDataSourceType |
取得或設定作為訂閱者所使用的資料來源類型。 |
| SubscriberEncryptedPassword |
取得或設定訂閱者的加密密碼。 |
| SubscriberLogin |
透過 SQL Server 認證,取得或設定連接訂閱者時所使用的登入名稱。 |
| SubscriberPassword |
透過 SQL Server 認證設定連接用戶時所使用的密碼。 |
| SubscriberSecurityMode |
取得或設定連接用戶時使用的安全模式。 |
| SubscriptionType |
會取得或設定訂閱是推送還是拉取訂閱。 |
| SyncToAlternate |
取得或設定同步是否與替代的同步夥伴進行同步。 |
| UploadGenerationsPerBatch |
在從訂閱者上傳變更到Publisher時,取得或設定單批次處理的世代數。 層代會定義為每個發行項的邏輯變更群組。 |
| UseInteractiveResolver |
在對帳過程中是否使用互動式解析器,取得或設定。 |
| UseWebSynchronization |
取得或設定是否使用網頁同步。 |
| Validate |
取得或設定在同步結束時是否對訂閱者資料進行資料驗證。 |
| WorkingDirectory |
取得或設定在使用 FTP 時存取快照檔案的工作目錄。 |
方法
| 名稱 | Description |
|---|---|
| Abort() |
中止同步。 |
| ClearAllTraceFlags() |
清除同步代理使用的所有追蹤標誌。 |
| ClearTraceFlag(Int32) |
清除追蹤標記。 |
| Dispose() |
釋放被 使用的 MergeSynchronizationAgent未管理資源。 |
| Dispose(Boolean) |
釋放類別 MergeSynchronizationAgent 使用的非管理資源,並可選擇性地釋放受管理資源。 |
| EnableTraceFlag(Int32) |
啟用旗幟追蹤功能。 |
| Finalize() |
最終確定代理人。 |
| IsSnapshotRequired() |
連接 Publisher 或 Distributor 及 Subscriber,以判斷下一次代理同步時是否會套用新的快照。 |
| ProcessMessagesAtPublisher() |
在出版商處理訊息。 |
| ProcessMessagesAtSubscriber() |
在訂閱者處處理訊息。 |
| Synchronize() |
啟動 合併代理程式 以同步訂閱。 |
事件
| 名稱 | Description |
|---|---|
| ComStatus |
當 合併代理程式 回傳同步 Com 狀態資訊時會發生。 |
| Status |
當 合併代理程式 回傳同步狀態資訊時,會發生這種情況。 |
適用於
執行緒安全性
任何此類公開靜態(以 Visual Basic 共享)成員皆為執行緒安全。 任何實例成員都不保證具有執行緒安全性。