TransPullSubscription 类

定义

代表对交易性出版物的拉取订阅。

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
继承
TransPullSubscription

示例

// 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)成员对多线程操作都是安全的。 不能保证任何实例成员是线程安全的。

构造函数

名称 说明
TransPullSubscription()

创建类的新实例 TransPullSubscription

TransPullSubscription(String, String, String, String, ServerConnection, Boolean)

创建一个新的类实例 TransPullSubscription ,包含定义拉取订阅的属性,以及是否为订阅创建代理任务。

TransPullSubscription(String, String, String, String, ServerConnection)

创建一个新的类实例 TransPullSubscription ,带有定义拉取订阅的属性。

属性

名称 说明
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

获取或设置可用于可转换订阅的数据转换服务(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)

方法

名称 说明
CheckValidCreation()

检查有效的复制创建。

(继承自 ReplicationObject)
CheckValidDefinition(Boolean)

表示该定义是否有效。

(继承自 PullSubscription)
CommitPropertyChanges()

将所有缓存的属性更改语句发送到Microsoft SQL Server实例。

(继承自 ReplicationObject)
Create()

在订阅者上创建拉取订阅。

(继承自 PullSubscription)
CustomEnabledForSyncMgr(StringBuilder)

支持同步管理器的自定义发布。

(继承自 PullSubscription)
Decouple()

将被引用的复制对象与服务器解耦。

(继承自 ReplicationObject)
DoUpdateMemoryOptimizedProperty(String)

代表对交易性出版物的拉取订阅。

GetChangeCommand(StringBuilder, String, String)

返回复制中的更改命令。

(继承自 ReplicationObject)
GetCreateCommand(StringBuilder, Boolean, ScriptOptions)

返回复制中的create命令。

(继承自 ReplicationObject)
GetDropCommand(StringBuilder, Boolean)

返回复制中的drop命令。

(继承自 ReplicationObject)
InitMemberVariables(String, String, String, String, Boolean)

初始化成员变量。

(继承自 PullSubscription)
InternalRefresh(Boolean)

从复制中启动内部刷新。

(继承自 ReplicationObject)
LastAgentJobHistoryInfo()

返回上一次运行的同步代理作业信息。

(继承自 PullSubscription)
Load()

从服务器加载现有对象的属性。

(继承自 ReplicationObject)
LoadProperties()

从服务器加载现有对象的属性。

(继承自 ReplicationObject)
Refresh()

重新加载对象的属性。

(继承自 ReplicationObject)
Reinitialize()

标记了重新初始化的拉取订阅。

Remove()

移除了拉取订阅。

(继承自 PullSubscription)
Script(ScriptOptions)

返回一个 Transact-SQL 脚本,根据当前对象的属性设置 PullSubscription 创建或删除拉取订阅。

(继承自 PullSubscription)
StopSynchronizationJob()

尝试停止正在同步订阅的运行中的 分发代理 作业。

SynchronizeWithJob()

启动代理任务以同步订阅。

适用于

另请参阅