ReplicationDatabase can be used to represent a publication or subscription database. ReplicationDatabase cannot be used to represent system databases, such as master, tempdb, msdb, and model. A distribution database is represented by DistributionDatabase.

This namespace, class, or member is supported only in version 2.0 of the .NET Framework.

Thread Safety

Any public static (Shared in Microsoft Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.

' Set the Distributor and publication database names.' Publisher and Distributor are on the same server instance.Dim publisherName AsString = publisherInstance
Dim distributorName AsString = subscriberInstance
Dim distributionDbName AsString = "distribution"Dim publicationDbName AsString = "AdventureWorks"' 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 AdventureWorks database.If publicationDb.LoadProperties() ThenIf publicationDb.EnabledMergePublishing Then
publicationDb.EnabledMergePublishing = FalseElseIf publicationDb.EnabledTransPublishing Then
publicationDb.EnabledTransPublishing = FalseEndIfElseThrowNew ApplicationException( _
String.Format("The {0} database does not exist.", publicationDbName))
EndIf' 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.ThrowNew ApplicationException(String.Format( _
"{0} is not a Publisher for {1}.", publisherName, distributorName))
EndIf' Drop the distribution database.If distributionDb.LoadProperties() Then
distributionDb.Remove()
Else' Do something here if the distribition DB does not exist.ThrowNew ApplicationException(String.Format( _
"The distribution database '{0}' does not exist on {1}.", _
distributionDbName, distributorName))
EndIf' 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.ThrowNew ApplicationException(String.Format( _
"The Distributor '{0}' does not exist.", distributorName))
EndIfElseThrowNew ApplicationException("You must first delete all subscriptions.")
EndIfCatch ex As Exception
' Implement appropriate error handling here.ThrowNew ApplicationException("The Publisher and Distributor could not be uninstalled", ex)
Finally
publisherConn.Disconnect()
distributorConn.Disconnect()
EndTry