DistributionPublisher 类

定义

表示在当前连接的分发服务器上注册的发布服务器的有关信息。

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

示例

此示例演示如何 DistributionPublisher 使用 对象来启用发布。

// Set the server and database names
string distributionDbName = "distribution";
string publisherName = publisherInstance;
string publicationDbName = "AdventureWorks2012";

DistributionDatabase distributionDb;
ReplicationServer distributor;
DistributionPublisher publisher;
ReplicationDatabase publicationDb;

// Create a connection to the server using Windows Authentication.
ServerConnection conn = new ServerConnection(publisherName);

try
{
    // Connect to the server acting as the Distributor 
    // and local Publisher.
    conn.Connect();

    // Define the distribution database at the Distributor,
    // but do not create it now.
    distributionDb = new DistributionDatabase(distributionDbName, conn);
    distributionDb.MaxDistributionRetention = 96;
    distributionDb.HistoryRetention = 120;

    // Set the Distributor properties and install the Distributor.
    // This also creates the specified distribution database.
    distributor = new ReplicationServer(conn);
    distributor.InstallDistributor((string)null, distributionDb);

    // Set the Publisher properties and install the Publisher.
    publisher = new DistributionPublisher(publisherName, conn);
    publisher.DistributionDatabase = distributionDb.Name;
    publisher.WorkingDirectory = @"\\" + publisherName + @"\repldata";
    publisher.PublisherSecurity.WindowsAuthentication = true;
    publisher.Create();

    // Enable AdventureWorks2012 as a publication database.
    publicationDb = new ReplicationDatabase(publicationDbName, conn);

    publicationDb.EnabledTransPublishing = true;
    publicationDb.EnabledMergePublishing = true;
}
catch (Exception ex)
{
    // Implement appropriate error handling here.
    throw new ApplicationException("An error occured when installing distribution and publishing.", ex);
}
finally
{
    conn.Disconnect();
}
' Set the server and database names
Dim distributionDbName As String = "distribution"
Dim publisherName As String = publisherInstance
Dim publicationDbName As String = "AdventureWorks2012"

Dim distributionDb As DistributionDatabase
Dim distributor As ReplicationServer
Dim publisher As DistributionPublisher
Dim publicationDb As ReplicationDatabase

' Create a connection to the server using Windows Authentication.
Dim conn As ServerConnection = New ServerConnection(publisherName)

Try
    ' Connect to the server acting as the Distributor 
    ' and local Publisher.
    conn.Connect()

    ' Define the distribution database at the Distributor,
    ' but do not create it now.
    distributionDb = New DistributionDatabase(distributionDbName, conn)
    distributionDb.MaxDistributionRetention = 96
    distributionDb.HistoryRetention = 120

    ' Set the Distributor properties and install the Distributor.
    ' This also creates the specified distribution database.
    distributor = New ReplicationServer(conn)
    distributor.InstallDistributor((CType(Nothing, String)), distributionDb)

    ' Set the Publisher properties and install the Publisher.
    publisher = New DistributionPublisher(publisherName, conn)
    publisher.DistributionDatabase = distributionDb.Name
    publisher.WorkingDirectory = "\\" + publisherName + "\repldata"
    publisher.PublisherSecurity.WindowsAuthentication = True
    publisher.Create()

    ' Enable AdventureWorks2012 as a publication database.
    publicationDb = New ReplicationDatabase(publicationDbName, conn)

    publicationDb.EnabledTransPublishing = True
    publicationDb.EnabledMergePublishing = True

Catch ex As Exception
    ' Implement appropriate error handling here.
    Throw New ApplicationException("An error occured when installing distribution and publishing.", ex)

Finally
    conn.Disconnect()

End Try

此示例演示如何 DistributionPublisher 使用 对象在分发服务器上禁用发布。

// Set the Distributor and publication database names.
// Publisher and Distributor are on the same server instance.
string publisherName = publisherInstance;
string distributorName = publisherInstance;
string distributionDbName = "distribution";
string publicationDbName = "AdventureWorks2012";

// Create connections to the Publisher and Distributor
// using Windows Authentication.
ServerConnection publisherConn = new ServerConnection(publisherName);
ServerConnection distributorConn = new ServerConnection(distributorName);

// Create the objects we need.
ReplicationServer distributor =
    new ReplicationServer(distributorConn);
DistributionPublisher publisher;
DistributionDatabase distributionDb =
    new DistributionDatabase(distributionDbName, distributorConn);
ReplicationDatabase publicationDb;
publicationDb = new ReplicationDatabase(publicationDbName, publisherConn);

try
{
    // Connect to the Publisher and Distributor.
    publisherConn.Connect();
    distributorConn.Connect();

    // Disable all publishing on the AdventureWorks2012 database.
    if (publicationDb.LoadProperties())
    {
        if (publicationDb.EnabledMergePublishing)
        {
            publicationDb.EnabledMergePublishing = false;
        }
        else if (publicationDb.EnabledTransPublishing)
        {
            publicationDb.EnabledTransPublishing = false;
        }
    }
    else
    {
        throw new ApplicationException(
            String.Format("The {0} database does not exist.", publicationDbName));
    }

    // We cannot uninstall the Publisher if there are still Subscribers.
    if (distributor.RegisteredSubscribers.Count == 0)
    {
        // Uninstall the Publisher, if it exists.
        publisher = new DistributionPublisher(publisherName, distributorConn);
        if (publisher.LoadProperties())
        {
            publisher.Remove(false);
        }
        else
        {
            // Do something here if the Publisher does not exist.
            throw new ApplicationException(String.Format(
                "{0} is not a Publisher for {1}.", publisherName, distributorName));
        }

        // Drop the distribution database.
        if (distributionDb.LoadProperties())
        {
            distributionDb.Remove();
        }
        else
        {
            // Do something here if the distribition DB does not exist.
            throw new ApplicationException(String.Format(
                "The distribution database '{0}' does not exist on {1}.",
                distributionDbName, distributorName));
        }

        // Uninstall the Distributor, if it exists.
        if (distributor.LoadProperties())
        {
            // Passing a value of false means that the Publisher 
            // and distribution databases must already be uninstalled,
            // and that no local databases be enabled for publishing.
            distributor.UninstallDistributor(false);
        }
        else
        {
            //Do something here if the distributor does not exist.
            throw new ApplicationException(String.Format(
                "The Distributor '{0}' does not exist.", distributorName));
        }
    }
    else
    {
        throw new ApplicationException("You must first delete all subscriptions.");
    }
}
catch (Exception ex)
{
    // Implement appropriate error handling here.
    throw new ApplicationException("The Publisher and Distributor could not be uninstalled", ex);
}
finally
{
    publisherConn.Disconnect();
    distributorConn.Disconnect();
}
' Set the Distributor and publication database names.
' Publisher and Distributor are on the same server instance.
Dim publisherName As String = publisherInstance
Dim distributorName As String = subscriberInstance
Dim distributionDbName As String = "distribution"
Dim publicationDbName As String = "AdventureWorks2012"

' Create connections to the Publisher and Distributor
' using Windows Authentication.
Dim publisherConn As ServerConnection = New ServerConnection(publisherName)
Dim distributorConn As ServerConnection = New ServerConnection(distributorName)

' Create the objects we need.
Dim distributor As ReplicationServer
distributor = New ReplicationServer(distributorConn)
Dim publisher As DistributionPublisher
Dim distributionDb As DistributionDatabase
distributionDb = New DistributionDatabase(distributionDbName, distributorConn)
Dim publicationDb As ReplicationDatabase
publicationDb = New ReplicationDatabase(publicationDbName, publisherConn)

Try
    ' Connect to the Publisher and Distributor.
    publisherConn.Connect()
    distributorConn.Connect()

    ' Disable all publishing on the AdventureWorks2012 database.
    If publicationDb.LoadProperties() Then
        If publicationDb.EnabledMergePublishing Then
            publicationDb.EnabledMergePublishing = False
        ElseIf publicationDb.EnabledTransPublishing Then
            publicationDb.EnabledTransPublishing = False
        End If
    Else
        Throw New ApplicationException( _
            String.Format("The {0} database does not exist.", publicationDbName))
    End If

    ' We cannot uninstall the Publisher if there are still Subscribers.
    If distributor.RegisteredSubscribers.Count = 0 Then
        ' Uninstall the Publisher, if it exists.
        publisher = New DistributionPublisher(publisherName, distributorConn)
        If publisher.LoadProperties() Then
            publisher.Remove(False)
        Else
            ' Do something here if the Publisher does not exist.
            Throw New ApplicationException(String.Format( _
                "{0} is not a Publisher for {1}.", publisherName, distributorName))
        End If

        ' Drop the distribution database.
        If distributionDb.LoadProperties() Then
            distributionDb.Remove()
        Else
            ' Do something here if the distribition DB does not exist.
            Throw New ApplicationException(String.Format( _
             "The distribution database '{0}' does not exist on {1}.", _
             distributionDbName, distributorName))
        End If

        ' Uninstall the Distributor, if it exists.
        If distributor.LoadProperties() Then
            ' Passing a value of false means that the Publisher 
            ' and distribution databases must already be uninstalled,
            ' and that no local databases be enabled for publishing.
            distributor.UninstallDistributor(False)
        Else
            'Do something here if the distributor does not exist.
            Throw New ApplicationException(String.Format( _
                "The Distributor '{0}' does not exist.", distributorName))
        End If
    Else
        Throw New ApplicationException("You must first delete all subscriptions.")
    End If

Catch ex As Exception
    ' Implement appropriate error handling here.
    Throw New ApplicationException("The Publisher and Distributor could not be uninstalled", ex)

Finally
    publisherConn.Disconnect()
    distributorConn.Disconnect()

End Try

注解

DistributionPublisher 需要与发布服务器使用的分发服务器建立连接。

线程安全性

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

构造函数

DistributionPublisher()

创建 DistributionPublisher 类的新实例。

DistributionPublisher(String, ServerConnection)

使用发布服务器名称和与发布服务器使用的分发服务器的连接来创建 DistributionPublisher 类的新实例。

属性

CachePropertyChanges

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

(继承自 ReplicationObject)
ConnectionContext

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

(继承自 ReplicationObject)
DistributionDatabase

获取或设置发布服务器使用的分发数据库的名称。

DistributionPublications

获取发布服务器上存在的发布。

HeterogeneousLogReaderAgentExists

获取一个值,该值指示对于非 SQL Server 发布服务器日志读取器代理作业是否存在。

HeterogeneousLogReaderAgentProcessSecurity

获取非 SQL Server 发布服务器的日志读取器代理使用的安全上下文。

IsExistingObject

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

(继承自 ReplicationObject)
Name

获取或设置 Microsoft SQL Server 的 Publisher 实例的名称。

PublisherSecurity

获取在连接到发布服务器时复制代理使用的安全上下文。

PublisherType

获取或设置发布服务器类型。

RegisteredSubscribers

获取订阅发布服务器上的发布的订阅服务器。

SqlServerName

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

(继承自 ReplicationObject)
Status

获取发布服务器状态。

ThirdParty

获取或设置一个值,该值指示发布服务器是否为非 SQL Server 发布服务器。

TransPublications

获取位于发布服务器上的事务发布。

TrustedDistributorConnection

获取或设置一个值,该值指示是否信任分发服务器连接。

UserData

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

(继承自 ReplicationObject)
WorkingDirectory

获取或设置用于存储发布的数据和架构文件的工作目录的名称。

方法

CheckValidCreation()

检查有效复制创建。

(继承自 ReplicationObject)
CheckValidDefinition(Boolean)

指示定义是否有效。

(继承自 ReplicationObject)
CommitPropertyChanges()

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

(继承自 ReplicationObject)
Create()

使用分发服务器的指定属性注册发布服务器。

CreateHeterogeneousLogReaderAgent()

为非 SQL Server 发布服务器创建日志读取器代理作业。

Decouple()

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

(继承自 ReplicationObject)
EnumDistributionPublications()

返回与此发布服务器上的发布有关的存储在分发服务器上的信息。

EnumRegisteredSubscribers()

返回与此发布服务器上的发布的订阅服务器有关的存储在分发服务器上的信息。

EnumTransPublications()

返回与此发布服务器上的事务发布有关的分发服务器上的信息。

GetChangeCommand(StringBuilder, String, String)

从复制返回更改命令。

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

从复制返回创建命令。

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

从复制返回删除命令。

(继承自 ReplicationObject)
InternalRefresh(Boolean)

从复制启动内部刷新。

(继承自 ReplicationObject)
Load()

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

(继承自 ReplicationObject)
LoadProperties()

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

(继承自 ReplicationObject)
Refresh()

重新加载该对象的属性。

(继承自 ReplicationObject)
Remove(Boolean)

从当前连接的分发服务器中删除此发布服务器的注册。

Script(ScriptOptions)

生成可用于安装或卸载发布服务器的 Transact-SQL 脚本。

适用于

另请参阅