Script Method (Replication Objects) (SQL-DMO)

The Script method generates a Transact-SQL command batch that can be used to re-create the Microsoft® SQL Server™ component referenced by the SQL-DMO object.

Applies To
DistributionDatabase Object RegisteredSubscriber Object
DistributionDatabases Collection RegisteredSubscribers Collection
DistributionPublisher Object Replication Object
DistributionPublishers Collection ReplicationDatabase Object
Distributor Object ReplicationDatabases Collection
MergePublication Object Subscriber Object
MergePublications Collection TransArticle Object
MergePullSubscription Object TransPublication Object
MergePullSubscriptions Collection TransPublications Collection
MergeSubscription Object TransPullSubscription Object
MergeSubscriptions Collection TransPullSubscriptions Collection
Publisher Object TransSubscription Object
  TransSubscriptions Collection

Syntax

object.Script( [ ScriptType ] , [ ScriptFilePath ] ) as String

Part Description
object Expression that evaluates to an object in the Applies To list.
ScriptType Optional. A long integer overriding default scripting behavior as described in Settings.
ScriptFilePath Optional. A string specifying an operating system file as an additional target for the generated Transact-SQL statements script.

Settings

When setting the ScriptType argument specifying multiple behaviors, combine values by using an Or. Use these values to set ScriptType.

Constant Value Description
SQLDMORepScript_AnsiFile 16777216 Create output file as a multibyte character text file.
SQLDMORepScript_AppendToFile 8192 Append output to the file identified in the ScriptFilePath argument. By default, Script overwrites an existing file.
SQLDMORepScript_Creation 16384 Command batch includes Transact-SQL statements statements creating the referenced component.
SQLDMORepScript_Default 256 SQLDMORepScript_
InstallDistributor.
SQLDMORepScript_Deletion 32768 Command batch includes Transact-SQL statements removing the referenced component. Transact-SQL statements removing a component are prefixed by a test for existence.
SQLDMORepScript_
DisableReplicationDB
134217728 Command batch includes Transact-SQL statements disabling a replication database.
SQLDMORepScript_
EnableReplicationDB
67108864 Command batch includes Transact-SQL statements enabling a replication database.
SQLDMORepScript_
InstallDistributor
256 Default. Command batch includes Transact-SQL statements installing a Distributor.
SQLDMORepScript_InstallPublisher 1024 Command batch includes Transact-SQL statements installing a Publisher.
SQLDMORepScript_
InstallReplication
1048576 Command batch includes Transact-SQL statements installing replication components.
SQLDMORepScript_
NoCommandTerm
268435456 Individual Transact-SQL statements statements in the command batch are not delimited using the connection-specific command terminator. By default, individual Transact-SQL statements statements are delimited
SQLDMORepScript_NoSubscription 128 When scripting a command batch creating a publication, do not include statements creating existing subscriptions.
SQLDMORepScript_
PublicationCreation
65536 Command batch includes Transact-SQL statements creating a publication
SQLDMORepScript_
PublicationDeletion
131072 Command batch includes Transact-SQL statements deleting a publication
SQLDMORepScript_
SubscriptionCreation
262144 Command batch includes Transact-SQL statements creating a subscription
SQLDMORepScript_
SubscriptionDeletion
524288 Command batch includes Transact-SQL statements deleting a subscription
SQLDMORepScript_ToFileOnly 4096 When used, and an output file is specified in the ScriptFilePath argument, the Script method does not return the script to the caller, but only writes the script to the output file
SQLDMORepScript_UnicodeFile 33554432 Create output file as a Unicode character text file.
SQLDMORepScript_
UninstallDistributor
512 Command batch includes Transact-SQL statements removing the Distributor
SQLDMORepScript_
UninstallPublisher
2048 Command batch includes Transact-SQL statements removing the Publisher.
SQLDMORepScript_
UninstallReplication
2097152 Command batch includes Transact-SQL statements removing replication components

Returns

A Transact-SQL command batch as a string.

Remarks

The Script method of replication objects captures an image of a SQL Server replication installation. For example, using the Script method of the TransArticle object generates a command batch that can be used to create the transactional or snapshot replication article referenced, not the object replicated by the article.

For SQL-DMO objects publishing replicatable database objects, SQL-DMO implements the ScriptDestinationObject method to generate command batches that re-create the objects replicated. For more information, see ScriptDestinationObject Method.


Note SQL-DMO object scripting methods are fully compatible with SQL Server version 7.0. However, database compatibility level affects Transact-SQL command batch contents.

When scripting a database with a compatibility level of less than 7.0, or when scripting any of its objects, the resulting Transact-SQL command batch includes only keywords reserved by that level.

Transact-SQL command syntax is always compliant with SQL Server 7.0. Where they are provided, you can use optional scripting arguments, such as SQLDMOScript2_NoFG to remove some version 7.0 specific syntax.


Prototype (C/C++)

HRESULT Script(
SQLDMO_REPSCRIPT_TYPE ScriptType = SQLDMORepScript_Default,
SQLDMO_LPCSTR ScriptFilePath = NULL,
SQLDMO_LPBSTR ScriptText = NULL);

(Distributor Object)

HRESULT Script(
SQLDMO_REPSCRIPT_TYPE ScriptType = SQLDMORepScript_InstallDistributor,
SQLDMO_LPCSTR ScriptFilePath = NULL,
SQLDMO_LPBSTR ScriptText = NULL);


Note SQL-DMO strings are always returned as OLE BSTR objects. A C/C++ application obtains a reference to the string. The application must release the reference by using SysFreeString.


  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.