Programming the SQL Snapshot ActiveX Control
New Information - SQL Server 2000 SP3.
Security Note Scripts can be the source of security vulnerabilities; they can invoke system functions without user knowledge or intervention and may contain security credentials in plain text. Review the script for security issues before use. For more information, see Security and Scripting.
The SQL Snapshot control is implemented as a Microsoft® ActiveX® in-process component. It provides a way to create snapshots, and is used by all types of replication. The control is comparable to the Snapshot Agent. Its primary class, the SQLSnapshot object, creates a snapshot of the specified publication on the specified Distributor.
Dynamic snapshots are supported. There are properties to provide values for the HOST_NAME() and SUSER_SNAME() functions when they appear in the filter criteria of dynamic publications, and to specify the location where the dynamic snapshots are written.
Instantiating the SQL Snapshot Control
This example is a Microsoft® Visual Basic® Sub procedure that creates a snapshot from a publication named FullSnapPublication using the database UE_PublisherDB on Publisher UE_PUBLISHER and saves it on Distributor UE_DISTRIBUTOR. Windows Authentication is used for both the Publisher and Distributor connections. The example shows the snapshot code for a snapshot publication. The code for a merge publication requires the ReplicationType property to be set.
Sub Main() Dim oSnapCtl As SQLINITXLib.SQLSnapshot Set oSnapCtl = New SQLINITXLib.SQLSnapshot oSnapCtl.Publisher = "UE_PUBLISHER" oSnapCtl.PublisherDatabase = "UE_PublisherDB" oSnapCtl.PublisherSecurityMode = NT_AUTHENTICATION oSnapCtl.Publication = "FullSnapPublication" oSnapCtl.Distributor = "UE_DISTRIBUTOR" oSnapCtl.DistributorSecurityMode = NT_AUTHENTICATION oSnapCtl.Initialize oSnapCtl.Run oSnapCtl.Terminate End Sub
Note Include the call to the Terminate method to close connections and release allocated memory.