TransSynchronizationAgent 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供 Replication 散發代理程式 的功能。
public ref class TransSynchronizationAgent : MarshalByRefObject, IDisposable, Microsoft::SqlServer::Replication::ITransSynchronizationAgent
[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("adeda98a-bdfc-4029-b6fb-991d6b468395")]
public class TransSynchronizationAgent : MarshalByRefObject, IDisposable, Microsoft.SqlServer.Replication.ITransSynchronizationAgent
[<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("adeda98a-bdfc-4029-b6fb-991d6b468395")>]
type TransSynchronizationAgent = class
inherit MarshalByRefObject
interface IDisposable
interface ITransSynchronizationAgent
Public Class TransSynchronizationAgent
Inherits MarshalByRefObject
Implements IDisposable, ITransSynchronizationAgent
- 繼承
-
TransSynchronizationAgent
- 屬性
- 實作
範例
在以下範例中,Synchronize該方法在從屬性存取TransSynchronizationAgent的類別實例SynchronizationAgent中被呼叫,以同步推送訂閱。
// Define the server, publication, and database names.
string subscriberName = subscriberInstance;
string publisherName = publisherInstance;
string publicationName = "AdvWorksProductTran";
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";
// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
TransSubscription subscription;
try
{
// Connect to the Publisher.
conn.Connect();
// Define the push subscription.
subscription = new TransSubscription();
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 Distribution 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 = "AdvWorksProductTran"
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 TransSubscription
Try
' Connect to the Publisher.
conn.Connect()
' Define the push subscription.
subscription = New TransSubscription()
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 Distribution 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.")
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
備註
該 TransSynchronizationAgent 類別支援程式同步訂閱與交易型或快照型出版品的能力。
建構函式
| 名稱 | Description |
|---|---|
| TransSynchronizationAgent() |
建立 TransSynchronizationAgent 類別的執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| AltSnapshotFolder |
取得或設定訂閱的備用快照資料夾。 |
| ComErrorCollection |
會收到一組由複製代理產生的錯誤。 |
| Distributor |
取得或設定作為訂閱分發者的 Microsoft SQL Server 實例名稱。 |
| DistributorAddress |
當屬性指定時,取得或設定用於連接分配器的 DistributorNetwork 網路位址。 |
| DistributorEncryptedPassword |
透過 SQL Server 認證取得或設定加密密碼,連接分發商時使用。 |
| DistributorLogin |
透過 SQL Server 認證取得或設定連接分發商時使用的登入名稱。 |
| DistributorNetwork |
取得或設定連接分發商時使用的用戶端 Net-Library。 |
| DistributorPassword |
透過 SQL Server 認證取得或設定連接分發器時使用的密碼。 |
| DistributorSecurityMode |
取得或設定連接分電器時所用的安全模式。 |
| DtsPackageFileName |
取得或設定 Microsoft SQL Server 2000 資料轉換服務(DTS)套件的名稱與路徑,該套件用於在命令列集套用於訂閱者之前轉換。 |
| DtsPackagePassword |
取得或設定用於存取 Microsoft SQL Server 2000 資料轉換服務(DTS)套件的擁有者密碼,該套件由該DtsPackageFileName屬性指定。 |
| FileTransferType |
接收或設定初始快照檔案如何傳送給訂閱者。 |
| HostName |
取得或設定所用的主機名稱。 |
| LastUpdatedTime |
取得複製代理程式最後一次同步訂閱的時間戳。 |
| LoginTimeout |
取得或設定等待連線建立的最大秒數。 |
| MaxDeliveredTransactions |
取得或設定在單一代理執行中套用至訂閱者的最大交易數量。 |
| Output |
取得或設定代理輸出檔案的檔名與路徑。 |
| OutputVerboseLevel |
取得或設定 散發代理程式 在代理輸出檔案中記錄的資訊量。 |
| ProfileName |
取得或設定代理人所使用的設定檔名稱。 |
| Publication |
取得或設定出版品名稱。 |
| Publisher |
取得或設定訂閱的Microsoft SQL Server實例名稱,該實例是訂閱Publisher。 |
| PublisherDatabase |
取得或設定出版資料庫名稱。 |
| QueryTimeout |
取得或設定允許內部查詢完成的秒數。 |
| SecureDistributorEncryptedPassword |
取得或設定分發商的安全加密密碼。 |
| SecureSubscriberEncryptedPassword |
取得或設定訂閱者的安全加密密碼。 |
| SkipErrors |
取得或設定一個以冒號分隔的錯誤編號清單,列出此代理要跳過的錯誤號碼。 |
| Subscriber |
取得或設定 Microsoft SQL Server 的訂閱者實例名稱。 |
| SubscriberDatabase |
取得或設定訂閱資料庫名稱。 |
| SubscriberDatabasePath |
取得或設定訂閱者的資料庫路徑。 |
| SubscriberDataSourceType |
取得或設定作為訂閱者的資料來源類型。 |
| SubscriberEncryptedPassword |
取得或設定用戶的加密密碼。 |
| SubscriberLogin |
透過 SQL Server 認證取得或設定連接用戶時使用的登入名稱。 |
| SubscriberPassword |
透過 SQL Server 認證取得或設定連接用戶時使用的密碼。 |
| SubscriberSecurityMode |
取得或設定連接出版商時所使用的安全模式。 |
| SubscriptionType |
會取得或設定訂閱是推送還是拉取訂閱。 |
| UndeliveredCommands |
會取得未交付指令的數量。 |
| UndeliveredTransactions |
會取得未交付交易的數量。 |
| UseInProcLoader |
在使用者套用快照檔案時,取得或設定一個值,指示是否使用BULK INSERT指令。 |
| WorkingDirectory |
當使用檔案傳輸協定(FTP)時,取得或設定快照檔案可從中存取的工作目錄。 |
方法
| 名稱 | Description |
|---|---|
| Abort() |
中 TransSynchronizationAgent 止手術。 |
| Dispose() |
釋放目前類別實例 TransSynchronizationAgent 所使用的所有資源。 |
| Dispose(Boolean) |
釋放 TransSynchronizationAgent 類別所使用的所有資源。 |
| Finalize() | |
| IsSnapshotRequired() |
連接分配器與用戶,以判斷下一次代理同步時是否會套用新的快照。 |
| Synchronize() |
啟動 散發代理程式 以同步訂閱。 |
事件
| 名稱 | Description |
|---|---|
| ComStatus |
當 散發代理程式 回傳同步 Com 狀態資訊時,會發生這種情況。 |
| Status |
當 散發代理程式 回傳同步狀態資訊時,會發生這種情況。 |
適用於
執行緒安全性
這個 TransSynchronizationAgent 類別不支援多執行緒公寓。 你可以在方法上宣告 [STAThread] 作為應用程式主要入口點的屬性,來指定單執行緒公寓。 這是基於Microsoft Windows的應用程式的預設Microsoft Visual Studio。