共用方式為


MergeSynchronizationAgent 類別

Provides the functionality of the Replication Merge Agent.

繼承階層

System. . :: . .Object
  System. . :: . .MarshalByRefObject
    Microsoft.SqlServer.Replication..::..MergeSynchronizationAgent

命名空間:  Microsoft.SqlServer.Replication
組件:  Microsoft.SqlServer.Replication (在 Microsoft.SqlServer.Replication.dll 中)

語法

'宣告
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
<GuidAttribute("ee5ee47e-6d29-448f-b2d2-f8e632db336a")> _
<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public Class MergeSynchronizationAgent _
    Inherits MarshalByRefObject _
    Implements IDisposable, IMergeSynchronizationAgent
'用途
Dim instance As MergeSynchronizationAgent
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
[GuidAttribute("ee5ee47e-6d29-448f-b2d2-f8e632db336a")]
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public class MergeSynchronizationAgent : MarshalByRefObject, 
    IDisposable, IMergeSynchronizationAgent
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
[ComVisibleAttribute(true)]
[GuidAttribute(L"ee5ee47e-6d29-448f-b2d2-f8e632db336a")]
[PermissionSetAttribute(SecurityAction::Demand, Name = L"FullTrust")]
public ref class MergeSynchronizationAgent : public MarshalByRefObject, 
    IDisposable, IMergeSynchronizationAgent
[<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)>]
[<ComVisibleAttribute(true)>]
[<GuidAttribute("ee5ee47e-6d29-448f-b2d2-f8e632db336a")>]
[<PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")>]
type MergeSynchronizationAgent =  
    class
        inherit MarshalByRefObject
        interface IDisposable
        interface IMergeSynchronizationAgent
    end
public class MergeSynchronizationAgent extends MarshalByRefObject implements IDisposable, IMergeSynchronizationAgent

MergeSynchronizationAgent 型別公開下列成員。

建構函式

  名稱 說明
公用方法 MergeSynchronizationAgent Creates an instance of the MergeSynchronizationAgent class.

上層

屬性

  名稱 說明
公用屬性 AlternateSynchronizationPartnerCollection Gets the alternate synchronization partners for a subscription.
公用屬性 AltSnapshotFolder Gets or sets the alternate snapshot folder for the subscription.
公用屬性 ComErrorCollection Gets a collection of errors generated by the replication agent.
公用屬性 Distributor Gets or sets the name of the instance of Microsoft SQL Server that is acting as the Distributor for the subscription.
公用屬性 DistributorAddress Gets or sets the network address that is used to connect to the Distributor when the DistributorNetwork property is specified.
公用屬性 DistributorEncryptedPassword 基礎結構。
公用屬性 DistributorLogin Gets or sets the login name that is used when connecting to the Distributor using SQL Server Authentication.
公用屬性 DistributorNetwork Gets or sets the client Net-Library that is used when connecting to the Distributor.
公用屬性 DistributorPassword Sets the password that is used when connecting to the Distributor using SQL Server Authentication.
公用屬性 DistributorSecurityMode Gets or sets the security mode used when connecting to the Distributor.
公用屬性 DownloadGenerationsPerBatch Gets or sets the number of generations to be processed in a single batch while downloading changes from the Publisher to the Subscriber. A generation is defined as a logical group of changes per article.
公用屬性 DynamicSnapshotLocation Gets or sets the location of the partitioned snapshot for this Subscriber.
公用屬性 ExchangeType Gets or sets how data is exchanged during synchronization.
公用屬性 FileTransferType Gets or sets how the initial snapshot files are transferred to the Subscriber.
公用屬性 HostName Gets or sets the value used by the Merge Agent when it evaluates a parameterized filter that uses the HOST_NAME function.
公用屬性 InputMessageFile 基礎結構。
公用屬性 InternetLogin Gets or sets the login name that is used with Web synchronization when connecting to the Publisher by using Internet authentication.
公用屬性 InternetPassword Sets the password for the InternetLogin property that is used with Web synchronization when connecting to the Publisher by using Internet authentication.
公用屬性 InternetProxyLogin Gets or sets the login name that is used with Web synchronization when connecting to the Web server by using an Internet proxy server.
公用屬性 InternetProxyPassword Sets the password for the login that is used with Web synchronization when connecting to the Web server by using an Internet proxy server.
公用屬性 InternetProxyServer Gets or sets the name of the Internet proxy server that is used with Web synchronization when connecting to the Web server.
公用屬性 InternetSecurityMode Gets or sets the HTTP authentication method that is used when connecting to the Web server during Web synchronization.
公用屬性 InternetTimeout Gets or sets the HTTP time-out when connecting to the Web server.
公用屬性 InternetUrl Gets or sets the URL of the Web service that is configured for Web synchronization.
公用屬性 LastUpdatedTime Gets the timestamp of the last time that replication agent synchronized the subscription.
公用屬性 LoginTimeout Gets or sets the maximum number of seconds to wait for connections to be established.
公用屬性 MetadataRetentionCleanup Get or sets whether to clean up metadata.
公用屬性 Output Gets or sets the agent output file.
公用屬性 OutputMessageFile 基礎結構。
公用屬性 OutputVerboseLevel Gets or sets the level of detail of information that is written to the agent output file.
公用屬性 ProfileName Gets or sets the name of the profile that is used by the agent.
公用屬性 Publication Gets or sets the name of the publication.
公用屬性 Publisher Gets or sets the name of the instance of Microsoft SQL Server that is the Publisher for the subscription.
公用屬性 PublisherAddress Gets or sets the network address that is used to connect to the Publisher when the PublisherNetwork property is specified.
公用屬性 PublisherChanges Gets the total number of Publisher changes that were applied at the Subscriber during the last synchronization.
公用屬性 PublisherConflicts Gets the total number of conflicts that occurred at the Publisher during the last synchronization.
公用屬性 PublisherDatabase Gets or sets the name of the publication database.
公用屬性 PublisherEncryptedPassword 基礎結構。
公用屬性 PublisherFailoverPartner Gets or sets the failover partner instance of SQL Server that is participating in a database mirroring session with the publication database.
公用屬性 PublisherLogin Gets or sets the login name that is used when connecting to the Publisher by using SQL Server Authentication.
公用屬性 PublisherNetwork Gets or sets the client Net-Library that is used when connecting to the Publisher.
公用屬性 PublisherPassword Sets the password that is used when connecting to the Publisher by using SQL Server Authentication.
公用屬性 PublisherSecurityMode Gets or sets the security mode that is used when connecting to the Publisher.
公用屬性 QueryTimeout Gets or sets the number of seconds that are allowed for internal queries to finish.
公用屬性 SecureDistributorEncryptedPassword 基礎結構。
公用屬性 SecurePublisherEncryptedPassword 基礎結構。
公用屬性 SecureSubscriberEncryptedPassword 基礎結構。
公用屬性 Subscriber Gets or sets the name of the instance of Microsoft SQL Server that is the Subscriber.
公用屬性 SubscriberChanges Gets the total number of Subscriber changes that were applied at the Publisher during the last synchronization.
公用屬性 SubscriberConflicts Gets the total number of conflicts that occurred at the Publisher during the last synchronization.
公用屬性 SubscriberDatabase Gets or sets the name of the subscription database.
公用屬性 SubscriberDatabasePath 基礎結構。
公用屬性 SubscriberDataSourceType Gets or sets the type of data source that is used as the Subscriber.
公用屬性 SubscriberEncryptedPassword 基礎結構。
公用屬性 SubscriberLogin Gets or sets the login name used that is when connecting to the Subscriber by using SQL Server Authentication.
公用屬性 SubscriberPassword Sets the password that is used when connecting to the Subscriber by using SQL Server Authentication.
公用屬性 SubscriberSecurityMode Gets or sets the security mode used when connecting to the Subscriber.
公用屬性 SubscriptionType Gets or sets whether the subscription is a push or pull subscription.
公用屬性 SyncToAlternate Gets or sets whether the synchronization is to an alternate synchronization partner.
公用屬性 UploadGenerationsPerBatch Gets or sets the number of generations to be processed in a single batch while uploading changes from the Subscriber to the Publisher. A generation is defined as a logical group of changes per article.
公用屬性 UseInteractiveResolver Gets or sets whether the interactive resolver is used during reconciliation.
公用屬性 UseWebSynchronization Gets or sets whether Web synchronization is used.
公用屬性 Validate Gets or sets whether data validation is performed on the Subscriber data at the end of the synchronization.
公用屬性 WorkingDirectory Gets or sets the working directory from which snapshot files are accessed when FTP is used.

上層

方法

  名稱 說明
公用方法 Abort 基礎結構。
公用方法 ClearAllTraceFlags 基礎結構。
公用方法 ClearTraceFlag 基礎結構。
公用方法 CreateObjRef (繼承自 MarshalByRefObject。)
公用方法 Dispose() () () () 基礎結構。
受保護的方法 Dispose(Boolean) 基礎結構。
公用方法 EnableTraceFlag 基礎結構。
公用方法 Equals (繼承自 Object。)
受保護的方法 Finalize 基礎結構。 (覆寫 Object. . :: . .Finalize() () () ()。)
公用方法 GetHashCode (繼承自 Object。)
公用方法 GetLifetimeService (繼承自 MarshalByRefObject。)
公用方法 GetType (繼承自 Object。)
公用方法 InitializeLifetimeService (繼承自 MarshalByRefObject。)
公用方法 IsSnapshotRequired Connects to the Publisher or Distributor and the Subscriber to determine whether a new snapshot will be applied during the next agent synchronization.
受保護的方法 MemberwiseClone() () () () (繼承自 Object。)
受保護的方法 MemberwiseClone(Boolean) (繼承自 MarshalByRefObject。)
公用方法 ProcessMessagesAtPublisher 基礎結構。
公用方法 ProcessMessagesAtSubscriber 基礎結構。
公用方法 Synchronize Starts the Merge Agent to synchronize the subscription.
公用方法 ToString (繼承自 Object。)

上層

事件

  名稱 說明
公用事件 ComStatus 基礎結構。
公用事件 Status Occurs when the Merge Agent returns synchronization status information.

上層

備註

The MergeSynchronizationAgent class supports the ability to do the following replication tasks:

  • Synchronize subscriptions.

  • Specify whether only the upload phase, only the download phase, or both phases are run during synchronization.

  • Validate that a subscription has the expected data.

  • Specify a different snapshot folder, from which the initial snapshot for a subscription can be applied.

The MergeSynchronizationAgent class can be used with Publishers and Subscribers that are running on both SQL Server 2000 and SQL Server 2005.

A MergeSynchronizationAgent class cannot be used with Distributors that are running on SQL Server 2000.

範例

In the following example, the Synchronize method is called on the instance of the MergeSynchronizationAgent class that is accessed from the SynchronizationAgent property to synchronize the push subscription.

          // Define the server, publication, and database names.
            string subscriberName = subscriberInstance;
            string publisherName = publisherInstance;
            string publicationName = "AdvWorksSalesOrdersMerge";
            string subscriptionDbName = "AdventureWorks2008R2Replica";
            string publicationDbName = "AdventureWorks2008R2";

            // 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 = "AdventureWorks2008R2Replica"
Dim publicationDbName As String = "AdventureWorks2008R2"

' 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

In the following example, an instance of the MergeSynchronizationAgent class is used to synchronize a merge subscription. Because the pull subscription was created by using a value of false for CreateSyncAgentByDefault, additional properties must be supplied.

            // Define the server, publication, and database names.
            string subscriberName = subscriberInstance;
            string publisherName = publisherInstance;
            string distributorName = distributorInstance;
            string publicationName = "AdvWorksSalesOrdersMerge";
            string subscriptionDbName = "AdventureWorks2008R2Replica";
            string publicationDbName = "AdventureWorks2008R2";
            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 = "AdventureWorks2008R2Replica"
Dim publicationDbName As String = "AdventureWorks2008R2"
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

執行緒安全性

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.