TransSubscription 類別

定義

代表對交易性或快照出版的推送訂閱。

public ref class TransSubscription sealed : Microsoft::SqlServer::Replication::Subscription
public sealed class TransSubscription : Microsoft.SqlServer.Replication.Subscription
type TransSubscription = class
    inherit Subscription
Public NotInheritable Class TransSubscription
Inherits Subscription
繼承

範例

           // Define the Publisher, publication, and databases.
           string publicationName = "AdvWorksProductTran";
           string publisherName = publisherInstance;
           string subscriberName = subscriberInstance;
           string subscriptionDbName = "AdventureWorks2012Replica";
           string publicationDbName = "AdventureWorks2012";

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

           // Create the objects that we need.
           TransPublication publication;
           TransSubscription subscription;

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

               // Ensure that the publication exists and that 
               // it supports push subscriptions.
               publication = new TransPublication();
               publication.Name = publicationName;
               publication.DatabaseName = publicationDbName;
               publication.ConnectionContext = conn;

               if (publication.IsExistingObject)
               {
                   if ((publication.Attributes & PublicationAttributes.AllowPush) == 0)
                   {
                       publication.Attributes |= PublicationAttributes.AllowPush;
                   }

                   // Define the push subscription.
                   subscription = new TransSubscription();
                   subscription.ConnectionContext = conn;
                   subscription.SubscriberName = subscriberName;
                   subscription.PublicationName = publicationName;
                   subscription.DatabaseName = publicationDbName;
                   subscription.SubscriptionDBName = subscriptionDbName;

                   // Specify the Windows login credentials for the Distribution Agent job.
                   subscription.SynchronizationAgentProcessSecurity.Login = winLogin;
                   subscription.SynchronizationAgentProcessSecurity.Password = winPassword;

                   // 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 push subscription.
                   subscription.Create();
               }
               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
           {
               conn.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 a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)

' Create the objects that we need.
Dim publication As TransPublication
Dim subscription As TransSubscription

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

    ' Ensure that the publication exists and that 
    ' it supports push subscriptions.
    publication = New TransPublication()
    publication.Name = publicationName
    publication.DatabaseName = publicationDbName
    publication.ConnectionContext = conn

    If publication.IsExistingObject Then
        If (publication.Attributes And PublicationAttributes.AllowPush) = 0 Then
            publication.Attributes = publication.Attributes _
            Or PublicationAttributes.AllowPush
        End If

        ' Define the push subscription.
        subscription = New TransSubscription()
        subscription.ConnectionContext = conn
        subscription.SubscriberName = subscriberName
        subscription.PublicationName = publicationName
        subscription.DatabaseName = publicationDbName
        subscription.SubscriptionDBName = subscriptionDbName

        ' Specify the Windows login credentials for the Distribution Agent job.
        subscription.SynchronizationAgentProcessSecurity.Login = winLogin
        subscription.SynchronizationAgentProcessSecurity.Password = winPassword

        ' 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 push subscription.
        subscription.Create()
    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
    conn.Disconnect()
End Try

備註

在設定遠端 Distributor 的 Publisher 時,所有參數(包括 SynchronizationAgentProcessSecurity)所提供的值會以純文字形式傳送給 Distributor。 您應該先加密「發行者」及其遠端「散發者」之間的連線,然後再呼叫 Create 方法。 更多資訊請參見 sp_reinitsubscription(Transact-SQL)

當訂閱屬於非SQL Server Publisher時,ConnectionContext屬性會設定為發行者而非Publisher,DatabaseName屬性設為發行資料庫而非出版資料庫,屬性PublisherName則設為非 SQL Server Publisher 的名稱。

線程安全性

任何此類的公開靜態(SharedMicrosoft Visual Basic)成員對多執行緒操作都是安全的。 任何實例成員都不保證具有執行緒安全性。

建構函式

名稱 Description
TransSubscription()

建立 TransSubscription 類別的新實例。

TransSubscription(String, String, String, String, ServerConnection)

建立一個新的類別實例TransSubscription,包含指定的發佈、資料庫、Subscriber 及 subscriber 資料庫,並以指定連線連接 Microsoft SQL Server 實例。

屬性

名稱 Description
AgentJobId

取得用來同步訂閱的代理工作 ID。

(繼承來源 Subscription)
AgentOffload

取得或設定同步代理是否在非該代理工作建立的電腦上執行。 此特性已不再支援運行 Microsoft SQL Server 2005 及以後版本的發行版。

(繼承來源 Subscription)
AgentOffloadServer

在使用遠端代理啟用時,取得或設定代理執行的遠端電腦名稱。

(繼承來源 Subscription)
AgentSchedule

取得用來同步訂閱的代理工作排程。

(繼承來源 Subscription)
BackupInformation

從備份中取得或設定初始化訂閱所需的資訊。

CachePropertyChanges

取得或設定是快取複製屬性的變更,還是立即套用。

(繼承來源 ReplicationObject)
ConnectionContext

取得或設定連接到 Microsoft SQL Server 實例。

(繼承來源 ReplicationObject)
CreateSyncAgentByDefault

取得或設定用於同步訂閱的代理工作是否預設為建立。

(繼承來源 Subscription)
DatabaseName

取得或設定出版資料庫名稱。

(繼承來源 Subscription)
DtsPackageLocation

取得或設定 Microsoft SQL Server 2000 資料轉換服務(DTS)套件的位置。

DtsPackageName

取得或設定 Microsoft SQL Server 2000 資料轉換服務(DTS)套件的名稱,該套件會套用於訂閱者。

DtsPackagePassword

設定執行 Microsoft SQL Server 2000 資料轉換服務(DTS)套件所使用的密碼。

EnabledForSynchronizationManager

指定訂閱是否能使用 Microsoft Windows同步管理器進行同步。

(繼承來源 Subscription)
FullSubscription

會得到一個表示訂閱是否已滿的值。

IsExistingObject

它會判斷該物件是否存在於伺服器上。

(繼承來源 ReplicationObject)
LoopBackDetection

取得或設定 散發代理程式 是否將從訂閱者發起的交易回傳給訂閱者。

MemoryOptimized

代表對交易性或快照出版的推送訂閱。

Name

會被分配到現有訂閱名稱上。

(繼承來源 Subscription)
PublicationName

取得或設定訂閱所訂閱的出版物名稱。

(繼承來源 Subscription)
PublisherName

當訂閱屬於非SQL Server Publisher時,取得或設定Publisher名稱。

SecureDtsPackagePassword

設定用於執行 Microsoft SQL Server 2000 資料轉換服務(DTS)套件的密碼(物件SecureString)。

SqlServerName

取得該物件所連接的 Microsoft SQL Server 實例名稱。

(繼承來源 ReplicationObject)
Status

會取得訂閱狀態。

(繼承來源 Subscription)
SubscriberCatalog

為非 SQL Server 訂閱者建立 OLE DB 提供者連線時,取得或設定所使用的目錄。

SubscriberDatasource

OLE DB提供者對非SQL Server訂閱者所理解的資料來源名稱。

SubscriberDatasourceType

識別非 SQL Server 訂閱者的資料來源類型。

SubscriberLocation

OLE DB提供者對非SQL Server訂閱者所理解的資料庫位置。

SubscriberName

取得或設定 Microsoft SQL Server 的 Subscriber 實例名稱。

(繼承來源 Subscription)
SubscriberProvider

非 SQL Server 訂閱者 OLE DB 提供者註冊的唯一程式識別碼(PROGID)

SubscriberProviderString

非 SQL Server 訂閱者使用 OLE DB 提供者專用的 連接字串 連接資料來源。

SubscriberSecurity

取得用來連接訂閱者的安全上下文。

(繼承來源 Subscription)
SubscriberType

接收或設定訂閱者資料變更的更新行為。

SubscriptionDBName

取得或設定接收複製資料的訂閱者資料庫名稱。

(繼承來源 Subscription)
SubscriptionLSN

取得或設定訂閱的日誌序號。

SubscriptionType

它會知道訂閱註冊是推訂閱還是拉訂閱。

(繼承來源 Subscription)
SynchronizationAgent

取得一個可用來同步訂閱的類別實例 TransSynchronizationAgent

SynchronizationAgentName

取得或設定已建立的代理工作名稱以同步訂閱。

(繼承來源 Subscription)
SynchronizationAgentProcessSecurity

取得用來指定同步代理工作執行的Microsoft Windows帳號以同步訂閱的安全上下文。

(繼承來源 Subscription)
SyncType

取得或設定訂閱初始化的方式。

(繼承來源 Subscription)
UserData

取得或設定一個物件屬性,讓使用者能將自己的資料附加到物件上。

(繼承來源 ReplicationObject)

方法

名稱 Description
CheckValidCreation()

檢查有效的複製建立。

(繼承來源 ReplicationObject)
CheckValidDefinition(Boolean)

表示訂閱定義是否有效。

(繼承來源 Subscription)
CommitPropertyChanges()

將所有快取的屬性變更語句傳送到 Microsoft SQL Server 實例。

(繼承來源 ReplicationObject)
Create()

在 Publisher 建立訂閱註冊。

(繼承來源 Subscription)
Decouple()

將參考的複製物件與伺服器解耦。

(繼承來源 ReplicationObject)
DoUpdateMemoryOptimizedProperty(String)

代表對交易性或快照出版的推送訂閱。

GetChangeCommand(StringBuilder, String, String)

回傳複製中的變更指令。

(繼承來源 ReplicationObject)
GetCreateCommand(StringBuilder, Boolean, ScriptOptions)

回傳複製中的 create 指令。

(繼承來源 ReplicationObject)
GetDropCommand(StringBuilder, Boolean)

從複製中回傳 drop 指令。

(繼承來源 ReplicationObject)
InternalRefresh(Boolean)

會從複製中啟動內部刷新。

(繼承來源 ReplicationObject)
Load()

從伺服器載入現有物件的屬性。

(繼承來源 ReplicationObject)
LoadProperties()

從伺服器載入現有物件的屬性。

(繼承來源 ReplicationObject)
Refresh()

重新載入物件的屬性。

(繼承來源 ReplicationObject)
Reinitialize()

下次 散發代理程式 執行同步訂閱時,標記該訂閱需重新初始化。

Reinitialize(Boolean)

重新初始化訂閱。

Remove()

刪除 Publisher 的訂閱註冊,並移除訂閱者的複製物件,以實現推送訂閱。

(繼承來源 Subscription)
Script(ScriptOptions)

回傳一個 Transact-SQL 腳本,可用於建立或刪除訂閱。

(繼承來源 Subscription)
StopSynchronizationJob()

嘗試停止正在同步訂閱的 散發代理程式 工作。

SynchronizeWithJob()

啟動代理工作以同步訂閱。

適用於

另請參閱