TransSubscription 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示对事务性或快照发布的推送订阅。
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
注解
在配置带有远程分发器的 Publisher 时,所有参数(包括 SynchronizationAgentProcessSecurity)提供的值都会以纯文本形式发送给分发器。 调用 Create 方法之前,应先对发布服务器与其远程分发服务器之间的连接进行加密。 更多信息请参见 sp_reinitsubscription(Transact-SQL)。
当订阅属于非SQL Server Publisher时,ConnectionContext属性被设置为分发者而非Publisher,DatabaseName属性设置为分发数据库而非出版数据库,属性PublisherName设置为非SQL Server Publisher的名称。
线程安全性
任何此类公共静态(SharedMicrosoft Visual Basic)成员对多线程操作都是安全的。 不能保证任何实例成员是线程安全的。
构造函数
| 名称 | 说明 |
|---|---|
| TransSubscription() |
创建类的新实例 TransSubscription 。 |
| TransSubscription(String, String, String, String, ServerConnection) |
创建一个新的类实例TransSubscription,包含指定的发布、数据库、Subscriber和subscriber数据库,并与Microsoft SQL Server实例有指定的连接。 |
属性
| 名称 | 说明 |
|---|---|
| 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 |
非 SQL Server 订阅者对 OLE DB 提供商理解的数据库位置。 |
| SubscriberName |
获取或设置作为订阅者的 Microsoft SQL Server 实例的名称。 (继承自 Subscription) |
| SubscriberProvider |
唯一程序标识符(PROGID),用于注册非SQL Server订阅者的OLE DB提供者 |
| 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) |