MergeSubscription 类

定义

表示对在发布服务器注册的合并发布的订阅。

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 与合并发布的拉取订阅和推送订阅一起使用。

使用远程分发服务器配置发布服务器时,为所有参数(包括 SynchronizationAgentProcessSecurity)提供的值将作为纯文本发送到分发服务器。 调用 Create 方法之前,应先对发布服务器与其远程分发服务器之间的连接进行加密。 有关详细信息,请参阅 sp_reinitmergesubscription (Transact-SQL)

线程安全性

Microsoft Visual Basic) 此类型成员中的任何公共静态 Shared (对于多线程操作都是安全的。 但不保证所有实例成员都是线程安全的。

构造函数

MergeSubscription()

创建 MergeSubscription 类的新实例。

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

使用指定的与发布服务器的连接以及唯一定义订阅的属性创建 MergeSubscription 类的新实例。

属性

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

获取合并代理用于连接到发布服务器的安全上下文。

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()

在发布服务器上创建订阅注册。

(继承自 Subscription)
Decouple()

将引用的复制对象与服务器相分离。

(继承自 ReplicationObject)
GetChangeCommand(StringBuilder, String, String)

从复制返回更改命令。

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

从复制返回创建命令。

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

从复制返回删除命令。

(继承自 ReplicationObject)
InternalRefresh(Boolean)

从复制启动内部刷新。

(继承自 ReplicationObject)
Load()

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

(继承自 ReplicationObject)
LoadProperties()

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

(继承自 ReplicationObject)
Refresh()

重新加载该对象的属性。

(继承自 ReplicationObject)
Reinitialize(Boolean)

将合并订阅标记为要重新初始化。

Remove()

删除发布服务器上的订阅注册,并删除订阅服务器上用于推送订阅的复制对象。

(继承自 Subscription)
Script(ScriptOptions)

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

(继承自 Subscription)
StopSynchronizationJob()

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

SynchronizeWithJob()

启动代理作业以便同步订阅。

适用于

另请参阅