MergeSynchronizationAgent 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供 Replication 合并代理 的功能。
public ref class MergeSynchronizationAgent : MarshalByRefObject, IDisposable, Microsoft::SqlServer::Replication::IMergeSynchronizationAgent
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComSourceInterfaces(typeof(Microsoft.SqlServer.Replication.IComStatusEvent))]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.Guid("ee5ee47e-6d29-448f-b2d2-f8e632db336a")]
public class MergeSynchronizationAgent : MarshalByRefObject, IDisposable, Microsoft.SqlServer.Replication.IMergeSynchronizationAgent
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComSourceInterfaces(typeof(Microsoft.SqlServer.Replication.IComStatusEvent))>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Runtime.InteropServices.Guid("ee5ee47e-6d29-448f-b2d2-f8e632db336a")>]
type MergeSynchronizationAgent = class
inherit MarshalByRefObject
interface IDisposable
interface IMergeSynchronizationAgent
Public Class MergeSynchronizationAgent
Inherits MarshalByRefObject
Implements IDisposable, IMergeSynchronizationAgent
- 继承
-
MergeSynchronizationAgent
- 属性
- 实现
示例
在以下示例中,Synchronize该方法在从该属性访问SynchronizationAgent的类实例MergeSynchronizationAgent上调用以同步推送订阅。
// Define the server, publication, and database names.
string subscriberName = subscriberInstance;
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";
// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
MergeSubscription subscription;
try
{
// Connect to the Publisher
conn.Connect();
// Define the subscription.
subscription = new MergeSubscription();
subscription.ConnectionContext = conn;
subscription.DatabaseName = publicationDbName;
subscription.PublicationName = publicationName;
subscription.SubscriptionDBName = subscriptionDbName;
subscription.SubscriberName = subscriberName;
// If the push subscription exists, start the synchronization.
if (subscription.LoadProperties())
{
// Check that we have enough metadata to start the agent.
if (subscription.SubscriberSecurity != null)
{
// Synchronously start the Merge Agent for the subscription.
subscription.SynchronizationAgent.Synchronize();
}
else
{
throw new ApplicationException("There is insufficent metadata to " +
"synchronize the subscription. Recreate the subscription with " +
"the agent job or supply the required agent properties at run time.");
}
}
else
{
// Do something here if the push subscription does not exist.
throw new ApplicationException(String.Format(
"The subscription to '{0}' does not exist on {1}",
publicationName, subscriberName));
}
}
catch (Exception ex)
{
// Implement appropriate error handling here.
throw new ApplicationException("The subscription could not be synchronized.", ex);
}
finally
{
conn.Disconnect();
}
' Define the server, publication, and database names.
Dim subscriberName As String = subscriberInstance
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"
' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
Dim subscription As MergeSubscription
Try
' Connect to the Publisher
conn.Connect()
' Define the subscription.
subscription = New MergeSubscription()
subscription.ConnectionContext = conn
subscription.DatabaseName = publicationDbName
subscription.PublicationName = publicationName
subscription.SubscriptionDBName = subscriptionDbName
subscription.SubscriberName = subscriberName
' If the push subscription exists, start the synchronization.
If subscription.LoadProperties() Then
' Check that we have enough metadata to start the agent.
If Not subscription.SubscriberSecurity Is Nothing Then
' Synchronously start the Merge Agent for the subscription.
' Log agent messages to an output file.
subscription.SynchronizationAgent.Output = "mergeagent.log"
subscription.SynchronizationAgent.OutputVerboseLevel = 2
subscription.SynchronizationAgent.Synchronize()
Else
Throw New ApplicationException("There is insufficent metadata to " + _
"synchronize the subscription. Recreate the subscription with " + _
"the agent job or supply the required agent properties at run time.")
End If
Else
' Do something here if the push subscription does not exist.
Throw New ApplicationException(String.Format( _
"The subscription to '{0}' does not exist on {1}", _
publicationName, subscriberName))
End If
Catch ex As Exception
' Implement appropriate error handling here.
Throw New ApplicationException("The subscription could not be synchronized.", ex)
Finally
conn.Disconnect()
End Try
在以下示例中,该类的一个实例 MergeSynchronizationAgent 用于同步合并订阅。 由于拉取订阅是通过使用 false 值创建的 CreateSyncAgentByDefault,因此必须提供额外的属性。
// Define the server, publication, and database names.
string subscriberName = subscriberInstance;
string publisherName = publisherInstance;
string distributorName = distributorInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";
string hostname = @"adventure-works\garrett1";
string webSyncUrl = "https://" + publisherInstance + "/SalesOrders/replisapi.dll";
// Create a connection to the Subscriber.
ServerConnection conn = new ServerConnection(subscriberName);
MergePullSubscription subscription;
MergeSynchronizationAgent agent;
try
{
// Connect to the Subscriber.
conn.Connect();
// Define the pull subscription.
subscription = new MergePullSubscription();
subscription.ConnectionContext = conn;
subscription.DatabaseName = subscriptionDbName;
subscription.PublisherName = publisherName;
subscription.PublicationDBName = publicationDbName;
subscription.PublicationName = publicationName;
// If the pull subscription exists, then start the synchronization.
if (subscription.LoadProperties())
{
// Get the agent for the subscription.
agent = subscription.SynchronizationAgent;
// Check that we have enough metadata to start the agent.
if (agent.PublisherSecurityMode == null)
{
// Set the required properties that could not be returned
// from the MSsubscription_properties table.
agent.PublisherSecurityMode = SecurityMode.Integrated;
agent.DistributorSecurityMode = SecurityMode.Integrated;
agent.Distributor = publisherName;
agent.HostName = hostname;
// Set optional Web synchronization properties.
agent.UseWebSynchronization = true;
agent.InternetUrl = webSyncUrl;
agent.InternetSecurityMode = SecurityMode.Standard;
agent.InternetLogin = winLogin;
agent.InternetPassword = winPassword;
}
// Enable agent output to the console.
agent.OutputVerboseLevel = 1;
agent.Output = "";
// Synchronously start the Merge Agent for the subscription.
agent.Synchronize();
}
else
{
// Do something here if the pull subscription does not exist.
throw new ApplicationException(String.Format(
"A subscription to '{0}' does not exist on {1}",
publicationName, subscriberName));
}
}
catch (Exception ex)
{
// Implement appropriate error handling here.
throw new ApplicationException("The subscription could not be " +
"synchronized. Verify that the subscription has " +
"been defined correctly.", ex);
}
finally
{
conn.Disconnect();
}
' Define the server, publication, and database names.
Dim subscriberName As String = subscriberInstance
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"
Dim hostname As String = "adventure-works\garrett1"
Dim webSyncUrl As String = "https://" + publisherInstance + "/SalesOrders/replisapi.dll"
' Create a connection to the Subscriber.
Dim conn As ServerConnection = New ServerConnection(subscriberName)
Dim subscription As MergePullSubscription
Dim agent As MergeSynchronizationAgent
Try
' Connect to the Subscriber.
conn.Connect()
' Define the pull subscription.
subscription = New MergePullSubscription()
subscription.ConnectionContext = conn
subscription.DatabaseName = subscriptionDbName
subscription.PublisherName = publisherName
subscription.PublicationDBName = publicationDbName
subscription.PublicationName = publicationName
' If the pull subscription exists, then start the synchronization.
If subscription.LoadProperties() Then
' Get the agent for the subscription.
agent = subscription.SynchronizationAgent
' Check that we have enough metadata to start the agent.
If agent.PublisherSecurityMode = Nothing Then
' Set the required properties that could not be returned
' from the MSsubscription_properties table.
agent.PublisherSecurityMode = SecurityMode.Integrated
agent.Distributor = publisherInstance
agent.DistributorSecurityMode = SecurityMode.Integrated
agent.HostName = hostname
' Set optional Web synchronization properties.
agent.UseWebSynchronization = True
agent.InternetUrl = webSyncUrl
agent.InternetSecurityMode = SecurityMode.Standard
agent.InternetLogin = winLogin
agent.InternetPassword = winPassword
End If
' Enable agent logging to the console.
agent.OutputVerboseLevel = 1
agent.Output = ""
' Synchronously start the Merge Agent for the subscription.
agent.Synchronize()
Else
' Do something here if the pull subscription does not exist.
Throw New ApplicationException(String.Format( _
"A subscription to '{0}' does not exist on {1}", _
publicationName, subscriberName))
End If
Catch ex As Exception
' Implement appropriate error handling here.
Throw New ApplicationException("The subscription could not be " + _
"synchronized. Verify that the subscription has " + _
"been defined correctly.", ex)
Finally
conn.Disconnect()
End Try
注解
该 MergeSynchronizationAgent 类支持执行以下复制任务的能力:
同步订阅。
在同步过程中,请指定仅运行上传阶段、下载阶段,还是两个阶段。
验证订阅是否包含预期数据。
指定一个不同的快照文件夹,从中应用订阅的初始快照。
构造函数
| 名称 | 说明 |
|---|---|
| MergeSynchronizationAgent() |
创建 MergeSynchronizationAgent 类的实例。 |
属性
| 名称 | 说明 |
|---|---|
| AlternateSynchronizationPartnerCollection |
订阅时可以获得替代同步合作伙伴。 |
| AltSnapshotFolder |
获取或设置订阅的备用快照文件夹。 |
| ComErrorCollection |
获得由复制代理生成的一组错误。 |
| Distributor |
获取或设置作为订阅分发器的 Microsoft SQL Server 实例的名称。 |
| DistributorAddress |
在指定属性时 DistributorNetwork ,获取或设置用于连接分发器的网络地址。 |
| DistributorEncryptedPassword |
获取或设置分发商加密密码。 |
| DistributorLogin |
获取或设置使用SQL Server认证连接分发器时使用的登录名。 |
| DistributorNetwork |
获取或设置连接分发商时使用的客户端 Net-Library。 |
| DistributorPassword |
设置使用 SQL Server 认证连接到分发器时使用的密码。 |
| DistributorSecurityMode |
获取或设置连接分发器时使用的安全模式。 |
| DownloadGenerationsPerBatch |
在从 Publisher 下载变更到订阅者时,获取或设置单批处理的代数。 生成的定义是每个项目中属于一个逻辑组的更改。 |
| DynamicSnapshotLocation |
获取或设置该订阅者的分区快照位置。 |
| ExchangeType |
获取或设置同步过程中数据交换的方式。 |
| FileTransferType |
获取或设置初始快照文件如何传输给订阅者。 |
| HostName |
当该函数计算参数化滤波器时,合并代理获得或设置其使用的值,该滤波器使用HOST_NAME函数。 |
| InputMessageFile |
获取或设置输入消息文件。 |
| InternetLogin |
通过互联网认证连接 Publisher 时,获取或设置登录名,用于网页同步。 |
| InternetPassword |
设置InternetLogin用于通过互联网认证连接 Publisher 时所使用的属性密码。 |
| InternetProxyLogin |
通过互联网代理服务器连接网页服务器时,获取或设置登录名,用于网页同步。 |
| InternetProxyPassword |
设置登录密码,连接网页同步时使用互联网代理服务器。 |
| InternetProxyServer |
获取或设置连接Web服务器时用于网页同步的互联网代理服务器名称。 |
| InternetSecurityMode |
获取或设置连接Web服务器时使用的HTTP认证方法。 |
| InternetTimeout |
连接Web服务器时,获取或设置HTTP超时。 |
| InternetUrl |
获取或设置配置为网页同步的 Web 服务的 URL。 |
| LastUpdatedTime |
获取复制代理上次同步订阅的时间戳。 |
| LoginTimeout |
获取或设置等待连接建立的最大秒数。 |
| MetadataRetentionCleanup |
获取或设置是否清理元数据。 |
| Output |
获取或设置代理输出文件。 |
| OutputMessageFile |
获取或设置输入消息文件。 |
| OutputVerboseLevel |
获取或设定写入代理输出文件的信息细节级别。 |
| ProfileName |
获取或设置代理使用的配置文件名称。 |
| Publication |
获取或确定出版物名称。 |
| Publisher |
获取或设置订阅Publisher的实例名称Microsoft SQL Server。 |
| PublisherAddress |
在指定属性时,获取或设置用于连接PublisherPublisherNetwork的网络地址。 |
| PublisherChanges |
获取上次同步期间,订阅者所应用的 Publisher 变更总数。 |
| PublisherConflicts |
获取上次同步期间 Publisher 发生的冲突总数。 |
| PublisherDatabase |
获取或设定发表数据库的名称。 |
| PublisherEncryptedPassword |
获取或设置发布者加密密码。 |
| PublisherFailoverPartner |
获取或设置参与与发布数据库镜像会话的 SQL Server 合作伙伴实例。 |
| PublisherLogin |
通过使用 SQL Server 认证,获取或设置连接 Publisher 时使用的登录名。 |
| PublisherNetwork |
获取或设置连接Publisher时使用的客户端 Net-Library。 |
| PublisherPassword |
通过使用 SQL Server 认证设置连接 Publisher 时使用的密码。 |
| PublisherSecurityMode |
获取或设置连接 Publisher 时使用的安全模式。 |
| QueryTimeout |
获取或设置允许内部查询完成的秒数。 |
| SecureDistributorEncryptedPassword |
获取或设置安全分发者加密密码。 |
| SecurePublisherEncryptedPassword |
获取或设置安全的发布者加密密码。 |
| SecureSubscriberEncryptedPassword |
获取或设置安全用户加密密码。 |
| Subscriber |
获取或设置作为订阅者的 Microsoft SQL Server 实例的名称。 |
| SubscriberChanges |
获取上次同步时在 Publisher 应用的订阅者变更总数。 |
| SubscriberConflicts |
获取上次同步期间 Publisher 发生的冲突总数。 |
| SubscriberDatabase |
获取或设置订阅数据库的名称。 |
| SubscriberDatabasePath |
获取或设置用户数据库路径。 |
| SubscriberDataSourceType |
获取或设置作为订阅者使用的数据源类型。 |
| SubscriberEncryptedPassword |
获取或设置用户加密密码。 |
| SubscriberLogin |
通过使用 SQL Server 认证连接订阅者时,获取或设置登录名。 |
| SubscriberPassword |
通过使用 SQL Server 认证设置连接订阅者的密码。 |
| SubscriberSecurityMode |
获取或设置连接用户时使用的安全模式。 |
| SubscriptionType |
获取或设置订阅是推订阅还是拉订阅。 |
| SyncToAlternate |
获取或设置同步是否与另一个同步伙伴同步。 |
| UploadGenerationsPerBatch |
在从订阅者上传变更到Publisher时,可以获得或设置单批处理的生成数量。 生成的定义是每个项目中属于一个逻辑组的更改。 |
| UseInteractiveResolver |
在对账过程中是否使用交互式解析器,获取或设置。 |
| UseWebSynchronization |
获取或设置是否使用网页同步。 |
| Validate |
在同步结束时,获取或设置是否对用户数据进行数据验证。 |
| WorkingDirectory |
获取或设置在使用 FTP 时访问快照文件的工作目录。 |
方法
| 名称 | 说明 |
|---|---|
| Abort() |
中止同步。 |
| ClearAllTraceFlags() |
清除同步代理使用的所有跟踪标志。 |
| ClearTraceFlag(Int32) |
清除了追踪标记。 |
| Dispose() |
释放被 MergeSynchronizationAgent使用的未管理资源。 |
| Dispose(Boolean) |
释放类使用的 MergeSynchronizationAgent 非管理资源,并可选择释放管理资源。 |
| EnableTraceFlag(Int32) |
启用了国旗追踪功能。 |
| Finalize() |
最终确定代理。 |
| IsSnapshotRequired() |
连接Publisher或Distributor与Subtributer,以确定下一次代理同步时是否应用新的快照。 |
| ProcessMessagesAtPublisher() |
在发布者处理消息。 |
| ProcessMessagesAtSubscriber() |
在用户处处理消息。 |
| Synchronize() |
启动 合并代理 以同步订阅。 |
活动
| 名称 | 说明 |
|---|---|
| ComStatus |
当合并代理返回同步Com状态信息时,发生在该事件中。 |
| Status |
当合并代理返回同步状态信息时,会发生这种情况。 |
适用于
线程安全性
任何此类公共静态(共享于Visual Basic)成员均为线程安全。 不能保证任何实例成员是线程安全的。