本主题介绍如何使用 SQL Server Management Studio、Transact-SQL 或复制管理对象(RMO)在 SQL Server 2014 中查看和修改发布属性。
本主题内容
准备工作:
若要查看和修改发布属性,请使用:
在您开始之前
局限性与限制
- 某些属性在创建发布后无法修改,如果存在发布订阅,则不能修改其他属性。 无法修改的属性显示为只读。
建议
- 发布完成后,某些属性更改需要新的快照。 若某出版物有订阅,某些更改还需要重新初始化所有订阅。 有关详细信息,请参阅 “更改发布”和“项目属性 ”,以及 向现有发布添加项目以及从现有发布中删除项目。
使用 SQL Server Management Studio
在 “发布属性 - <发布”对话框中查看和修改发布> 属性,该对话框在 SQL Server Management Studio 和复制监视器中可用。 有关启动复制监视器的信息,请参阅 “启动复制监视器”。
“ 发布属性 - <发布> ”对话框包含以下页面:
“ 常规 ”页包括发布名称和说明、数据库名称、发布类型以及订阅过期设置。
“ 项目 ”页对应于“新建发布向导”中的“ 项目 ”页。 使用此页可添加和删除项目,以及更改项目的属性和列筛选。
“筛选行”页面对应于“新建发布向导”中的“筛选表行”页面。 使用此页可为所有类型的发布添加、编辑和删除静态行筛选器,以及添加、编辑和删除合并发布的参数化行筛选器和联接筛选器。
“ 快照 ”页允许你指定快照的格式和位置、是否应压缩快照,以及应用快照之前和之后要运行的脚本。
FTP 快照页(适用于快照和事务性发布,以及针对运行 SQL Server 2005 之前版本的发布服务器的合并发布)允许您指定订阅者是否可以通过文件传输协议(FTP)下载快照文件。
FTP 快照和 Internet 页面(适用于运行 SQL Server 2005 或更高版本的发布服务器进行合并发布)允许您指定订阅者是否可以通过 FTP 下载快照文件,以及订阅者是否可以通过 HTTPS 同步订阅。
“ 订阅选项” 页允许设置应用于所有订阅的多个选项。 选项因发布类型而异。
" 发布访问列表 "页面允许您指定哪些登录名和组可以访问某一发布。
“代理安全”页允许您访问以下代理运行的帐户设置,并实现与复制拓扑中计算机的连接:用于所有发布的快照代理;用于所有事务性发布的日志读取器代理;以及用于允许排队更新订阅的事务性发布的队列读取器代理。
“数据分区”页(用于运行 SQL Server 2005 或更高版本的发布服务器的合并发布)允许您指定是否允许具有参数化筛选器的订阅服务器在没有可用快照时请求生成快照。 它还允许您为一个或多个分区生成快照,可以选择一次性生成或按定期计划生成。
在 Management Studio 中查看和修改发布属性
在 Management Studio 中连接到发布服务器,然后展开服务器节点。
展开 “复制 ”文件夹,然后展开 “本地发布” 文件夹。
右键单击发布,然后单击“ 属性”。
根据需要修改任何属性,然后单击“ 确定”。
在复制监视器中查看和修改发布属性
在复制监视器的左窗格中展开发布者组,然后展开发布者。
右键单击发布,然后单击“ 属性”。
根据需要修改任何属性,然后单击“ 确定”。
使用 Transact-SQL
可以使用复制存储过程以编程方式修改发布及其属性。 使用的存储过程将取决于发布的类型。
查看快照或事务发布的属性
- 执行 sp_helppublication,指定 @publication 参数的发布名称。 如果未指定此参数,则会返回发布方所有出版物的信息。
更改快照或事务发布的属性
执行 sp_changepublication,指定要在 @property 参数中更改的发布属性,并在 @value 参数中指定此属性的新值。
注释
如果更改需要生成新快照,则还必须为@force_invalidate_snapshot指定值 1,如果更改要求重新初始化订阅服务器,则必须为@force_reinit_subscription指定值 1。 有关更改时需要新快照或重新初始化的属性的详细信息,请参阅更改发布和文章属性。
查看合并出版物的属性
- 执行 sp_helpmergepublication,指定 @publication 参数的发布名称。 如果未指定此参数,则会返回有关该出版商所有发布物的信息。
更改合并发布的属性
执行 sp_changemergepublication,指定 @property 参数中正在更改的发布属性,并在 @value 参数中指定此属性的新值。
注释
如果更改需要生成新快照,则还必须为@force_invalidate_snapshot指定值 1,如果更改需要重新初始化订阅者,则必须为@force_reinit_subscription指定值 1。有关更改时需要新快照或重新初始化的属性的详细信息,请参阅更改发布和项目属性。
查看快照的属性
- 执行 sp_helppublication_snapshot,指定 @publication 参数的发布名称。
更改快照的属性
- 执行 sp_changepublication_snapshot,为相应的快照参数指定一个或多个新的快照属性。
示例 (Transact-SQL)
此事务性复制示例返回了发布的属性。
DECLARE @myTranPub AS sysname
SET @myTranPub = N'AdvWorksProductTran'
USE [AdventureWorks2012]
EXEC sp_helppublication @publication = @myTranPub
GO
此事务复制示例禁用发布的架构复制。
DECLARE @publication AS sysname
SET @publication = N'AdvWorksProductTran'
-- Turn off DDL replication for the transactional publication.
USE [AdventureWorks2012]
EXEC sp_changepublication
@publication = @publication,
@property = N'replicate_ddl',
@value = 0
GO
此合并复制示例返回该发布的相关属性。
DECLARE @publication AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
USE [AdventureWorks2012]
EXEC sp_helpmergepublication @publication = @publication;
GO
此合并复制示例禁用了发布中的架构复制。
DECLARE @publication AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
-- Disable DDL replication for the publication.
USE [AdventureWorks2012]
EXEC sp_changemergepublication
@publication = @publication,
@property = N'replicate_ddl',
@value = 0,
@force_invalidate_snapshot = 0,
@force_reinit_subscription = 0;
GO
使用复制管理对象 (RMO)
可以使用复制管理对象(RMO)以编程方式修改发布并访问其属性。 用于查看或修改发布属性的 RMO 类取决于发布的类型。
查看或修改快照或事务发布的属性
使用 ServerConnection 类创建与发布服务器的连接。
创建TransPublication类的一个实例,设置出版物的Name和DatabaseName属性,并将ConnectionContext属性设置为在步骤1中创建的连接。
调用 LoadProperties 方法获取该对象的属性。 如果此方法返回
false,则步骤 2 中的发布属性定义不正确或发布不存在。(可选)若要更改属性,请为一个或多个可设置的属性设置一个新值。 使用逻辑 AND 运算符(
&在 Microsoft Visual C# 中,And在 Microsoft Visual Basic 中)来确定是否为Attributes属性设置了给定PublicationAttributes值。 使用包含逻辑 OR 运算符(|在 Visual C# 和OrVisual Basic 中)和排他逻辑 OR 运算符(^在 Visual C# 和XorVisual Basic 中)更改 PublicationAttributes 属性 Attributes 的值。(可选)如果已将
true的值指定为 CachePropertyChanges,则调用 CommitPropertyChanges 方法以在服务器上提交更改。 如果将false的值指定为 CachePropertyChanges(默认值),则会将更改立即发送到服务器。
查看或修改合并发布项的属性
使用 ServerConnection 类创建与发布服务器的连接。
创建MergePublication类的实例,设置Name和DatabaseName属性用于发布,并将ConnectionContext属性设置为在步骤 1 中创建的连接。
调用 LoadProperties 方法获取该对象的属性。 如果此方法返回
false,则步骤 2 中的发布属性定义不正确或发布不存在。(可选)若要更改属性,请为一个或多个可设置的属性设置一个新值。 使用逻辑 AND 运算符(在 Visual C# 中为
&,在 Visual Basic 中为And)来确定是否为Attributes属性设置了给定的PublicationAttributes值。 使用包含型逻辑 OR 运算符(|在 Visual C# 中,Or在 Visual Basic 中)和专属型逻辑 OR 运算符(^在 Visual C# 中,Xor在 Visual Basic 中)更改 PublicationAttributes 属性的值 Attributes。(可选)如果已将
true的值指定为 CachePropertyChanges,则调用 CommitPropertyChanges 方法以在服务器上提交更改。 如果将false的值指定为 CachePropertyChanges(默认值),则会将更改立即发送到服务器。
示例 (RMO)
此示例设置事务性发布的发布属性。 更改会被缓存,直到明确发送到服务器为止。
// Define the server, database, and publication names
string publisherName = publisherInstance;
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks2012";
TransPublication 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 TransPublication();
publication.ConnectionContext = conn;
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
// Explicitly enable caching of property changes on this object.
publication.CachePropertyChanges = true;
// If we can't get the properties for this publication,
// throw an application exception.
if (publication.LoadProperties())
{
// Enable support for push subscriptions and disable support
// for pull subscriptions.
if ((publication.Attributes & PublicationAttributes.AllowPull) != 0)
{
publication.Attributes ^= PublicationAttributes.AllowPull;
}
if ((publication.Attributes & PublicationAttributes.AllowPush) == 0)
{
publication.Attributes |= PublicationAttributes.AllowPush;
}
// Send changes to the server.
publication.CommitPropertyChanges();
}
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 = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks2012"
Dim publication As TransPublication
' 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 TransPublication()
publication.ConnectionContext = conn
publication.Name = publicationName
publication.DatabaseName = publicationDbName
' Explicitly enable caching of property changes on this object.
publication.CachePropertyChanges = True
' If we can't get the properties for this publication,
' throw an application exception.
If publication.LoadProperties() Then
' Enable support for push subscriptions and disable support
' for pull subscriptions.
If (publication.Attributes And PublicationAttributes.AllowPull) <> 0 Then
publication.Attributes = publication.Attributes _
Xor PublicationAttributes.AllowPull
End If
If (publication.Attributes And PublicationAttributes.AllowPush) = 0 Then
publication.Attributes = publication.Attributes _
Or PublicationAttributes.AllowPush
End If
' Send changes to the server.
publication.CommitPropertyChanges()
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
此示例禁用合并发布中的 DDL 复制。
// 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
另请参阅
发布数据和数据库对象
更改发布和项目属性
对发布数据库进行架构更改
复制系统存储过程概念
向发布添加项目并从中删除项目
使用复制监视器查看信息和执行任务
查看和修改项目属性