MergeSynchronizationAgent 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供复制合并代理的功能。
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 实例用于同步合并订阅。 由于拉取订阅是使用值falseCreateSyncAgentByDefault创建的,因此必须提供其他属性。
// 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 |
获取或设置在连接到分发服务器时使用的客户端网络库。 |
| DistributorPassword |
设置使用SQL Server身份验证连接到分发服务器时使用的密码。 |
| DistributorSecurityMode |
获取或设置连接到分发服务器时使用的安全模式。 |
| DownloadGenerationsPerBatch |
获取或设置将更改从发布服务器下载到订阅服务器时要在单个批次中处理的生成数。 生成的定义是每个项目中属于一个逻辑组的更改。 |
| DynamicSnapshotLocation |
获取或设置此订阅服务器的分区快照的位置。 |
| ExchangeType |
获取或设置在同步期间交换数据的方式。 |
| FileTransferType |
获取或设置初始快照文件传输到订阅服务器的方式。 |
| HostName |
获取或设置合并代理在计算使用HOST_NAME函数的参数化筛选器时使用的值。 |
| InputMessageFile |
获取或设置输入消息文件。 |
| InternetLogin |
获取或设置在通过使用 Internet 身份验证连接到发布服务器时用于 Web 同步的登录名。 |
| InternetPassword |
为在通过使用 Internet 身份验证连接到发布服务器时用于 Web 同步的 InternetLogin 属性设置密码。 |
| InternetProxyLogin |
获取或设置在通过使用 Internet 代理服务器连接到 Web 服务器时用于 Web 同步的登录名。 |
| InternetProxyPassword |
设置在通过使用 Internet 代理服务器连接到 Web 服务器时用于 Web 同步的登录密码。 |
| InternetProxyServer |
获取或设置在连接到 Web 服务器时用于 Web 同步的 Internet 代理服务器的名称。 |
| InternetSecurityMode |
获取或设置在 Web 同步过程中连接到 Web 服务器时使用的 HTTP 身份验证方法。 |
| InternetTimeout |
获取或设置连接到 Web 服务器时的 HTTP 超时。 |
| InternetUrl |
获取或设置为 Web 同步配置的 Web 服务的 URL。 |
| LastUpdatedTime |
获取复制代理上次同步订阅的时间的时间戳。 |
| LoginTimeout |
获取或设置等待建立连接的最大秒数。 |
| MetadataRetentionCleanup |
获取或设置是否清除元数据。 |
| Output |
获取或设置代理输出文件。 |
| OutputMessageFile |
获取或设置输入消息文件。 |
| OutputVerboseLevel |
获取或设置写入代理输出文件的信息的详细信息级别。 |
| ProfileName |
获取或设置代理使用的配置文件的名称。 |
| Publication |
获取或设置发布的名称。 |
| Publisher |
获取或设置作为订阅的发布服务器的 Microsoft SQL Server 实例的名称。 |
| PublisherAddress |
获取或设置在指定 PublisherNetwork 属性时用于连接到发布服务器的网络地址。 |
| PublisherChanges |
获取在上次同步期间在订阅服务器上应用的发布服务器更改的总数。 |
| PublisherConflicts |
获取在上次同步期间在发布服务器上发生的冲突的总数。 |
| PublisherDatabase |
获取或设置发布数据库的名称。 |
| PublisherEncryptedPassword |
获取或设置发布服务器加密密码。 |
| PublisherFailoverPartner |
获取或设置与发布数据库一起参与数据库镜像会话的SQL Server的故障转移伙伴实例。 |
| PublisherLogin |
获取或设置使用SQL Server身份验证连接到发布服务器时使用的登录名。 |
| PublisherNetwork |
获取或设置在连接到发布服务器时使用的客户端网络库。 |
| PublisherPassword |
使用SQL Server身份验证设置连接到发布服务器时使用的密码。 |
| PublisherSecurityMode |
获取或设置在连接到发布服务器时使用的安全模式。 |
| QueryTimeout |
获取或设置允许内部查询完成的秒数。 |
| SecureDistributorEncryptedPassword |
获取或设置安全分发服务器加密密码。 |
| SecurePublisherEncryptedPassword |
获取或设置安全发布服务器加密密码。 |
| SecureSubscriberEncryptedPassword |
获取或设置安全订阅服务器加密密码。 |
| Subscriber |
获取或设置作为订阅服务器的 Microsoft SQL Server 实例的名称。 |
| SubscriberChanges |
获取在上次同步期间在发布服务器上应用的订阅服务器更改的总数。 |
| SubscriberConflicts |
获取在上次同步期间在发布服务器上发生的冲突的总数。 |
| SubscriberDatabase |
获取或设置订阅数据库的名称。 |
| SubscriberDatabasePath |
获取或设置订阅服务器数据库路径。 |
| SubscriberDataSourceType |
获取或设置用作订阅服务器的数据源的类型。 |
| SubscriberEncryptedPassword |
获取或设置订阅服务器加密密码。 |
| SubscriberLogin |
获取或设置使用SQL Server身份验证连接到订阅服务器时使用的登录名。 |
| SubscriberPassword |
使用SQL Server身份验证设置连接到订阅服务器时使用的密码。 |
| SubscriberSecurityMode |
获取或设置在连接到订阅服务器时使用的安全模式。 |
| SubscriptionType |
获取或设置订阅是推送订阅还是请求订阅。 |
| SyncToAlternate |
获取或设置是否与备用同步伙伴保持同步。 |
| UploadGenerationsPerBatch |
获取或设置将订阅服务器上的更改上载到发布服务器时要在单个批次处理的生成数。 生成的定义是每个项目中属于一个逻辑组的更改。 |
| UseInteractiveResolver |
获取或设置调解期间是否使用交互式冲突解决程序。 |
| UseWebSynchronization |
获取或设置是否使用 Web 同步。 |
| Validate |
获取或设置是否在同步结束时对订阅服务器数据执行数据验证。 |
| WorkingDirectory |
获取或设置在使用 FTP 时从其访问快照文件的工作目录。 |
方法
| Abort() |
中止同步。 |
| ClearAllTraceFlags() |
清除同步代理使用的所有跟踪标志。 |
| ClearTraceFlag(Int32) |
清除跟踪标志。 |
| Dispose() |
释放由 MergeSynchronizationAgent 使用的托管资源。 |
| Dispose(Boolean) |
释放类使用 MergeSynchronizationAgent 的非托管资源,并选择性地释放托管资源。 |
| EnableTraceFlag(Int32) |
启用标志跟踪。 |
| Finalize() |
确定代理。 |
| IsSnapshotRequired() |
连接到发布服务器或分发服务器和订阅服务器以便确定在下一个代理同步过程中是否将应用新快照。 |
| ProcessMessagesAtPublisher() |
处理发布服务器上的消息。 |
| ProcessMessagesAtSubscriber() |
处理订阅服务器上的消息。 |
| Synchronize() |
启动合并代理以便同步订阅。 |
事件
| ComStatus |
在合并代理返回同步 Com 状态信息时发生。 |
| Status |
在合并代理返回同步状态信息时发生。 |
适用于
线程安全性
此类型的所有公共静态(Visual Basic 中共享的)成员都是线程安全的。 但不保证所有实例成员都是线程安全的。