Export (0) Print
Expand All

ReplicationDatabase Constructor

 

Applies To: SQL Server 2016 Preview

Initializes a new instance of the ReplicationDatabase class.

Namespace:   Microsoft.SqlServer.Replication
Assembly:  Microsoft.SqlServer.Rmo (in Microsoft.SqlServer.Rmo.dll)

NameDescription
System_CAPS_pubmethodReplicationDatabase()

Initializes a new instance of the ReplicationDatabase class.

System_CAPS_pubmethodReplicationDatabase(String, ServerConnection)

Initializes a new instance of the ReplicationDatabase class with the specified database name, providing a connection to the server on which the database exists.

Return to top

ReplicationDatabase Constructor ()

Initializes a new instance of the ReplicationDatabase class.

public ReplicationDatabase()

The default constructor initializes any fields to their default values.

Return to top

ReplicationDatabase Constructor (String, ServerConnection)

Initializes a new instance of the ReplicationDatabase class with the specified database name, providing a connection to the server on which the database exists.

public ReplicationDatabase(
	string name,
	ServerConnection connectionContext
)

Parameters

name
Type: System.String

A String value that specifies the name of the replication database.

connectionContext
Type: Microsoft.SqlServer.Management.Common.ServerConnection

A ServerConnection object value that specifies the connection context that is used to establish a connection to the instance of SQL Server.

Legacy Code Example

			// 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();
			}
Return to top
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft