TransPullSubscription 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表對交易性出版品的拉取訂閱。
public ref class TransPullSubscription sealed : Microsoft::SqlServer::Replication::PullSubscription
public sealed class TransPullSubscription : Microsoft.SqlServer.Replication.PullSubscription
type TransPullSubscription = class
inherit PullSubscription
Public NotInheritable Class TransPullSubscription
Inherits PullSubscription
- 繼承
範例
// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksProductTran";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";
//Create connections to the Publisher and Subscriber.
ServerConnection subscriberConn = new ServerConnection(subscriberName);
ServerConnection publisherConn = new ServerConnection(publisherName);
// Create the objects that we need.
TransPublication publication;
TransPullSubscription subscription;
try
{
// Connect to the Publisher and Subscriber.
subscriberConn.Connect();
publisherConn.Connect();
// Ensure that the publication exists and that
// it supports pull subscriptions.
publication = new TransPublication();
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
publication.ConnectionContext = publisherConn;
if (publication.IsExistingObject)
{
if ((publication.Attributes & PublicationAttributes.AllowPull) == 0)
{
publication.Attributes |= PublicationAttributes.AllowPull;
}
// Define the pull subscription.
subscription = new TransPullSubscription();
subscription.ConnectionContext = subscriberConn;
subscription.PublisherName = publisherName;
subscription.PublicationName = publicationName;
subscription.PublicationDBName = publicationDbName;
subscription.DatabaseName = subscriptionDbName;
// Specify the Windows login credentials for the Distribution Agent job.
subscription.SynchronizationAgentProcessSecurity.Login = winLogin;
subscription.SynchronizationAgentProcessSecurity.Password = winPassword;
// Make sure that the agent job for the subscription is created.
subscription.CreateSyncAgentByDefault = true;
// By default, subscriptions to transactional publications are synchronized
// continuously, but in this case we only want to synchronize on demand.
subscription.AgentSchedule.FrequencyType = ScheduleFrequencyType.OnDemand;
// Create the pull subscription at the Subscriber.
subscription.Create();
Boolean registered = false;
// Verify that the subscription is not already registered.
foreach (TransSubscription existing
in publication.EnumSubscriptions())
{
if (existing.SubscriberName == subscriberName
&& existing.SubscriptionDBName == subscriptionDbName)
{
registered = true;
}
}
if (!registered)
{
// Register the subscription with the Publisher.
publication.MakePullSubscriptionWellKnown(
subscriberName, subscriptionDbName,
SubscriptionSyncType.Automatic,
TransSubscriberType.ReadOnly);
}
}
else
{
// Do something here if the publication does not exist.
throw new ApplicationException(String.Format(
"The publication '{0}' does not exist on {1}.",
publicationName, publisherName));
}
}
catch (Exception ex)
{
// Implement the appropriate error handling here.
throw new ApplicationException(String.Format(
"The subscription to {0} could not be created.", publicationName), ex);
}
finally
{
subscriberConn.Disconnect();
publisherConn.Disconnect();
}
' Define the Publisher, publication, and databases.
Dim publicationName As String = "AdvWorksProductTran"
Dim publisherName As String = publisherInstance
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"
'Create connections to the Publisher and Subscriber.
Dim subscriberConn As ServerConnection = New ServerConnection(subscriberName)
Dim publisherConn As ServerConnection = New ServerConnection(publisherName)
' Create the objects that we need.
Dim publication As TransPublication
Dim subscription As TransPullSubscription
Try
' Connect to the Publisher and Subscriber.
subscriberConn.Connect()
publisherConn.Connect()
' Ensure that the publication exists and that
' it supports pull subscriptions.
publication = New TransPublication()
publication.Name = publicationName
publication.DatabaseName = publicationDbName
publication.ConnectionContext = publisherConn
If publication.IsExistingObject Then
If (publication.Attributes And PublicationAttributes.AllowPull) = 0 Then
publication.Attributes = publication.Attributes _
Or PublicationAttributes.AllowPull
End If
' Define the pull subscription.
subscription = New TransPullSubscription()
subscription.ConnectionContext = subscriberConn
subscription.PublisherName = publisherName
subscription.PublicationName = publicationName
subscription.PublicationDBName = publicationDbName
subscription.DatabaseName = subscriptionDbName
subscription.Description = "Pull subscription to " + publicationDbName _
+ " on " + subscriberName + "."
' Specify the Windows login credentials for the Distribution Agent job.
subscription.SynchronizationAgentProcessSecurity.Login = winLogin
subscription.SynchronizationAgentProcessSecurity.Password = winPassword
' Make sure that the agent job for the subscription is created.
subscription.CreateSyncAgentByDefault = True
' By default, subscriptions to transactional publications are synchronized
' continuously, but in this case we only want to synchronize on demand.
subscription.AgentSchedule.FrequencyType = ScheduleFrequencyType.OnDemand
' Create the pull subscription at the Subscriber.
subscription.Create()
Dim registered As Boolean = False
' Verify that the subscription is not already registered.
For Each existing As TransSubscription In publication.EnumSubscriptions()
If existing.SubscriberName = subscriberName And _
existing.SubscriptionDBName = subscriptionDbName Then
registered = True
End If
Next existing
If Not registered Then
' Register the subscription with the Publisher.
publication.MakePullSubscriptionWellKnown( _
subscriberName, subscriptionDbName, _
SubscriptionSyncType.Automatic, _
TransSubscriberType.ReadOnly)
End If
Else
' Do something here if the publication does not exist.
Throw New ApplicationException(String.Format( _
"The publication '{0}' does not exist on {1}.", _
publicationName, publisherName))
End If
Catch ex As Exception
' Implement the appropriate error handling here.
Throw New ApplicationException(String.Format( _
"The subscription to {0} could not be created.", publicationName), ex)
Finally
subscriberConn.Disconnect()
publisherConn.Disconnect()
End Try
備註
對於拉取訂閱,散發代理程式 會直接在訂閱者端執行。
線程安全性
任何此類的公開靜態(SharedMicrosoft Visual Basic)成員對多執行緒操作都是安全的。 任何實例成員都不保證具有執行緒安全性。
建構函式
| 名稱 | Description |
|---|---|
| TransPullSubscription() |
建立 TransPullSubscription 類別的新實例。 |
| TransPullSubscription(String, String, String, String, ServerConnection, Boolean) |
建立一個新的類別實例 TransPullSubscription ,包含定義拉取訂閱的屬性,以及是否要為訂閱建立代理工作。 |
| TransPullSubscription(String, String, String, String, ServerConnection) |
建立一個新的類別實例 TransPullSubscription ,並帶有定義拉取訂閱的屬性。 |
屬性
| 名稱 | Description |
|---|---|
| AgentJobId |
取得用來同步訂閱的代理工作 ID。 (繼承來源 PullSubscription) |
| AgentOffload |
取得或設定同步代理是否在非建立代理工作所建立的電腦上執行。 此特性已不再支援運行 Microsoft SQL Server 2005 及以後版本的發行版。 (繼承來源 PullSubscription) |
| AgentOffloadServer |
在使用遠端代理啟用時,取得或設定代理執行的遠端電腦名稱。 (繼承來源 PullSubscription) |
| AgentSchedule |
取得用來同步訂閱的代理工作排程。 (繼承來源 PullSubscription) |
| AltSnapshotFolder |
當預設的分發器快照位置未被使用時,取得或設定發佈快照檔案的取得位置。 (繼承來源 PullSubscription) |
| Attributes |
取得或設定由訂閱所支援的交易出版屬性。 |
| CachePropertyChanges |
取得或設定是快取複製屬性的變更,還是立即套用。 (繼承來源 ReplicationObject) |
| ConnectionContext |
取得或設定連接到 Microsoft SQL Server 實例。 (繼承來源 ReplicationObject) |
| CreateSyncAgentByDefault |
取得或設定用於啟動複製代理以同步訂閱的代理工作是否在訂閱建立時被建立。 (繼承來源 PullSubscription) |
| DatabaseName |
取得或設定訂閱資料庫名稱。 (繼承來源 PullSubscription) |
| Description |
取得或設定拉取訂閱的文字描述。 (繼承來源 PullSubscription) |
| DistributorName |
取得或設定 Microsoft SQL Server 的實例,該實例作為發行者,並分發訂閱所訂閱的出版品。 (繼承來源 PullSubscription) |
| DistributorSecurity |
取得連接分發器時所用的安全上下文。 (繼承來源 PullSubscription) |
| DtsPackageLocation |
取得或設定與可轉換訂閱一起使用的資料轉換服務(DTS)套件的位置。 |
| DtsPackageName |
取得或設定可用於可轉換訂閱的資料轉換服務(Data Transformation Services,DTS)套件名稱。 |
| DtsPackagePassword |
取得或設定用於可轉換訂閱的密碼。 |
| EnabledForSynchronizationManager |
指定訂閱是否能使用 Windows 同步管理器同步。 (繼承來源 PullSubscription) |
| FtpAddress |
取得或設定 FTP 伺服器的 IP 位址。 (繼承來源 PullSubscription) |
| FtpLogin |
取得或設定 FTP 登入。 (繼承來源 PullSubscription) |
| FtpPassword |
取得或設定 FTP 密碼。 (繼承來源 PullSubscription) |
| FtpPort |
取得或設定 FTP 伺服器的埠號。 (繼承來源 PullSubscription) |
| IsExistingObject |
它會判斷該物件是否存在於伺服器上。 (繼承來源 ReplicationObject) |
| IsMemoryOptimized |
代表對交易性出版品的拉取訂閱。 (繼承來源 PullSubscription) |
| LastAgentDateTime |
會取得訂閱最後一次同步的日期和時間。 (繼承來源 PullSubscription) |
| LastAgentStatus |
查詢訂閱最新同步的狀態。 (繼承來源 PullSubscription) |
| LastAgentSummary |
取得最近一次訂閱同步結果的摘要。 (繼承來源 PullSubscription) |
| LastSummaryDateTime |
會取得最後一次同步完成的日期和時間。 |
| MemoryOptimized |
代表對交易性出版品的拉取訂閱。 |
| Name |
這樣就能產生拉取訂閱的名稱。 (繼承來源 PullSubscription) |
| PublicationDBName |
取得或設定出版資料庫名稱。 (繼承來源 PullSubscription) |
| PublicationName |
取得或設定訂閱所訂閱的出版物名稱。 (繼承來源 PullSubscription) |
| PublisherName |
取得或設定 Publisher 的名字。 (繼承來源 PullSubscription) |
| PublisherSecurity |
取得或設定同步代理程式連接 Publisher 時所使用的安全上下文。 (繼承來源 PullSubscription) |
| SecureFtpPassword |
取得或設定用於連接 FTP 伺服器的登入密碼。 (繼承來源 PullSubscription) |
| SqlServerName |
取得該物件所連接的 Microsoft SQL Server 實例名稱。 (繼承來源 ReplicationObject) |
| SubscriberSecurity |
取得同步代理在連接訂閱者時所使用的安全上下文。 (繼承來源 PullSubscription) |
| SubscriberType |
取得或設定訂閱的更新行為。 |
| SubscriptionId |
會取得訂閱 ID 的值。 (繼承來源 PullSubscription) |
| SubscriptionType |
會知道訂閱註冊是推送、拉取還是匿名訂閱。 (繼承來源 PullSubscription) |
| SynchronizationAgent |
取得一個代表 散發代理程式 實例的物件,可用來同步訂閱。 |
| SynchronizationAgentProcessSecurity |
取得用來指定同步代理工作執行的Microsoft Windows帳號以同步訂閱的安全上下文。 (繼承來源 PullSubscription) |
| Type |
取得或設定發表類型。 (繼承來源 PullSubscription) |
| UseFtp |
取得或設定同步代理是否透過檔案傳輸協定(FTP)存取初始化拉取訂閱所需的快照檔案。 (繼承來源 PullSubscription) |
| UserData |
取得或設定一個物件屬性,讓使用者能將自己的資料附加到物件上。 (繼承來源 ReplicationObject) |
| WorkingDirectory |
取得或設定訂閱者用來暫時儲存及解壓下載快照檔案的目錄路徑。 (繼承來源 PullSubscription) |