共用方式為


Subscriber Monitor Sample

The Sales Orders Sample solution includes two additional projects, SubscriberMonitor and SubscriberMonitorUtility. Together, these projects use the replication monitor support in Replication Management Objects (RMO) to provide the functionality to monitor the status of the subscription at the local Subscriber. The SubscriberMonitor.dll assembly is accessible by other applications that run at the Subscriber, and the SubscriberMonitorUtility.exe program is run directly to display the Subscriber Monitor.

Using Subscriber Monitor

To build and run the Subscriber Monitor Utility sample

  1. Ensure that the SQL Server 2005 replication samples are installed. For more information, see 安裝範例.

  2. Navigate to the installation location for the Subscriber Monitor sample. The default location for this sample is C:\Program Files\Microsoft SQL Server\90\Samples\Replication\Merge\CS\SubscriberMonitorUtility.

  3. Open the SubscriberMonitorUtility.sln solution file in Visual Studio 2005.

  4. Build the solution.

  5. Run SubscriberMonitorUtility.exe from the build location. The default build location is \bin\debug.

  6. In the Select Subscription to Monitor dialog box, choose an instance of SQL Server from the Local Server Name drop-down box.

  7. Select a subscription to monitor from the Available Subscriptions drop-down list box.

  8. (Optional) Click the Edit button to change subscription properties.

  9. Click Connect.

  10. Select a Merge Agent session from the Merge Sessions tree view.

  11. (Optional) Click the Refresh button to refresh the session list.

To programmatically invoke the Subscriber Monitor

  1. Open the Visual Studio 2005 project that will invoke the Subscriber Monitor.

  2. Add a reference to the SubscriberMonitor.dll assembly. This assembly is built as part of the SubscriberMonitorUtility.sln or SalesOrders.sln solutions. For more information about building the Sales Orders sample, see 合併式複寫的銷售訂單範例.

  3. (Optional) Add a using directive (C#) or Imports statement (Visual Basic .NET) for the Microsoft.Samples.SqlServer namespace.

  4. In your code, create an instance of the SubscriberMonitor class in one of the following ways:

    • Passing the Subscriber name and a SubscriberSubscription object that represents the subscription to monitor to the subscription parameter.
    • Passing values into the constructor for the following parameters that define a subscription: subscriber, publication, publisher, publicationDb, subscriber, and subscriptionDb.

Implementation Details

Subscriber Monitor is a Windows Forms application based on Microsoft Windows .NET Framework 2.0. The application is started by running SubscriberMonitorUtility.exe. This executable creates an instance of the SubscriberMonitor class, displays a dialog that enables a user to select the subscription to monitor, and then display the Windows form. The SubscriberMonitor class can also be instantiated from a sample application. Two constructor methods are implemented that allow you to pass subscription properties during the creation of the new object. These properties can also be set after the object is created.

When the default constructor is used, a dialog box is displayed that allows you to select the Subscriber instance on the local computer as well as the subscription to monitor. The Local Server Name drop-down list box is populated with available instance names returned by the ServerInstances property. When a server instance is selected, the Available Subscriptions drop-down list box is populated with subscriptions returned by calling the EnumSubscriberSubscriptions method.

The sample uses MergeSubscriberMonitor class to retrieve subscription information from the Subscriber and display this information in the form. When the form loads, the GetSessionsSummary method returns an array of MergeSessionSummary objects that represent up to five previous Merge Agent sessions. The Merge SessionsTreeView control is populated with these MergeSessionSummary objects. When you select one of the sessions, summary information about the session is displayed. Also, the array of MergeSessionDetail objects returned by the GetSessionDetails method are displayed in the Articles processed in sessionListView control.

For more information about using programming with the MergeSubscriberMonitor class, see How to: Programmatically Monitor Replication (RMO Programming).

請參閱

其他資源

複寫範例

說明及資訊

取得 SQL Server 2005 協助