RMO Example

A question that was asked during the SMO presentation in Adelaide last week was how to use the Replication Management Object (RMO) in SQL Server 2005 to programmatically control replication. The VB.Net snippet below configures the replication publisher and distribution.


Dim distributionDBName As String = “distribution”
Dim publisherDBName As String = “northwind”
Dim distributionDB As DistributionDatabase
Dim distributor As ReplicationServer
Dim publisher As DistributionPublisher
Dim SMOServer As ServerConnection = New ServerConnection()

‘ Define the distribution database
distributionDB = New DistributionDatabase(distributionDBName, SMOServer)
distributionDB.MaxDistributionRetention = 30
distributionDB.HistoryRetention = 60

‘ Install the distributor and create the distribution db
distributor = New ReplicationServer(SMOServer)
distributor.InstallDistributor((CType(Nothing, String)), distributionDB)

‘ Install the Publisher
publisher = New DistributionPublisher(publisherDBName, SMOServer)
publisher.DistributionDatabase = distributionDB.Name
publisher.WorkingDirectory = “\\” + publisherDBName + “\repldata”
publisher.PublisherSecurity.WindowsAuthentication = True