共用方式為


ReplicationServer.InstallDistributor Method

Definition

Installs a Distributor.

Overloads

InstallDistributor(String, String)

Registers a remote Distributor.

InstallDistributor(String, SecureString)

Registers a remote Distributor, where the password is specified using a SecureString object.

InstallDistributor(SecureString, DistributionDatabase)

Installs a Distributor on the currently connected instance of Microsoft SQL Server, where the password is specified using a SecureString object.

InstallDistributor(String, DistributionDatabase)

Installs a Distributor on the currently connected instance of Microsoft SQL Server.

Examples

// 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();
}

InstallDistributor(String, String)

Registers a remote Distributor.

public:
 void InstallDistributor(System::String ^ distributionServerName, System::String ^ password);
public void InstallDistributor (string distributionServerName, string password);
member this.InstallDistributor : string * string -> unit
Public Sub InstallDistributor (distributionServerName As String, password As String)

Parameters

distributionServerName
String

A String value that specifies the name of the remote server to be used as the Distributor for the current Publisher server. The distribution server name cannot be the same as the current server.

password
String

A String value that specifies the password. This is the same value used when calling InstallDistributor(String, DistributionDatabase) at the Distributor.

Remarks

This method must be called from a Publisher to register the remote Distributor. If the Publisher and Distributor are on the same server, you should not call this method.

Before calling InstallDistributor(String, String), you must have called InstallDistributor(String, DistributionDatabase) at the Distributor.

The InstallDistributor method can only be called by a member of the sysadmin fixed server role.

The InstallDistributor method is equivalent to executing the sp_adddistributor (Transact-SQL) stored procedure at the Publisher to register a remote Distributor.

Applies to

InstallDistributor(String, SecureString)

Registers a remote Distributor, where the password is specified using a SecureString object.

public:
 void InstallDistributor(System::String ^ distributionServerName, System::Security::SecureString ^ password);
public void InstallDistributor (string distributionServerName, System.Security.SecureString password);
member this.InstallDistributor : string * System.Security.SecureString -> unit
Public Sub InstallDistributor (distributionServerName As String, password As SecureString)

Parameters

distributionServerName
String

A String value that specifies the name of the remote server to be used as the Distributor for the current Publisher server. The distribution server name cannot be the same as the current server.

password
SecureString

A SecureString value that specifies the password. This is the same value used when calling InstallDistributor(String, DistributionDatabase) at the Distributor.

Remarks

This method must be called from a Publisher to register the remote Distributor. If the Publisher and Distributor are on the same server, you should not call this method.

Before calling InstallDistributor(String, SecureString), you must have called InstallDistributor(SecureString, DistributionDatabase) at the Distributor.

The InstallDistributor(String, SecureString) method provides additional security for the password while it is stored in memory and should be used instead of InstallDistributor(String, String).

The InstallDistributor method can only be called by a member of the sysadmin fixed server role.

The InstallDistributor method is equivalent to executing the sp_adddistributor (Transact-SQL) stored procedure at the Publisher to register a remote Distributor.

Applies to

InstallDistributor(SecureString, DistributionDatabase)

Installs a Distributor on the currently connected instance of Microsoft SQL Server, where the password is specified using a SecureString object.

public:
 void InstallDistributor(System::Security::SecureString ^ password, Microsoft::SqlServer::Replication::DistributionDatabase ^ distributionDB);
public void InstallDistributor (System.Security.SecureString password, Microsoft.SqlServer.Replication.DistributionDatabase distributionDB);
member this.InstallDistributor : System.Security.SecureString * Microsoft.SqlServer.Replication.DistributionDatabase -> unit
Public Sub InstallDistributor (password As SecureString, distributionDB As DistributionDatabase)

Parameters

password
SecureString

Is a SecureString value representing the password of the distributor_admin login used to access the Distributor.

Security Note When possible, prompt users to enter security credentials at run time. If you must store credentials, use the http://go.microsoft.com/fwlink/?LinkId=34733 cryptographic services provided by the Windows .NET Framework.

distributionDB
DistributionDatabase

A DistributionDatabase object representing the distribution database used by the Distributor.

Remarks

You must specify a strong password for password when the Distributor has remote Publishers. If password is set to null, a random password is generated, and you must call ChangeDistributorPassword to reset the password when the first remote Publisher is registered at the Distributor.

This method overload must be called at the Distributor before calling InstallDistributor(String, String) from a remote server.

The InstallDistributor(SecureString, DistributionDatabase) method provides additional security for the password while it is stored in memory and should be used instead of InstallDistributor(String, DistributionDatabase).

The InstallDistributor method can only be called by a member of the sysadmin fixed server role.

The InstallDistributor method is equivalent to the sp_adddistributor (Transact-SQL) stored procedure.

Applies to

InstallDistributor(String, DistributionDatabase)

Installs a Distributor on the currently connected instance of Microsoft SQL Server.

public:
 void InstallDistributor(System::String ^ password, Microsoft::SqlServer::Replication::DistributionDatabase ^ distributionDB);
public void InstallDistributor (string password, Microsoft.SqlServer.Replication.DistributionDatabase distributionDB);
member this.InstallDistributor : string * Microsoft.SqlServer.Replication.DistributionDatabase -> unit
Public Sub InstallDistributor (password As String, distributionDB As DistributionDatabase)

Parameters

password
String

Is the password of the distributor_admin login used to access the Distributor.

Security Note When possible, prompt users to enter security credentials at run time. If you must store credentials, use the http://go.microsoft.com/fwlink/?LinkId=34733 cryptographic services provided by the Windows .NET Framework.

distributionDB
DistributionDatabase

A DistributionDatabase object representing the distribution database used by the Distributor.

Exceptions

When distribution is already installed on the server.

When distributionDB is null, or when password exceeds 128 bytes or contains null characters.

Examples

// 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();
}

Remarks

You must specify a strong password for password when the Distributor has remote Publishers. If password is set to null, a random password is generated, and you must call ChangeDistributorPassword to reset the password when the first remote Publisher is registered at the Distributor.

This method overload must be called at the Distributor before calling InstallDistributor from a remote server.

The InstallDistributor method can only be called by a member of the sysadmin fixed server role.

The InstallDistributor method is equivalent to the sp_adddistributor (Transact-SQL) stored procedure.

See also

Applies to