MergeSubscription 类

定义

代表在Publisher注册的合并出版物的订阅。

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

示例

// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksSalesOrdersMerge";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";
string hostname = @"adventure-works\garrett1";

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

// Create the objects that we need.
MergePublication publication;
MergeSubscription subscription;

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

    // Ensure that the publication exists and that 
    // it supports push subscriptions.
    publication = new MergePublication();
    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 MergeSubscription();
        subscription.ConnectionContext = conn;
        subscription.SubscriberName = subscriberName;
        subscription.PublicationName = publicationName;
        subscription.DatabaseName = publicationDbName;
        subscription.SubscriptionDBName = subscriptionDbName;
        subscription.HostName = hostname;

        // Set a schedule to synchronize the subscription every 2 hours
        // during weekdays from 6am to 10pm.
        subscription.AgentSchedule.FrequencyType = ScheduleFrequencyType.Weekly;
        subscription.AgentSchedule.FrequencyInterval = Convert.ToInt32(0x003E);
        subscription.AgentSchedule.FrequencyRecurrenceFactor = 1;
        subscription.AgentSchedule.FrequencySubDay = ScheduleFrequencySubDay.Hour;
        subscription.AgentSchedule.FrequencySubDayInterval = 2;
        subscription.AgentSchedule.ActiveStartDate = 20051108;
        subscription.AgentSchedule.ActiveEndDate = 20071231;
        subscription.AgentSchedule.ActiveStartTime = 060000;
        subscription.AgentSchedule.ActiveEndTime = 100000;

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

        // 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 = "AdvWorksSalesOrdersMerge"
Dim publisherName As String = publisherInstance
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"
Dim hostname As String = "adventure-works\garrett1"

'Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)

' Create the objects that we need.
Dim publication As MergePublication
Dim subscription As MergeSubscription

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

    ' Ensure that the publication exists and that 
    ' it supports push subscriptions.
    publication = New MergePublication()
    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 MergeSubscription()
        subscription.ConnectionContext = conn
        subscription.SubscriberName = subscriberName
        subscription.PublicationName = publicationName
        subscription.DatabaseName = publicationDbName
        subscription.SubscriptionDBName = subscriptionDbName
        subscription.HostName = hostname

        ' Set a schedule to synchronize the subscription every 2 hours
        ' during weekdays from 6am to 10pm.
        subscription.AgentSchedule.FrequencyType = ScheduleFrequencyType.Weekly
        subscription.AgentSchedule.FrequencyInterval = Convert.ToInt32("0x003E", 16)
        subscription.AgentSchedule.FrequencyRecurrenceFactor = 1
        subscription.AgentSchedule.FrequencySubDay = ScheduleFrequencySubDay.Hour
        subscription.AgentSchedule.FrequencySubDayInterval = 2
        subscription.AgentSchedule.ActiveStartDate = 20051108
        subscription.AgentSchedule.ActiveEndDate = 20071231
        subscription.AgentSchedule.ActiveStartTime = 60000
        subscription.AgentSchedule.ActiveEndTime = 100000

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

        ' 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

注解

MergeSubscription 类适用于合并出版物的拉取订阅和推送订阅。

在配置带有远程分发器的 Publisher 时,所有参数(包括 SynchronizationAgentProcessSecurity)提供的值都会以纯文本形式发送给分发器。 调用 Create 方法之前,应先对发布服务器与其远程分发服务器之间的连接进行加密。 更多信息请参见 sp_reinitmergesubscription(Transact-SQL)

线程安全性

任何此类公共静态(SharedMicrosoft Visual Basic)成员对多线程操作都是安全的。 不能保证任何实例成员是线程安全的。

构造函数

名称 说明
MergeSubscription()

创建类的新实例 MergeSubscription

MergeSubscription(String, String, String, String, ServerConnection)

创建一个新的类实例MergeSubscription,并与指定的Publisher连接,并拥有唯一定义订阅的属性。

属性

名称 说明
AgentJobId

获取用于同步订阅的代理任务ID。

(继承自 Subscription)
AgentOffload

获取或设置同步代理是否运行在非创建代理作业的计算机上。 该属性不再支持运行 Microsoft SQL Server 2005 及以后版本的分发器。

(继承自 Subscription)
AgentOffloadServer

在使用远程代理激活时,获取或设置代理运行的远程计算机名称。

(继承自 Subscription)
AgentSchedule

获取用于同步订阅的代理任务的日程安排。

(继承自 Subscription)
CachePropertyChanges

获取或设置是缓存复制属性的更改,还是立即应用。

(继承自 ReplicationObject)
ConnectionContext

获取或设置连接到 Microsoft SQL Server 实例。

(继承自 ReplicationObject)
CreateSyncAgentByDefault

获取或设置用于同步订阅的代理任务是否默认创建。

(继承自 Subscription)
DatabaseName

获取或设定发表数据库的名称。

(继承自 Subscription)
Description

获取或设置合并订阅的文本描述。

EnabledForSynchronizationManager

指定订阅是否可以通过同步管理器同步Microsoft Windows。

(继承自 Subscription)
HostName

当该函数被用于定义订阅者数据分区的参数化行过滤器时,获取或设置 HOST_NAME 函数所提供的值。

IsExistingObject

判断该对象是否存在于服务器上。

(继承自 ReplicationObject)
Name

它会被分配到已有订阅上。

(继承自 Subscription)
Priority

获取或设置分配给服务器订阅的相对优先级值。

PublicationName

获取或设置订阅所订阅的出版物名称。

(继承自 Subscription)
PublisherSecurity

获取 合并代理 用来连接 Publisher 的安全上下文。

SqlServerName

获取该对象所连接的 Microsoft SQL Server 实例名称。

(继承自 ReplicationObject)
Status

获取订阅状态。

(继承自 Subscription)
SubscriberName

获取或设置作为订阅者的 Microsoft SQL Server 实例的名称。

(继承自 Subscription)
SubscriberSecurity

获取连接订阅者时使用的安全上下文。

(继承自 Subscription)
SubscriberType

获取或设置订阅是客户端还是服务器订阅。

SubscriptionDBName

获取或设置接收复制数据的订阅者数据库名称。

(继承自 Subscription)
SubscriptionType

它能识别订阅注册是推送订阅还是拉购订阅。

(继承自 Subscription)
SynchronizationAgent

获得一个类实例 MergeSynchronizationAgent ,可以用来同步订阅。

SynchronizationAgentName

获取或设置创建的代理任务名称以同步订阅。

(继承自 Subscription)
SynchronizationAgentProcessSecurity

获取用于指定同步代理作业运行的Microsoft Windows账户以同步订阅的安全上下文。

(继承自 Subscription)
SyncType

获取或设置订阅初始化的方式。

(继承自 Subscription)
UseInteractiveResolver

在同步过程中是否使用交互式解析器,获取或设置。

UserData

获取或设置一个对象属性,允许用户将自己的数据附加到该对象上。

(继承自 ReplicationObject)

方法

名称 说明
CheckValidCreation()

检查有效的复制创建。

(继承自 ReplicationObject)
CheckValidDefinition(Boolean)

表示订阅定义是否有效。

(继承自 Subscription)
CommitPropertyChanges()

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

(继承自 ReplicationObject)
Create()

在 Publisher 创建订阅注册。

(继承自 Subscription)
Decouple()

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

(继承自 ReplicationObject)
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(Boolean)

标记合并订阅以进行重新初始化。

Remove()

删除 Publisher 的订阅注册,并移除 Subscriber 的复制对象,用于推送订阅。

(继承自 Subscription)
Script(ScriptOptions)

返回一个 Transact-SQL 脚本,可用于创建或删除订阅。

(继承自 Subscription)
StopSynchronizationJob()

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

SynchronizeWithJob()

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

适用于

另请参阅