MergePublication 类

定义

表示合并发布。

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

示例

此示例创建合并发布。

// Set the Publisher, publication database, and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks2012";

ReplicationDatabase publicationDb;
MergePublication publication;

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

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

    // Enable the database for merge publication.				
    publicationDb = new ReplicationDatabase(publicationDbName, conn);
    if (publicationDb.LoadProperties())
    {
        if (!publicationDb.EnabledMergePublishing)
        {
            publicationDb.EnabledMergePublishing = true;
        }
    }
    else
    {
        // Do something here if the database does not exist. 
        throw new ApplicationException(String.Format(
            "The {0} database does not exist on {1}.",
            publicationDb, publisherName));
    }

    // Set the required properties for the merge publication.
    publication = new MergePublication();
    publication.ConnectionContext = conn;
    publication.Name = publicationName;
    publication.DatabaseName = publicationDbName;

    // Enable precomputed partitions.
    publication.PartitionGroupsOption = PartitionGroupsOption.True;

    // Specify the Windows account under which the Snapshot Agent job runs.
    // This account will be used for the local connection to the 
    // Distributor and all agent connections that use Windows Authentication.
    publication.SnapshotGenerationAgentProcessSecurity.Login = winLogin;
    publication.SnapshotGenerationAgentProcessSecurity.Password = winPassword;

    // Explicitly set the security mode for the Publisher connection
    // Windows Authentication (the default).
    publication.SnapshotGenerationAgentPublisherSecurity.WindowsAuthentication = true;

    // Enable Subscribers to request snapshot generation and filtering.
    publication.Attributes |= PublicationAttributes.AllowSubscriberInitiatedSnapshot;
    publication.Attributes |= PublicationAttributes.DynamicFilters;

    // Enable pull and push subscriptions.
    publication.Attributes |= PublicationAttributes.AllowPull;
    publication.Attributes |= PublicationAttributes.AllowPush;

    if (!publication.IsExistingObject)
    {
        // Create the merge publication.
        publication.Create();
        
        // Create a Snapshot Agent job for the publication.
        publication.CreateSnapshotAgent();
    }
    else
    {
        throw new ApplicationException(String.Format(
            "The {0} publication already exists.", publicationName));
    }
}

catch (Exception ex)
{
    // Implement custom application error handling here.
    throw new ApplicationException(String.Format(
        "The publication {0} could not be created.", publicationName), ex);
}
finally
{
    conn.Disconnect();
}
' Set the Publisher, publication database, and publication names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2012"

Dim publicationDb As ReplicationDatabase
Dim publication As MergePublication

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

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

    ' Enable the database for merge publication.				
    publicationDb = New ReplicationDatabase(publicationDbName, conn)
    If publicationDb.LoadProperties() Then
        If Not publicationDb.EnabledMergePublishing Then
            publicationDb.EnabledMergePublishing = True
        End If
    Else
        ' Do something here if the database does not exist. 
        Throw New ApplicationException(String.Format( _
         "The {0} database does not exist on {1}.", _
         publicationDb, publisherName))
    End If

    ' Set the required properties for the merge publication.
    publication = New MergePublication()
    publication.ConnectionContext = conn
    publication.Name = publicationName
    publication.DatabaseName = publicationDbName

    ' Enable precomputed partitions.
    publication.PartitionGroupsOption = PartitionGroupsOption.True

    ' Specify the Windows account under which the Snapshot Agent job runs.
    ' This account will be used for the local connection to the 
    ' Distributor and all agent connections that use Windows Authentication.
    publication.SnapshotGenerationAgentProcessSecurity.Login = winLogin
    publication.SnapshotGenerationAgentProcessSecurity.Password = winPassword

    ' Explicitly set the security mode for the Publisher connection
    ' Windows Authentication (the default).
    publication.SnapshotGenerationAgentPublisherSecurity.WindowsAuthentication = True

    ' Enable Subscribers to request snapshot generation and filtering.
    publication.Attributes = publication.Attributes Or _
        PublicationAttributes.AllowSubscriberInitiatedSnapshot
    publication.Attributes = publication.Attributes Or _
        PublicationAttributes.DynamicFilters

    ' Enable pull and push subscriptions
    publication.Attributes = publication.Attributes Or _
        PublicationAttributes.AllowPull
    publication.Attributes = publication.Attributes Or _
        PublicationAttributes.AllowPush

    If Not publication.IsExistingObject Then
        ' Create the merge publication.
        publication.Create()

        ' Create a Snapshot Agent job for the publication.
        publication.CreateSnapshotAgent()
    Else
        Throw New ApplicationException(String.Format( _
            "The {0} publication already exists.", publicationName))
    End If
Catch ex As Exception
    ' Implement custom application error handling here.
    Throw New ApplicationException(String.Format( _
        "The publication {0} could not be created.", publicationName), ex)
Finally
    conn.Disconnect()
End Try

此示例更改合并发布的属性。

// Define the server, database, and publication names
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks2012";

MergePublication publication;

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

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

    // Set the required properties for the publication.
    publication = new MergePublication();
    publication.ConnectionContext = conn;
    publication.Name = publicationName;
    publication.DatabaseName = publicationDbName;


    // If we can't get the properties for this merge publication, then throw an application exception.
    if (publication.LoadProperties())
    {
        // If DDL replication is currently enabled, disable it.
        if (publication.ReplicateDdl == DdlReplicationOptions.All)
        {
            publication.ReplicateDdl = DdlReplicationOptions.None;
        }
        else
        {
            publication.ReplicateDdl = DdlReplicationOptions.All;
        }
    }
    else
    {
        throw new ApplicationException(String.Format(
            "Settings could not be retrieved for the publication. " +
            "Ensure that the publication {0} exists on {1}.",
            publicationName, publisherName));
    }
}
catch (Exception ex)
{
    // Do error handling here.
    throw new ApplicationException(
        "The publication property could not be changed.", ex);
}
finally
{
    conn.Disconnect();
}
' Define the server, database, and publication names
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2012"

Dim publication As MergePublication

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

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

    ' Set the required properties for the publication.
    publication = New MergePublication()
    publication.ConnectionContext = conn
    publication.Name = publicationName
    publication.DatabaseName = publicationDbName

    ' If we can't get the properties for this merge publication, then throw an application exception.
    If publication.LoadProperties() Then
        ' If DDL replication is currently enabled, disable it.
        If publication.ReplicateDdl = DdlReplicationOptions.All Then
            publication.ReplicateDdl = DdlReplicationOptions.None
        Else
            publication.ReplicateDdl = DdlReplicationOptions.All
        End If
    Else
        Throw New ApplicationException(String.Format( _
         "Settings could not be retrieved for the publication. " + _
         "Ensure that the publication {0} exists on {1}.", _
         publicationName, publisherName))
    End If
Catch ex As Exception
    ' Do error handling here.
    Throw New ApplicationException( _
        "The publication property could not be changed.", ex)
Finally
    conn.Disconnect()
End Try

此示例删除合并发布。

// Define the Publisher, publication database, 
// and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks2012";

MergePublication publication;
ReplicationDatabase publicationDb;

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

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

    // Set the required properties for the merge publication.
    publication = new MergePublication();
    publication.ConnectionContext = conn;
    publication.Name = publicationName;
    publication.DatabaseName = publicationDbName;

    // Delete the publication, if it exists and has no subscriptions.
    if (publication.LoadProperties() && !publication.HasSubscription)
    {
        publication.Remove();
    }
    else
    {
        // Do something here if the publication does not exist
        // or has subscriptions.
        throw new ApplicationException(String.Format(
            "The publication {0} could not be deleted. " +
            "Ensure that the publication exists and that all " +
            "subscriptions have been deleted.",
            publicationName, publisherName));
    }

    // If no other merge publications exists,
    // disable publishing on the database.
    publicationDb = new ReplicationDatabase(publicationDbName, conn);
    if (publicationDb.LoadProperties())
    {
        if (publicationDb.MergePublications.Count == 0 && publicationDb.EnabledMergePublishing)
        {
            publicationDb.EnabledMergePublishing = false;
        }
    }
    else
    {
        // Do something here if the database does not exist.
        throw new ApplicationException(String.Format(
            "The database {0} does not exist on {1}.",
            publicationDbName, publisherName));
    }
}
catch (Exception ex)
{
    // Implement application error handling here.
    throw new ApplicationException(String.Format(
        "The publication {0} could not be deleted.",
        publicationName), ex);
}
finally
{
    conn.Disconnect();
}
' Define the Publisher, publication database, 
' and publication names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2012"

Dim publication As MergePublication
Dim publicationDb As ReplicationDatabase

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

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

    ' Set the required properties for the merge publication.
    publication = New MergePublication()
    publication.ConnectionContext = conn
    publication.Name = publicationName
    publication.DatabaseName = publicationDbName

    ' Delete the publication, if it exists and has no subscriptions.
    If (publication.LoadProperties() And Not publication.HasSubscription) Then
        publication.Remove()
    Else
        ' Do something here if the publication does not exist
        ' or has subscriptions.
        Throw New ApplicationException(String.Format( _
         "The publication {0} could not be deleted. " + _
         "Ensure that the publication exists and that all " + _
         "subscriptions have been deleted.", _
         publicationName, publisherName))
    End If

    ' If no other merge publications exists,
    ' disable publishing on the database.
    publicationDb = New ReplicationDatabase(publicationDbName, conn)
    If publicationDb.LoadProperties() Then
        If publicationDb.MergePublications.Count = 0 _
        And publicationDb.EnabledMergePublishing Then
            publicationDb.EnabledMergePublishing = False
        End If
    Else
        ' Do something here if the database does not exist.
        Throw New ApplicationException(String.Format( _
         "The database {0} does not exist on {1}.", _
         publicationDbName, publisherName))
    End If
Catch ex As Exception
    ' Implement application error handling here.
    Throw New ApplicationException(String.Format( _
     "The publication {0} could not be deleted.", _
     publicationName), ex)
Finally
    conn.Disconnect()
End Try

注解

线程安全性

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

构造函数

MergePublication()

创建 MergePublication 类的新实例。

MergePublication(String, String, ServerConnection)

使用指定的名称、数据库和与发布服务器的连接初始化 MergePublication 类的新实例。

MergePublication(String, String, ServerConnection, Boolean)

创建 MergePublication 类的实例,指定默认情况下是否应创建快照代理作业。

属性

AltSnapshotFolder

获取或设置用于发布的备用快照文件位置。

(继承自 Publication)
Attributes

获取或设置发布属性。

(继承自 Publication)
AutomaticReinitializationPolicy

获取或设置在由于发布中的更改而重新初始化订阅时是否将发布服务器上的更改上载到发布服务器。

CachePropertyChanges

获取或设置是缓存对复制属性所做的更改还是立即应用它们。

(继承自 ReplicationObject)
CompatibilityLevel

获取或设置可订阅合并发布的 Microsoft SQL Server的最早版本。

ConflictRetention

获取或设置在冲突表中保留冲突数据行的天数。

(继承自 Publication)
ConnectionContext

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

(继承自 ReplicationObject)
CreateSnapshotAgentByDefault

获取或设置在创建发布时是否自动添加快照代理作业。

(继承自 Publication)
DatabaseName

获取或设置发布数据库的名称。

(继承自 Publication)
Description

获取或设置发布的文本说明。

(继承自 Publication)
FtpAddress

为允许通过 FTP 进行订阅初始化的发布获取或设置文件传输协议 (FTP) 服务器计算机的地址。

(继承自 Publication)
FtpLogin

为允许通过 FTP 进行订阅初始化的发布获取或设置用于连接到文件传输协议 (FTP) 服务器的登录名。

(继承自 Publication)
FtpPassword

为允许通过 FTP 进行订阅初始化的发布设置用于连接到文件传输协议 (FTP) 服务器的登录名的密码。

(继承自 Publication)
FtpPort

为允许通过 FTP 进行订阅初始化的发布获取或设置文件传输协议 (FTP) 服务器计算机的端口。

(继承自 Publication)
FtpSubdirectory

为允许通过 FTP 进行订阅初始化的发布获取或设置文件传输协议 (FTP) 服务器计算机上的子目录。

(继承自 Publication)
HasSubscription

获取发布是否具有一个或多个订阅。

(继承自 Publication)
IsExistingObject

获取服务器上是否存在该对象。

(继承自 ReplicationObject)
MaxConcurrentDynamicSnapshots

获取或设置在发布具有参数化行筛选器的情况下,在生成数据快照时支持的并发快照代理会话的最大数目。

MaxConcurrentMerge

获取或设置可同时与发布保持同步的合并代理的最大数目。

MergeArticles

获取合并发布中的现有项目。

MergeSubscriptions

获取属于合并发布的订阅。

Name

获取或设置发布的名称。

(继承自 Publication)
PartitionGroupsOption

获取或设置是否应使用预先计算的分区来优化同步过程。

PostSnapshotScript

获取或设置在初始快照应用到订阅服务器后执行的 Transact-SQL 脚本文件的名称和完整路径。

(继承自 Publication)
PreSnapshotScript

获取或设置在将初始快照应用到订阅服务器之前执行的 Transact-SQL 脚本文件的名称和完整路径。

(继承自 Publication)
Priority

获取发布的优先级。

PubId

获取唯一标识发布的值。

(继承自 Publication)
ReplicateDdl

获取或设置用于确定是否复制 DDL 更改的数据定义语言 (DDL) 复制选项。

(继承自 Publication)
RetentionPeriod

获取或设置在某一订阅未与发布同步时经过多长时间该订阅到期。

(继承自 Publication)
RetentionPeriodUnit

获取或设置用于表示 RetentionPeriodUnit 属性的单位。

SecureFtpPassword

为允许通过 FTP 进行订阅初始化的发布设置用于连接到文件传输协议 (FTP) 服务器的登录名的密码(作为 SecureString 对象)。

(继承自 Publication)
SnapshotAgentExists

获取SQL Server 代理作业是否存在以生成此发布的初始快照。

(继承自 Publication)
SnapshotAvailable

获取或设置一个值,该值指示是否已为此发布生成快照文件并且可用于初始化订阅服务器。

SnapshotGenerationAgentProcessSecurity

获取一个对象,该对象设置运行快照代理作业所基于的 Windows 帐户。

(继承自 Publication)
SnapshotGenerationAgentPublisherSecurity

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

(继承自 Publication)
SnapshotJobId

获取当前发布的快照代理作业 ID。

(继承自 Publication)
SnapshotMethod

获取或设置初始快照的数据文件格式。

(继承自 Publication)
SnapshotSchedule

获取一个对象,该对象为当前发布的快照代理设置计划。

(继承自 Publication)
SqlServerName

获取此对象连接到的 Microsoft SQL Server 实例的名称。

(继承自 ReplicationObject)
Status

获取或设置发布的状态。

(继承自 Publication)
Type

获取或设置发布的类型。

(继承自 Publication)
UserData

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

(继承自 ReplicationObject)
UsesHostName

获取一个值,该值指示合并发布是否具有使用 HOST_NAME 函数来评估分区的参数化行筛选器。

ValidateSubscriberInfo

获取或设置在使用参数化行筛选器时用于定义已发布数据的订阅服务器分区的函数。

WebSynchronizationUrl

获取或设置用于 Web 同步的 URL。

方法

AddMergeDynamicSnapshotJob(MergeDynamicSnapshotJob, ReplicationAgentSchedule)

添加一个快照代理作业,在使用参数化行筛选器时该代理作业为订阅服务器生成筛选的数据分区。

AddMergeDynamicSnapshotJobForLateBoundComClients(Object, Object)

使后期绑定的 COM 客户端能够添加一个快照代理作业,在使用参数化行筛选器时该代理作业为订阅服务器生成筛选的数据分区。

AddMergePartition(MergePartition)

为具有参数化行筛选器的合并发布定义订阅服务器分区。

BrowseSnapshotFolder()

返回生成了快照文件的目录位置的完整路径。

ChangeMergeDynamicSnapshotJobScheduleWithJobId(String, ReplicationAgentSchedule)

修改快照代理作业的计划,该作业基于作业 ID 为订阅服务器生成筛选的数据分区。

ChangeMergeDynamicSnapshotJobScheduleWithJobIdForLateBoundComClients(String, Object)

允许后期绑定 COM 客户端修改快照代理作业的计划,该作业基于作业 ID 为订阅服务器生成筛选的数据分区。

ChangeMergeDynamicSnapshotJobScheduleWithJobName(String, ReplicationAgentSchedule)

修改快照代理作业的计划,该作业基于作业名称为订阅服务器生成筛选的数据分区。

ChangeMergeDynamicSnapshotJobScheduleWithJobNameForLateBoundComClients(String, Object)

允许后期绑定 COM 客户端修改快照代理作业的计划,该作业基于作业名称为订阅服务器生成筛选的数据分区。

CheckValidCreation()

检查有效复制创建。

(继承自 ReplicationObject)
CheckValidDefinition(Boolean)

指示是否检查有效定义。

(继承自 Publication)
CommitPropertyChanges()

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

(继承自 ReplicationObject)
CopySnapshot(String)

将合并发布的快照文件从快照文件夹复制到某一目标文件夹。

Create()

创建发布。

(继承自 Publication)
CreateSnapshotAgent()

如果此作业尚不存在,则创建用于生成发布初始快照的SQL Server 代理作业。

(继承自 Publication)
Decouple()

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

(继承自 ReplicationObject)
DisableSynchronizationPartner(String, String, String)

禁用此合并发布的指定同步伙伴。

EnableSynchronizationPartner(SynchronizationPartner)

启用此合并发布的指定同步伙伴。

EnumAllMergeJoinFilters()

返回对合并发布定义的所有合并联接筛选器。

EnumArticles()

返回发布中的项目。

(继承自 Publication)
EnumMergeDynamicSnapshotJobs()

返回合并动态快照作业的列表。

EnumMergePartitions()

返回为此合并发布定义的订阅服务器分区。

EnumPublicationAccesses(Boolean)

返回有权访问发布服务器的登录名。

(继承自 Publication)
EnumSubscriptions()

返回订阅发布的订阅。

(继承自 Publication)
EnumSynchronizationPartners()

返回此合并发布的备用同步伙伴。

GenerateFilters()

创建合并发布的筛选器。

GetChangeCommand(StringBuilder, String, String)

从复制返回更改命令。

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

从复制返回创建命令。

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

从复制返回删除命令。

(继承自 ReplicationObject)
GetMergeDynamicSnapshotJobScheduleWithJobId(String)

返回快照代理作业的计划,该作业基于作业 ID 为订阅服务器生成筛选的数据分区。

GetMergeDynamicSnapshotJobScheduleWithJobName(String)

返回快照代理作业的计划,该作业基于作业名称为订阅服务器生成筛选的数据分区。

GrantPublicationAccess(String)

将指定的登录名添加到发布访问列表 (PAL) 中。

(继承自 Publication)
InternalRefresh(Boolean)

从复制启动内部刷新。

(继承自 ReplicationObject)
Load()

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

(继承自 ReplicationObject)
LoadProperties()

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

(继承自 ReplicationObject)
MakePullSubscriptionWellKnown(String, String, SubscriptionSyncType, MergeSubscriberType, Single)

在发布服务器上注册合并请求订阅。

ReadLastValidationDateTimes(String, String)

返回有关订阅服务器的最新订阅验证的信息。

Refresh()

重新加载该对象的属性。

(继承自 ReplicationObject)
ReinitializeAllSubscriptions(Boolean)

将所有订阅标记为重新初始化。

Remove()

删除现有发布。

(继承自 Publication)
Remove(Boolean)

即使在无法访问分发服务器时也删除现有发布。

(继承自 Publication)
RemoveMergeDynamicSnapshotJob(String)

从合并发布中删除指定的动态快照作业。

RemoveMergePartition(MergePartition)

删除对合并发布定义的现有订阅服务器分区。

RemovePullSubscription(String, String)

删除具有对合并发布的请求订阅的订阅服务器的注册。

ReplicateUserDefinedScript(String)

将用户定义的脚本的执行复制到指定发布的订阅服务器。

(继承自 Publication)
ResynchronizeSubscription(String, String, ResynchronizeType, String)

将合并订阅重新同步到指定的已知验证状态。

RevokePublicationAccess(String)

从发布访问列表 (PAL) 中删除指定的登录名。

(继承自 Publication)
Script(ScriptOptions)

生成一个 Transact-SQL 脚本,该脚本可用于根据脚本选项指定重新创建发布。

(继承自 Publication)
ScriptMergeDynamicSnapshotJob(MergeDynamicSnapshotJob, ReplicationAgentSchedule, ScriptOptions)

生成一个 Transact-SQL 脚本,该脚本可用于重新创建快照代理作业,该作业使用参数化行筛选器为发布生成订阅服务器的分区数据快照。

ScriptMergePartition(MergePartition, ScriptOptions)

生成一个 Transact-SQL 脚本,该脚本可用于使用参数化行筛选器为发布的发布重新创建订阅服务器分区。

ScriptPublicationActivation(ScriptOptions)

生成一个 Transact-SQL 脚本,该脚本在运行时将合并发布的状态设置为活动状态。

StartSnapshotGenerationAgentJob()

启动为发布生成初始快照的作业。

(继承自 Publication)
StopSnapshotGenerationAgentJob()

尝试停止正在运行的快照代理作业。

(继承自 Publication)
ValidatePublication(ValidationOption)

将所有订阅标记为在下一个同步过程中进行验证。

ValidateSubscription(String, String, ValidationOption)

将指定的订阅标记为在下一个同步过程中进行验证。

适用于

另请参阅