MergePublication 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
代表合并出版物。
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
注解
线程安全性
任何此类公共静态(SharedMicrosoft Visual Basic)成员对多线程操作都是安全的。 不能保证任何实例成员是线程安全的。
构造函数
| 名称 | 说明 |
|---|---|
| MergePublication() |
创建类的新实例 MergePublication 。 |
| MergePublication(String, String, ServerConnection, Boolean) |
创建该类的实例MergePublication,指定是否应默认创建 快照代理 作业。 |
| MergePublication(String, String, ServerConnection) |
初始化一个带有指定名称、数据库及与Publisher连接的类的新实例MergePublication。 |
属性
| 名称 | 说明 |
|---|---|
| AltSnapshotFolder |
获取或设置发布的备用快照文件位置。 (继承自 Publication) |
| Attributes |
获取或设置出版属性。 (继承自 Publication) |
| AutomaticReinitializationPolicy |
当订阅因发布内容变更而重新初始化时,获取或设置Publisher的变更是否上传到Publisher。 |
| 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 |
为登录登录的对象设置密码(作为 SecureString 对象),用于连接允许通过FTP初始化订阅的发布文件传输协议(FTP)。 (继承自 Publication) |
| SnapshotAgentExists |
获取是否存在 SQL Server 代理 作业以生成本出版物的初始快照。 (继承自 Publication) |
| SnapshotAvailable |
获取或设置一个值,表示本出版物的快照文件是否已生成并可供初始化订阅者使用。 |
| SnapshotGenerationAgentProcessSecurity |
获取一个对象,设置Windows账户,从而运行快照代理作业。 (继承自 Publication) |
| SnapshotGenerationAgentPublisherSecurity |
获取 快照代理 用于连接 Publisher 的安全上下文。 (继承自 Publication) |
| SnapshotJobId |
获取当前发布的 快照代理 作业 ID。 (继承自 Publication) |
| SnapshotMethod |
获取或设置初始快照的数据文件格式。 (继承自 Publication) |
| SnapshotSchedule |
获取一个对象,为当前发布的 快照代理 设置调度。 (继承自 Publication) |
| SqlServerName |
获取该对象所连接的 Microsoft SQL Server 实例名称。 (继承自 ReplicationObject) |
| Status |
获取或确定出版物的状态。 (继承自 Publication) |
| Type |
获取或确定发表的类型。 (继承自 Publication) |
| UserData |
获取或设置一个对象属性,允许用户将自己的数据附加到该对象上。 (继承自 ReplicationObject) |
| UsesHostName |
获得一个值,表示合并发布是否包含参数化的行过滤器,该过滤器使用 HOST_NAME 函数来评估分区。 |
| ValidateSubscriberInfo |
在使用参数化行过滤器时,获取或设置用于定义已发布数据订阅者分区的函数。 |
| WebSynchronizationUrl |
获取或设置用于网页同步的URL。 |