Subscription.SynchronizationAgentProcessSecurity 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取安全上下文,该上下文用于指定运行同步代理作业以同步订阅的 Microsoft Windows 帐户。
public:
property Microsoft::SqlServer::Replication::IProcessSecurityContext ^ SynchronizationAgentProcessSecurity { Microsoft::SqlServer::Replication::IProcessSecurityContext ^ get(); };
public Microsoft.SqlServer.Replication.IProcessSecurityContext SynchronizationAgentProcessSecurity { get; }
member this.SynchronizationAgentProcessSecurity : Microsoft.SqlServer.Replication.IProcessSecurityContext
Public ReadOnly Property SynchronizationAgentProcessSecurity As IProcessSecurityContext
属性值
一个表示 Windows 帐户的 IProcessSecurityContext 对象。
示例
// Define the Publisher, publication, and databases.
string publicationName = "AdvWorksProductTran";
string publisherName = publisherInstance;
string subscriberName = subscriberInstance;
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";
//Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
// Create the objects that we need.
TransPublication publication;
TransSubscription subscription;
try
{
// Connect to the Publisher.
conn.Connect();
// Ensure that the publication exists and that
// it supports push subscriptions.
publication = new TransPublication();
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
publication.ConnectionContext = conn;
if (publication.IsExistingObject)
{
if ((publication.Attributes & PublicationAttributes.AllowPush) == 0)
{
publication.Attributes |= PublicationAttributes.AllowPush;
}
// Define the push subscription.
subscription = new TransSubscription();
subscription.ConnectionContext = conn;
subscription.SubscriberName = subscriberName;
subscription.PublicationName = publicationName;
subscription.DatabaseName = publicationDbName;
subscription.SubscriptionDBName = subscriptionDbName;
// Specify the Windows login credentials for the Distribution Agent job.
subscription.SynchronizationAgentProcessSecurity.Login = winLogin;
subscription.SynchronizationAgentProcessSecurity.Password = winPassword;
// By default, subscriptions to transactional publications are synchronized
// continuously, but in this case we only want to synchronize on demand.
subscription.AgentSchedule.FrequencyType = ScheduleFrequencyType.OnDemand;
// Create the push subscription.
subscription.Create();
}
else
{
// Do something here if the publication does not exist.
throw new ApplicationException(String.Format(
"The publication '{0}' does not exist on {1}.",
publicationName, publisherName));
}
}
catch (Exception ex)
{
// Implement the appropriate error handling here.
throw new ApplicationException(String.Format(
"The subscription to {0} could not be created.", publicationName), ex);
}
finally
{
conn.Disconnect();
}
' Define the Publisher, publication, and databases.
Dim publicationName As String = "AdvWorksProductTran"
Dim publisherName As String = publisherInstance
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"
'Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
' Create the objects that we need.
Dim publication As TransPublication
Dim subscription As TransSubscription
Try
' Connect to the Publisher.
conn.Connect()
' Ensure that the publication exists and that
' it supports push subscriptions.
publication = New TransPublication()
publication.Name = publicationName
publication.DatabaseName = publicationDbName
publication.ConnectionContext = conn
If publication.IsExistingObject Then
If (publication.Attributes And PublicationAttributes.AllowPush) = 0 Then
publication.Attributes = publication.Attributes _
Or PublicationAttributes.AllowPush
End If
' Define the push subscription.
subscription = New TransSubscription()
subscription.ConnectionContext = conn
subscription.SubscriberName = subscriberName
subscription.PublicationName = publicationName
subscription.DatabaseName = publicationDbName
subscription.SubscriptionDBName = subscriptionDbName
' Specify the Windows login credentials for the Distribution Agent job.
subscription.SynchronizationAgentProcessSecurity.Login = winLogin
subscription.SynchronizationAgentProcessSecurity.Password = winPassword
' By default, subscriptions to transactional publications are synchronized
' continuously, but in this case we only want to synchronize on demand.
subscription.AgentSchedule.FrequencyType = ScheduleFrequencyType.OnDemand
' Create the push subscription.
subscription.Create()
Else
' Do something here if the publication does not exist.
Throw New ApplicationException(String.Format( _
"The publication '{0}' does not exist on {1}.", _
publicationName, publisherName))
End If
Catch ex As Exception
' Implement the appropriate error handling here.
Throw New ApplicationException(String.Format( _
"The subscription to {0} could not be created.", publicationName), ex)
Finally
conn.Disconnect()
End Try
注解
必须使用 属性返回的 IProcessSecurityContextSynchronizationAgentProcessSecurity 接口指定 Windows 帐户信息。 如果订阅是由发布服务器上的 sysadmin 固定服务器角色的成员创建的,则不需要这样做。
推送订阅的同步代理始终使用 使用 属性提供的 SynchronizationAgentProcessSecurity Windows 身份验证凭据在本地连接到分发服务器。 有关代理建立的连接以及这些连接所需的权限的信息,请参阅 复制代理安全模型。
使用远程分发服务器配置发布服务器时,为所有参数(包括 SynchronizationAgentProcessSecurity)提供的值将作为纯文本发送到分发服务器。 调用 Create 方法之前,应先对发布服务器与其远程分发服务器之间的连接进行加密。 有关详细信息,请参阅 加密与 SQL Server 的连接。
只有 SynchronizationAgentProcessSecurity 发布服务器上的 sysadmin 固定服务器角色的成员、发布数据库中 db_owner 固定数据库角色的成员或创建订阅的用户才能检索属性。
属性 SynchronizationAgentProcessSecurity 只能由发布服务器上的 sysadmin 固定服务器角色的成员或发布数据库中 db_owner 固定数据库角色的成员设置。
检索 SynchronizationAgentProcessSecurity 属性等效于执行 sp_helpsubscription 或 sp_helpmergesubscription。
在返回IProcessSecurityContext的接口上设置属性等效于执行sp_addsubscription sp_addmergesubscription、sp_changesubscription或sp_changemergesubscription。