MergeArticle 类

定义

表示合并发布中的项目。

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

示例

此示例创建三个合并项目及其相关的联接筛选器。

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

// Specify article names.
string articleName1 = "Employee";
string articleName2 = "SalesOrderHeader";
string articleName3 = "SalesOrderDetail";

// Specify join filter information.
string filterName12 = "SalesOrderHeader_Employee";
string filterClause12 = "Employee.EmployeeID = " +
    "SalesOrderHeader.SalesPersonID";
string filterName23 = "SalesOrderDetail_SalesOrderHeader";
string filterClause23 = "SalesOrderHeader.SalesOrderID = " +
    "SalesOrderDetail.SalesOrderID";

string salesSchema = "Sales";
string hrSchema = "HumanResources";

MergeArticle article1 = new MergeArticle();
MergeArticle article2 = new MergeArticle();
MergeArticle article3 = new MergeArticle();
MergeJoinFilter filter12 = new MergeJoinFilter();
MergeJoinFilter filter23 = new MergeJoinFilter();

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

// Create three merge articles that are horizontally partitioned
// using a parameterized row filter on Employee.EmployeeID, which is 
// extended to the two other articles using join filters. 
try
{
    // Connect to the Publisher.
    conn.Connect();

    // Create each article. 
    // For clarity, each article is defined separately. 
    // In practice, iterative structures and arrays should 
    // be used to efficiently create multiple articles.

    // Set the required properties for the Employee article.
    article1.ConnectionContext = conn;
    article1.Name = articleName1;
    article1.DatabaseName = publicationDbName;
    article1.SourceObjectName = articleName1;
    article1.SourceObjectOwner = hrSchema;
    article1.PublicationName = publicationName;
    article1.Type = ArticleOptions.TableBased;

    // Define the parameterized filter clause based on Hostname.
    article1.FilterClause = "Employee.LoginID = HOST_NAME()";

    // Set the required properties for the SalesOrderHeader article.
    article2.ConnectionContext = conn;
    article2.Name = articleName2;
    article2.DatabaseName = publicationDbName;
    article2.SourceObjectName = articleName2;
    article2.SourceObjectOwner = salesSchema;
    article2.PublicationName = publicationName;
    article2.Type = ArticleOptions.TableBased;

    // Set the required properties for the SalesOrderDetail article.
    article3.ConnectionContext = conn;
    article3.Name = articleName3;
    article3.DatabaseName = publicationDbName;
    article3.SourceObjectName = articleName3;
    article3.SourceObjectOwner = salesSchema;
    article3.PublicationName = publicationName;
    article3.Type = ArticleOptions.TableBased;

    if (!article1.IsExistingObject) article1.Create();
    if (!article2.IsExistingObject) article2.Create();
    if (!article3.IsExistingObject) article3.Create();

    // Select published columns for SalesOrderHeader.
    // Create an array of column names to vertically filter out.
    // In this example, only one column is removed.
    String[] columns = new String[1];

    columns[0] = "CreditCardApprovalCode";

    // Remove the column.
    article2.RemoveReplicatedColumns(columns);

    // Define a merge filter clauses that filter 
    // SalesOrderHeader based on Employee and 
    // SalesOrderDetail based on SalesOrderHeader. 

    // Parent article.
    filter12.JoinArticleName = articleName1;
    // Child article.
    filter12.ArticleName = articleName2;
    filter12.FilterName = filterName12;
    filter12.JoinUniqueKey = true;
    filter12.FilterTypes = FilterTypes.JoinFilter;
    filter12.JoinFilterClause = filterClause12;

    // Add the join filter to the child article.
    article2.AddMergeJoinFilter(filter12);

    // Parent article.
    filter23.JoinArticleName = articleName2;
    // Child article.
    filter23.ArticleName = articleName3;
    filter23.FilterName = filterName23;
    filter23.JoinUniqueKey = true;
    filter23.FilterTypes = FilterTypes.JoinFilter;
    filter23.JoinFilterClause = filterClause23;

    // Add the join filter to the child article.
    article3.AddMergeJoinFilter(filter23);
}
catch (Exception ex)
{
    // Do error handling here and rollback the transaction.
    throw new ApplicationException(
        "The filtered articles could not be created", ex);
}
finally
{
    conn.Disconnect();
}
' Define the Publisher and publication names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2012"

' Specify article names.
Dim articleName1 As String = "Employee"
Dim articleName2 As String = "SalesOrderHeader"
Dim articleName3 As String = "SalesOrderDetail"

' Specify join filter information.
Dim filterName12 As String = "SalesOrderHeader_Employee"
Dim filterClause12 As String = "Employee.EmployeeID = " + _
    "SalesOrderHeader.SalesPersonID"
Dim filterName23 As String = "SalesOrderDetail_SalesOrderHeader"
Dim filterClause23 As String = "SalesOrderHeader.SalesOrderID = " + _
    "SalesOrderDetail.SalesOrderID"

Dim salesSchema As String = "Sales"
Dim hrSchema As String = "HumanResources"

Dim article1 As MergeArticle = New MergeArticle()
Dim article2 As MergeArticle = New MergeArticle()
Dim article3 As MergeArticle = New MergeArticle()
Dim filter12 As MergeJoinFilter = New MergeJoinFilter()
Dim filter23 As MergeJoinFilter = New MergeJoinFilter()

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

' Create three merge articles that are horizontally partitioned
' using a parameterized row filter on Employee.EmployeeID, which is 
' extended to the two other articles using join filters. 
Try
    ' Connect to the Publisher.
    conn.Connect()

    ' Create each article. 
    ' For clarity, each article is defined separately. 
    ' In practice, iterative structures and arrays should 
    ' be used to efficiently create multiple articles.

    ' Set the required properties for the Employee article.
    article1.ConnectionContext = conn
    article1.Name = articleName1
    article1.DatabaseName = publicationDbName
    article1.SourceObjectName = articleName1
    article1.SourceObjectOwner = hrSchema
    article1.PublicationName = publicationName
    article1.Type = ArticleOptions.TableBased

    ' Define the parameterized filter clause based on Hostname.
    article1.FilterClause = "Employee.LoginID = HOST_NAME()"

    ' Set the required properties for the SalesOrderHeader article.
    article2.ConnectionContext = conn
    article2.Name = articleName2
    article2.DatabaseName = publicationDbName
    article2.SourceObjectName = articleName2
    article2.SourceObjectOwner = salesSchema
    article2.PublicationName = publicationName
    article2.Type = ArticleOptions.TableBased

    ' Set the required properties for the SalesOrderDetail article.
    article3.ConnectionContext = conn
    article3.Name = articleName3
    article3.DatabaseName = publicationDbName
    article3.SourceObjectName = articleName3
    article3.SourceObjectOwner = salesSchema
    article3.PublicationName = publicationName
    article3.Type = ArticleOptions.TableBased

    ' Create the articles, if they do not already exist.
    If article1.IsExistingObject = False Then
        article1.Create()
    End If
    If article2.IsExistingObject = False Then
        article2.Create()
    End If
    If article3.IsExistingObject = False Then
        article3.Create()
    End If

    ' Select published columns for SalesOrderHeader.
    ' Create an array of column names to vertically filter out.
    ' In this example, only one column is removed.
    Dim columns() As String = New String(0) {}

    columns(0) = "CreditCardApprovalCode"

    ' Remove the column.
    article2.RemoveReplicatedColumns(columns)

    ' Define a merge filter clauses that filter 
    ' SalesOrderHeader based on Employee and 
    ' SalesOrderDetail based on SalesOrderHeader. 

    ' Parent article.
    filter12.JoinArticleName = articleName1
    ' Child article.
    filter12.ArticleName = articleName2
    filter12.FilterName = filterName12
    filter12.JoinUniqueKey = True
    filter12.FilterTypes = FilterTypes.JoinFilter
    filter12.JoinFilterClause = filterClause12

    ' Add the join filter to the child article.
    article2.AddMergeJoinFilter(filter12)

    ' Parent article.
    filter23.JoinArticleName = articleName2
    ' Child article.
    filter23.ArticleName = articleName3
    filter23.FilterName = filterName23
    filter23.JoinUniqueKey = True
    filter23.FilterTypes = FilterTypes.JoinFilter
    filter23.JoinFilterClause = filterClause23

    ' Add the join filter to the child article.
    article3.AddMergeJoinFilter(filter23)

Catch ex As Exception
    ' Do error handling here and rollback the transaction.
    Throw New ApplicationException( _
        "The filtered articles could not be created", ex)
Finally
    conn.Disconnect()
End Try

此示例更改和现有的合并项目,以将业务逻辑处理程序与项目相关联。 有关详细信息,请参阅 sp_helpmergearticlecolumn (Transact-SQL) )

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

// Set the friendly name of the business logic handler.
string customLogic = "OrderEntryLogic";

MergeArticle article = new MergeArticle();

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

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

    // Set the required properties for the article.
    article.ConnectionContext = conn;
    article.Name = articleName;
    article.DatabaseName = publicationDbName;
    article.PublicationName = publicationName;

    // Load the article properties.
    if (article.LoadProperties())
    {
        article.ArticleResolver = customLogic;
    }
    else
    {
        // Throw an exception of the article does not exist.
        throw new ApplicationException(String.Format(
        "{0} is not published in {1}", articleName, publicationName));
    }
    
}
catch (Exception ex)
{
    // Do error handling here and rollback the transaction.
    throw new ApplicationException(String.Format(
        "The business logic handler {0} could not be associated with " +
        " the {1} article.",customLogic,articleName), ex);
}
finally
{
    conn.Disconnect();
}
' Define the Publisher, publication, and article names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2012"
Dim articleName As String = "SalesOrderHeader"

' Set the friendly name of the business logic handler.
Dim customLogic As String = "OrderEntryLogic"

Dim article As MergeArticle = New MergeArticle()

' 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 article.
    article.ConnectionContext = conn
    article.Name = articleName
    article.DatabaseName = publicationDbName
    article.PublicationName = publicationName

    ' Load the article properties.
    If article.LoadProperties() Then
        article.ArticleResolver = customLogic
    Else
        ' Throw an exception of the article does not exist.
        Throw New ApplicationException(String.Format( _
         "{0} is not published in {1}", articleName, publicationName))
    End If

Catch ex As Exception
    ' Do error handling here and rollback the transaction.
    Throw New ApplicationException(String.Format( _
     "The business logic handler {0} could not be associated with " + _
     " the {1} article.", customLogic, articleName), ex)
Finally
    conn.Disconnect()
End Try

注解

线程安全性

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

构造函数

MergeArticle()

创建 MergeArticle 类的新实例。

MergeArticle(String, String, String, ServerConnection)

使用指定的名称、发布、数据库和与 Microsoft SQL Server 实例的连接创建 类的新MergeArticle实例。

属性

AllowInteractiveResolver

获取或设置在同步过程中发生冲突时是否允许订阅调用交互式冲突解决程序。

ArticleId

获取项目 ID 值。

(继承自 Article)
ArticleResolver

获取或设置同步项目时使用的自定义冲突解决程序或业务逻辑处理程序的友好名称。

CachePropertyChanges

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

(继承自 ReplicationObject)
CheckPermissions

获取或设置在从订阅服务器上载更改前在发布服务器上检查权限的方式。

ColumnTracking

获取或设置同步数据行时如何检测冲突。

CompensateForErrors

获取或设置在同步过程中遇到错误时是否采取补救措施。

ConflictTable

获取用于跟踪在同步合并项目时发生的冲突的表的名称。

ConnectionContext

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

(继承自 ReplicationObject)
CreateArticleAsHeterogeneous

获取或设置一个值,该值指示是否创建异类项目。

(继承自 Article)
CreationScript

获取或设置用于在订阅服务器上创建目标对象的 Transact-SQL 脚本文件的名称和完整路径。

(继承自 Article)
DatabaseName

获取或设置包含在项目中发布的数据和对象的数据库的名称。

(继承自 Article)
DeleteTracking

获取或设置是否复制删除。

Description

获取或设置项目的文本说明。

(继承自 Article)
DestinationObjectName

获取或设置作为订阅服务器上项目的源数据库对象的数据库对象。

(继承自 Article)
DestinationObjectOwner

获取或设置订阅服务器上项目的源数据库对象的架构所有者。

(继承自 Article)
FilterClause

获取或设置 WHERE (Transact-SQL) 子句,该子句被计算为水平筛选项目。

IdentityRangeManagementOption

获取或设置项目的标识范围管理选项。

(继承自 Article)
IdentityRangeThreshold

获取或设置标识列值的新范围按其分配给发布服务器或订阅服务器的值。

(继承自 Article)
IsExistingObject

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

(继承自 ReplicationObject)
MultipleColumnUpdate

获取或设置一个值,该值指示是否更新多个列。

Name

获取或设置项目的名称。

(继承自 Article)
PartitionOption

获取或设置使用参数化行筛选器筛选项目时的筛选选项。

PreCreationMethod

获取或设置在订阅数据库中已存在已发布对象时要执行的操作。

(继承自 Article)
ProcessingOrder

获取或设置在同步过程中项目的处理顺序。

PublicationName

获取或设置项目所属于的发布的名称。

(继承自 Article)
PublisherIdentityRangeSize

获取或设置分配给发布服务器上的表列的标识值的范围。

(继承自 Article)
ResolverInfo

获取或设置要由基于 COM 的冲突解决程序使用的附加数据和参数。

SchemaOption

获取或设置项目的架构创建选项。

(继承自 Article)
SnapshotObjectName

获取表示项目的初始快照数据的数据库对象的名称。

SnapshotObjectOwner

获取表示项目的初始快照数据的数据库对象的所有者。

SourceObjectName

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

(继承自 Article)
SourceObjectOwner

获取或设置要发布的数据库对象的所有者。

(继承自 Article)
SqlServerName

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

(继承自 ReplicationObject)
Status

获取或设置合并项目的状态。

StreamBlobColumns

获取或设置在复制二进制大型对象 (BLOB) 列时是否使用数据流优化。

SubscriberIdentityRangeSize

获取或设置在必须分配其他标识范围前可以插入到订阅服务器上的表中的标识列的最大新行数。

(继承自 Article)
SubscriberUploadOption

获取或设置在包含客户端订阅的订阅服务器上进行更新的行为。

Type

获取或设置项目的类型。

(继承自 Article)
UserData

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

(继承自 ReplicationObject)
VerifyResolverSignature

获取或设置用于在基于 COM 的冲突解决程序上验证数字签名以确定它是否来自可信来源的选项。

VerticalPartition

获取一个值,该值指示是否在表项目中发布所有列。

(继承自 Article)

方法

AddMergeJoinFilter(MergeJoinFilter)

向合并项目添加联接筛选器。

AddReplicatedColumns(Array)

向合并项目添加指定的列。

ChangeMergeJoinFilter(MergeJoinFilter, MergeJoinFilter)

更改对合并项目定义的联接筛选器。

CheckValidCreation()

检查有效项目创建。

(继承自 Article)
CheckValidDefinition(Boolean)

指示定义是否有效。

(继承自 Article)
CommitPropertyChanges()

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

(继承自 ReplicationObject)
Create()

基于 对象或 对象的当前属性TransArticle,在当前连接的 SQL Server 实例上MergeArticle创建一个新项目。

(继承自 Article)
Decouple()

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

(继承自 ReplicationObject)
EnumMergeJoinFilters()

返回为合并项目定义的联接筛选器。

GetChangeCommand(StringBuilder, String, String)

从复制返回更改命令。

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

从复制返回创建命令。

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

从复制返回删除命令。

(继承自 ReplicationObject)
InitializeSharedPropertiesBasedOnExistingArticles()

指示是否基于现有项目初始化共享属性。

InternalRefresh(Boolean)

从复制启动内部刷新。

(继承自 ReplicationObject)
ListReplicatedColumns()

返回垂直分区的项目中所存在的列。

Load()

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

(继承自 ReplicationObject)
LoadProperties()

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

(继承自 ReplicationObject)
Refresh()

重新加载该对象的属性。

(继承自 ReplicationObject)
Remove()

根据对象的当前属性或对象的当前属性TransArticle,删除当前连接的 SQL Server 实例上的MergeArticle现有项目。

(继承自 Article)
RemoveMergeJoinFilter(String)

从项目中删除指定的合并联接筛选器。

RemoveReplicatedColumns(Array)

从垂直分区的项目中删除现有列。

Script(ScriptOptions)

生成一个 Transact-SQL 脚本,可以执行该脚本来创建或删除 TransArticle 服务器上的对象或 MergeArticle 对象。

(继承自 Article)
ScriptMergeJoinFilter(MergeJoinFilter, ScriptOptions)

返回附加到合并项目上的合并联接筛选器的 Transact-SQL 脚本。

适用于

另请参阅