TransPublication 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示事务发布。
public ref class TransPublication sealed : Microsoft::SqlServer::Replication::Publication
public sealed class TransPublication : Microsoft.SqlServer.Replication.Publication
type TransPublication = class
inherit Publication
Public NotInheritable Class TransPublication
Inherits Publication
- 继承
示例
此示例创建事务发布。
// Set the Publisher, publication database, and publication names.
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks2012";
string publisherName = publisherInstance;
ReplicationDatabase publicationDb;
TransPublication publication;
// Create a connection to the Publisher using Windows Authentication.
ServerConnection conn;
conn = new ServerConnection(publisherName);
try
{
// Connect to the Publisher.
conn.Connect();
// Enable the AdventureWorks2012 database for transactional publishing.
publicationDb = new ReplicationDatabase(publicationDbName, conn);
// If the database exists and is not already enabled,
// enable it for transactional publishing.
if (publicationDb.LoadProperties())
{
if (!publicationDb.EnabledTransPublishing)
{
publicationDb.EnabledTransPublishing = true;
}
// If the Log Reader Agent does not exist, create it.
if (!publicationDb.LogReaderAgentExists)
{
// Specify the Windows account under which the agent job runs.
// This account will be used for the local connection to the
// Distributor and all agent connections that use Windows Authentication.
publicationDb.LogReaderAgentProcessSecurity.Login = winLogin;
publicationDb.LogReaderAgentProcessSecurity.Password = winPassword;
// Explicitly set authentication mode for the Publisher connection
// to the default value of Windows Authentication.
publicationDb.LogReaderAgentPublisherSecurity.WindowsAuthentication = true;
// Create the Log Reader Agent job.
publicationDb.CreateLogReaderAgent();
}
}
else
{
throw new ApplicationException(String.Format(
"The {0} database does not exist at {1}.",
publicationDb, publisherName));
}
// Set the required properties for the transactional publication.
publication = new TransPublication();
publication.ConnectionContext = conn;
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
// Specify a transactional publication (the default).
publication.Type = PublicationType.Transactional;
// Activate the publication so that we can add subscriptions.
publication.Status = State.Active;
// Enable push and pull subscriptions and independent Distribition Agents.
publication.Attributes |= PublicationAttributes.AllowPull;
publication.Attributes |= PublicationAttributes.AllowPush;
publication.Attributes |= PublicationAttributes.IndependentAgent;
// 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;
if (!publication.IsExistingObject)
{
// Create the transactional 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 publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks2012"
Dim publisherName As String = publisherInstance
Dim publicationDb As ReplicationDatabase
Dim publication As TransPublication
' Create a connection to the Publisher using Windows Authentication.
Dim conn As ServerConnection
conn = New ServerConnection(publisherName)
Try
' Connect to the Publisher.
conn.Connect()
' Enable the AdventureWorks2012 database for transactional publishing.
publicationDb = New ReplicationDatabase(publicationDbName, conn)
' If the database exists and is not already enabled,
' enable it for transactional publishing.
If publicationDb.LoadProperties() Then
If Not publicationDb.EnabledTransPublishing Then
publicationDb.EnabledTransPublishing = True
End If
' If the Log Reader Agent does not exist, create it.
If Not publicationDb.LogReaderAgentExists Then
' Specify the Windows account under which the agent job runs.
' This account will be used for the local connection to the
' Distributor and all agent connections that use Windows Authentication.
publicationDb.LogReaderAgentProcessSecurity.Login = winLogin
publicationDb.LogReaderAgentProcessSecurity.Password = winPassword
' Explicitly set authentication mode for the Publisher connection
' to the default value of Windows Authentication.
publicationDb.LogReaderAgentPublisherSecurity.WindowsAuthentication = True
' Create the Log Reader Agent job.
publicationDb.CreateLogReaderAgent()
End If
Else
Throw New ApplicationException(String.Format( _
"The {0} database does not exist at {1}.", _
publicationDb, publisherName))
End If
' Set the required properties for the transactional publication.
publication = New TransPublication()
publication.ConnectionContext = conn
publication.Name = publicationName
publication.DatabaseName = publicationDbName
' Specify a transactional publication (the default).
publication.Type = PublicationType.Transactional
'Enable push and pull subscriptions and independent Distribition Agents.
publication.Attributes = _
publication.Attributes Or PublicationAttributes.AllowPull
publication.Attributes = _
publication.Attributes Or PublicationAttributes.AllowPush
publication.Attributes = _
publication.Attributes Or PublicationAttributes.IndependentAgent
' Activate the publication so that we can add subscriptions.
publication.Status = State.Active
' 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
If Not publication.IsExistingObject Then
' Create the transactional 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 Publisher, publication database,
// and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks2012";
TransPublication publication;
ReplicationDatabase publicationDb;
// Create a connection to the Publisher
// using Windows Authentication.
ServerConnection conn = new ServerConnection(publisherName);
try
{
conn.Connect();
// Set the required properties for the transactional publication.
publication = new TransPublication();
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 transactional publications exists,
// disable publishing on the database.
publicationDb = new ReplicationDatabase(publicationDbName, conn);
if (publicationDb.LoadProperties())
{
if (publicationDb.TransPublications.Count == 0)
{
publicationDb.EnabledTransPublishing = 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 = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks2012"
Dim publication As TransPublication
Dim publicationDb As ReplicationDatabase
' Create a connection to the Publisher
' using Windows Authentication.
Dim conn As ServerConnection = New ServerConnection(publisherName)
Try
conn.Connect()
' Set the required properties for the transactional publication.
publication = New TransPublication()
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 transactional publications exists,
' disable publishing on the database.
publicationDb = New ReplicationDatabase(publicationDbName, conn)
If publicationDb.LoadProperties() Then
If publicationDb.TransPublications.Count = 0 Then
publicationDb.EnabledTransPublishing = 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
(对于多线程操作都是安全的。 但不保证所有实例成员都是线程安全的。
构造函数
TransPublication() |
创建 TransPublication 类的新实例。 |
TransPublication(String, String, ServerConnection) |
使用所需的属性创建 TransPublication 类的新实例。 |
TransPublication(String, String, ServerConnection, Boolean) |
使用所需的属性创建 TransPublication 类的新实例,并且指示是否为发布创建快照代理作业。 |
属性
AltSnapshotFolder |
获取或设置用于发布的备用快照文件位置。 (继承自 Publication) |
Attributes |
获取或设置发布属性。 (继承自 Publication) |
CachePropertyChanges |
获取或设置是缓存对复制属性所做的更改还是立即应用它们。 (继承自 ReplicationObject) |
CompatibilityLevel |
获取或设置引用的发布可以支持的订阅服务器上运行的最早版本的 Microsoft SQL Server。 (继承自 Publication) |
ConflictPolicy |
获取或设置支持更新订阅的发布的冲突策略。 |
ConflictRetention |
获取或设置在冲突表中保留冲突数据行的天数。 (继承自 Publication) |
ConnectionContext |
获取或设置与 Microsoft SQL Server 实例的连接。 (继承自 ReplicationObject) |
ContinueOnConflict |
确定检测到冲突后分发代理是否继续处理更改。 |
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) |
Name |
获取或设置发布的名称。 (继承自 Publication) |
PeerConflictDetectionEnabled |
获取是否通过使用 SetPeerConflictDetection(Boolean, Int32) 启用了对等冲突检测。 |
PeerOriginatorID |
获取对等拓扑中某一节点的 ID;在 PeerConflictDetectionEnabled 设置为 |
PostSnapshotScript |
获取或设置在初始快照应用到订阅服务器后执行的 Transact-SQL 脚本文件的名称和完整路径。 (继承自 Publication) |
PreSnapshotScript |
获取或设置在将初始快照应用到订阅服务器之前执行的 Transact-SQL 脚本文件的名称和完整路径。 (继承自 Publication) |
PubId |
获取唯一标识发布的值。 (继承自 Publication) |
PublisherName |
获取或设置非 SQL Server 发布服务器的名称。 |
QueueType |
获取或设置用于允许排队更新订阅的发布的队列的类型。 |
ReplicateDdl |
获取或设置用于确定是否复制 DDL 更改的数据定义语言 (DDL) 复制选项。 (继承自 Publication) |
RetentionPeriod |
获取或设置在某一订阅未与发布同步时经过多长时间该订阅到期。 (继承自 Publication) |
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) |
TransArticles |
表示发布中的项目。 |
TransSubscriptions |
表示对发布的订阅。 |
Type |
获取或设置发布的类型。 (继承自 Publication) |
UserData |
获取或设置允许用户将他们自己的数据附加到该对象的对象属性。 (继承自 ReplicationObject) |