Replication Programming
Programming Replication ActiveX Controls Using VBScript
Using the Microsoft® ActiveX® replication controls with Microsoft Visual Basic® Scripting Edition is supported with the following limitations:
- Named constants are not supported. You must specify the actual value represented by the constant; for example, AddSubscription(0, 1) instead of coding AddSubscription(EXISTING_DATABASE, SYNC_MANAGER).
- The error handler is not supported. You must use the ErrorRecords.Count method to determine if there are failures.
This example demonstrates how an HTML page using Visual Basic Scripting Edition configures the SQL Distribution control to synchronize data for an anonymous subscription over the Internet:
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>
<body>
<p><font face="Papyrus">This is only a test.</font></p>
<p>
<object classid="clsid:08B0B2E6-3FB3-11D3-A4DE-00C04F610189" id="oSQLDistribution" data="DATA:application/x-oleobject;BASE64,5rKwCLM/0xGk3gDAT2EBiQADAADYEwAA2BMAAA==" width="240" height="240">
</object>
</p>
<script LANGUAGE="VBScript">
<!--
Sub window_onload()
Call DoSync()
End Sub
Sub DoSync()
Dim oErrorObject
On Error Resume Next
' Configure the control for an anonymous subscription.
oSQLDistribution.Publisher = "PUBLISHERNAME"
oSQLDistribution.PublisherDatabase = "PublishedDBName"
oSQLDistribution.Publication = "PublicationName"
oSQLDistribution.PublisherSecurityMode = 0 ' DB_AUTHENTICATION
oSQLDistribution.PublisherLogin = "sa"
oSQLDistribution.PublisherPassword = ""
oSQLDistribution.SubscriberDatasourceType = 0 ' SQL_SERVER
oSQLDistribution.Subscriber = "SUBSCRIBERNAME"
oSQLDistribution.SubscriberDatabase = "SubscribingDBName"
oSQLDistribution.SubscriptionType = 2 ' ANONYMOUS
oSQLDistribution.SubscriberSecurityMode = 0 ' DB_AUTHENTICATION
oSQLDistribution.SubscriberLogin = "sa"
oSQLDistribution.SubscriberPassword = ""
'Configure the control to access Publisher over the Internet using TCP/IP.
oSQLDistribution.PublisherNetwork = 1 ' TCPIP_SOCKETS
' Replace 000.00.00.00 with the correct IP address
oSQLDistribution.PublisherAddress = "000.00.00.00,1433"
oSQLDistribution.FileTransferType = 1 ' FILETRANSFERFTP
' Synchronize the data.
oSQLDistribution.Initialize
If (oSQLDistribution.ErrorRecords.Count > 0) Then
' Display each error message.
For Each oErrorObject in oSQLDistribution.ErrorRecords
MsgBox oErrorObject.Description, vbCritical, "SQLDist Failure"
Next
Else
oSQLDistribution.Run
If (oSQLDistribution.ErrorRecords.Count > 0) Then
' Display each error message.
For Each oErrorObject in oSQLDistribution.ErrorRecords
MsgBox oErrorObject.Description, vbCritical, "SQLDist Failure"
Next
Else
oSQLDistribution.Terminate
If (oSQLDistribution.ErrorRecords.Count > 0) Then
' Display each error message.
For Each oErrorObject in oSQLDistribution.ErrorRecords
MsgBox oErrorObject.Description, vbCritical, "SQLDist Failure"
Next
End If
End If
End If
End Sub
Sub oSQLDistribution_Status(Message, Percent)
'Display message here.
End Sub
</script>
</body>
</html>
Note The properties in this example are the same for both the SQL Merge and SQL Distribution controls. You can replace references to the SQLDistribution object with references to the SQLMerge object.