Compartir a través de


ReplicationDatabase Constructores

Definición

Inicializa una nueva instancia de la clase ReplicationDatabase.

Sobrecargas

ReplicationDatabase()

Inicializa una nueva instancia de la clase ReplicationDatabase.

ReplicationDatabase(String, ServerConnection)

Inicializa una instancia nueva de la clase ReplicationDatabase con el nombre de base de datos especificado, que proporciona una conexión al servidor en el que existe la base de datos.

ReplicationDatabase()

Inicializa una nueva instancia de la clase ReplicationDatabase.

public:
 ReplicationDatabase();
public ReplicationDatabase ();
Public Sub New ()

Comentarios

El constructor predeterminado inicializa los campos con sus valores predeterminados.

Se aplica a

ReplicationDatabase(String, ServerConnection)

Inicializa una instancia nueva de la clase ReplicationDatabase con el nombre de base de datos especificado, que proporciona una conexión al servidor en el que existe la base de datos.

public:
 ReplicationDatabase(System::String ^ name, Microsoft::SqlServer::Management::Common::ServerConnection ^ connectionContext);
public ReplicationDatabase (string name, Microsoft.SqlServer.Management.Common.ServerConnection connectionContext);
new Microsoft.SqlServer.Replication.ReplicationDatabase : string * Microsoft.SqlServer.Management.Common.ServerConnection -> Microsoft.SqlServer.Replication.ReplicationDatabase
Public Sub New (name As String, connectionContext As ServerConnection)

Parámetros

name
String

Valor String que especifica el nombre de la base de datos de replicación.

connectionContext
ServerConnection

Valor ServerConnection de objeto que especifica el contexto de conexión que se usa para establecer una conexión a la instancia de SQL Server.

Ejemplos

// 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

Consulte también

Se aplica a