Using SQL Merge and SQL Distribution Controls in a Custom Visual Basic Application

Replication Programming

Replication Programming

Using SQL Merge and SQL Distribution Controls in a Custom Visual Basic Application

The programs in the replctrl folder are samples of how to include the SQL Merge and SQL Distribution controls in a custom application. This sample is located in C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\Samples\sqlrepl\replctrl.

To run the sample programs

  1. On the computer that will be a Publisher with a local Distributor, verify that the SQL Server Agent is running. If it is not running, start it.

  2. Open SQL Query Analyzer, open \Samples\sqlrepl\replctrl\instsamp.sql, and then run instsamp.sql. This SQL script configures the computer for publishing and distribution, enables the computer as a Subscriber, adds a distribution database with the name distributor, creates a transactional publication named SampleTransactionalPublication, and creates a merge publication named SampleMergePublication. 

  3. The instsamp.sql script creates pull and push subscriptions for each publication and creates and configures a database called Northwind_replica as the subscription database. Any warnings from the script regarding tables that have been created with a maximum row size that exceeds the maximum number of bytes per row can be ignored. The computer is now configured as a Publisher with a local Distributor and enabled as a Subscriber.

    The Northwind publication database will have two publications: SampleTransactionalPublication and SampleMergePublication. The instance of SQL Server contains a new subscription database, Northwind_replica.

  4. After the instsamp.sql script has completed successfully, in SQL Server Enterprise Manager, expand Replication Monitor, expand the Agents folder, and then click the Snapshot Agents folder. In the right pane, for each agent listed, right-click, and then click Start Agent. This starts the Snapshot Agents for each publication and creates a snapshot for each publication.

  5. Start Visual Basic, and then open \Samples\sqlrepl\replctrl\VB\replsamp.vbp.

  6. On the Project menu, click References, and then in the Available References list, verify that the following controls are selected:
    • Microsoft SQL Distribution Control 8.0

    • Microsoft SQL Merge Control 8.0

    • Microsoft SQL Snapshot Control 8.0

    • Microsoft SQL Replication Errors 8.0
  7. On the File menu, click Make ReplSamp.exe, and then save the executable to a directory.

  8. Run replsamp.exe. The following options will be displayed:

    Generate Snapshot for Transactional Publication

    Creates a snapshot for the Northwind transactional publication. The snapshot activity can be monitored interactively in SQL Server Enterprise Manager using Replication Monitor and the Agents folder.

    Generate Snapshot for Merge Publication

    Creates a snapshot for the Northwind merge publication. The snapshot activity can be monitored interactively in SQL Server Enterprise Manager using Replication Monitor and the Agents folder.

    Update Transactional Subscription Tables

    Runs the Distribution Agent and applies the snapshot and schema at the subscription database, Northwind_replica. After the SQL Replication Sample dialog box shows that the task has completed, the Northwind_replica subscription database shows the new tables. The distribution activity can be monitored interactively in SQL Server Enterprise Manager using Replication Monitor and the Agents folder.

    Update Merge Subscription Tables

    Runs the Merge Agent and applies the snapshot data and schema at the merge subscription database, Northwind_replica. After the SQL Replication Sample dialog box shows that the task has completed, the Northwind_replica subscription database shows the new tables. The merge activity can be monitored interactively in SQL Server Enterprise Manager using Replication Monitor and the Agents folder.