Replication Programming

Creating a Transformable Subscription Using Visual Basic

Advanced users familiar with the Data Transformation Services (DTS) object model can build their own transformable subscription DTS packages in Microsoft® Visual Basic™. For information about programming to the DTS object model, see DTS Programming Reference.

A transformable subscription is a subscription in which the data is modified as it flows from Publisher to Subscriber. In replication programming, a Visual Basic program for a transformable subscription closely resembles that of a DTS Visual Basic program used outside of replication. This sample is located in C:\Program Files\Microsoft SQL Server\80\Tools\DevTools\Samples\sqlrepl\repldts.

How to Run the Transformable Subscription Sample

The program in the repldts folder is a sample of how to write a transformable subscription using Visual Basic.

To run the sample program

  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, start it.

  2. Open Visual Basic 6.0. Open ReplDTS.vbp, and then open the code window for ModReplDTS (ReplDTS.bas).

  3. Select the following Project / References:
    • Microsoft DTSPackage Object Library (required)

    • Microsoft DTSDataPump Scripting Object Library (required to use a Microsoft ActiveX® script or custom transformation)

    • Microsoft DTS Custom Tasks Object Library (required to use one of the DTS custom tasks)
  4. Edit the following line of code to include your own connection information:
    goPackage.SavetoSQLServer "MyServerName", "sa", ""
  5. In Visual Basic, start the ReplDTS program.

  6. When the program is finished executing, you should receive a message indicating the Employees package was saved successfully. When you receive this message, save the project, and then close Visual Basic.

  7. In SQL Server Enterprise Manager, ensure that your server is configured for replication.

  8. In SQL Server Enterprise Manager, click Data Transformation Services, click Local Packages, and then on the Action menu, click Refresh to refresh the view. The package Employees should appear in the right pane.

  9. Open SQL Query Analyzer, open the repldts.sql script supplied with sample, and then edit the @subscriber parameter of sp_addsubscription so that it contains your server name. The sp_addsubscription stored procedure is the last SQL statement in the file.

  10. Run the repldts.sql script. You can run the entire script at once, or you can run the script a block at a time and check each message.

  11. After the repldts.sql script has completed successfully, in SQL Server Enterprise Manager, expand Replication Monitor, expand the Agents folder, and then click the Snapshot Agent folder.

  12. In the right pane, right-click the Snapshot Agent for the Employees publication, and then click Start Agent.

  13. When the Snapshot Agent has completed, view or query the data in MyEmployees table of the subscription database ReplDTS_SubDB, and then compare it to the data in the Employees table of the publication database ReplDTS_PubDB.

  14. The Address column of the MyEmployees table in the subscription database, ReplDTS_subDB, contains data concatenated from several columns of the Employees table of the publication database.
Examining the Sample Code

This section describes key parts of the sample Visual Basic program.