发布服务器属性 分发服务器修改,如何查看和修改发布服务器和分发服务器属性(RMO 编程)...

示例

此示例显示如何更改分发和分发数据库属性。

51d5cfa34efb6ae4c3e1795455232d4f.png安全说明

若要避免将凭据存储在代码中,应当在运行时提供新分发服务器密码。

// Set the Distributor and distribution database names.

string distributionDbName = "distribution";

string distributorName = publisherInstance;

ReplicationServer distributor;

DistributionDatabase distributionDb;

// Create a connection to the Distributor using Windows Authentication.

ServerConnection conn = new ServerConnection(distributorName);

try

{

// Open the connection.

conn.Connect();

distributor = new ReplicationServer(conn);

// Load Distributor properties, if it is installed.

if (distributor.LoadProperties())

{

// Password supplied at runtime.

distributor.ChangeDistributorPassword(password);

distributor.AgentCheckupInterval = 5;

// Save changes to the Distributor properties.

distributor.CommitPropertyChanges();

}

else

{

throw new ApplicationException(

String.Format("{0} is not a Distributor.", publisherInstance));

}

// Create an object for the distribution database

// using the open Distributor connection.

distributionDb = new DistributionDatabase(distributionDbName, conn);

// Change distribution database properties.

if (distributionDb.LoadProperties())

{

// Change maximum retention period to 48 hours and history retention

// period to 24 hours.

distributionDb.MaxDistributionRetention = 48;

distributionDb.HistoryRetention = 24;

// Save changes to the distribution database properties.

distributionDb.CommitPropertyChanges();

}

else

{

// Do something here if the distribution database does not exist.

}

}

catch (Exception ex)

{

// Implement the appropriate error handling here.

throw new ApplicationException("An error occured when changing Distributor " +

" or distribution database properties.", ex);

}

finally

{

conn.Disconnect();

}

' Set the Distributor and distribution database names.

Dim distributionDbName As String = "distribution"

Dim distributorName As String = publisherInstance

Dim distributor As ReplicationServer

Dim distributionDb As DistributionDatabase

' Create a connection to the Distributor using Windows Authentication.

Dim conn As ServerConnection = New ServerConnection(distributorName)

Try

' Open the connection.

conn.Connect()

distributor = New ReplicationServer(conn)

' Load Distributor properties, if it is installed.

If distributor.LoadProperties() Then

' Password supplied at runtime.

distributor.ChangeDistributorPassword(password)

distributor.AgentCheckupInterval = 5

' Save changes to the Distributor properties.

distributor.CommitPropertyChanges()

Else

Throw New ApplicationException( _

String.Format("{0} is not a Distributor.", publisherInstance))

End If

' Create an object for the distribution database

' using the open Distributor connection.

distributionDb = New DistributionDatabase(distributionDbName, conn)

' Change distribution database properties.

If distributionDb.LoadProperties() Then

' Change maximum retention period to 48 hours and history retention

' period to 24 hours.

distributionDb.MaxDistributionRetention = 48

distributionDb.HistoryRetention = 24

' Save changes to the distribution database properties.

distributionDb.CommitPropertyChanges()

Else

' Do something here if the distribution database does not exist.

End If

Catch ex As Exception

' Implement the appropriate error handling here.

Throw New ApplicationException("An error occured when changing Distributor " + _

" or distribution database properties.", ex)

Finally

conn.Disconnect()

End Try

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值