Script Method (Replication Objects)

SQL-DMO

SQL-DMO
Syntax

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

Parts

object

Expression that evaluates to an object in the Applies To list.

ScriptType

Optional. A long integer that overrides default scripting behavior as described in Settings.

ScriptFilePath

Optional. A string that specifies an operating system file as an additional target for the generated Transact-SQL statements script.

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 using SysFreeString.

Settings

When setting the ScriptType argument specifying multiple behaviors, combine values using an OR logical operator. Use these SQLDMO_REPSCRIPT_TYPE values to set ScriptType.

Constant Value Description
SQLDMORepScript_AnsiFile 16777216 Output to a file is written as ANSI character text.
SQLDMORepScript_AppendToFile 8192 Output is appended to a designated operating system file. If not set, output overwrites any data in an existing, designated file.
SQLDMORepScript_Creation 16384 Script includes database object creation.
SQLDMORepScript_Default 256 SQLDMORepScript_InstallDistributor.
SQLDMORepScript_Deletion 32768 Script includes deletion of existing database objects.
SQLDMORepScript_DisableReplicationDB 134217728 Script disables a replication database.
SQLDMORepScript_EnableReplicationDB 67108864 Script enables a replication database.
SQLDMORepScript_InstallDistributor 256 Default. The script installs the replication Distributor.
SQLDMORepScript_InstallPublisher 1024 Script installs a Publisher.
SQLDMORepScript_InstallReplication 1048576 Script installs replication.
SQLDMORepScript_NoCommandTerm 268435456 No command terminator is added to script commands.
SQLDMORepScript_NoSubscription 128 Script creation of publication, excluding push subscriptions.
SQLDMORepScript_PublicationCreation 65536 Script includes publication creation text.
SQLDMORepScript_PublicationDeletion 131072 Script includes text that removes publications.
SQLDMORepScript_PullSubscriptionCreation 262144 Script pull subscription creation.
SQLDMORepScript_PullSubscriptionDeletion 524288 Script pull subscription deletion.
SQLDMORepScript_ReplicationJobs 4194304 Script creation of replication-related jobs to preserve job schedule and steps. The corresponding job script must be run before the replication script.
This constant can only be used with Microsoft® SQL Server™ 2000. Only a member of the sysadmin fixed server role or the owner of a job have access to a job creation script.
SQLDMORepScript_SubscriptionCreation 262144 Obsolete.
SQLDMORepScript_SubscriptionDeletion 524288 Obsolete.
SQLDMORepScript_ToFileOnly 4096 Output generated by an executed script is directed to an operating system file only. If not set, output is available as status or error messages.
SQLDMORepScript_UnicodeFile 33554432 Output to a file is written as Unicode character text.
SQLDMORepScript_UninstallDistributor 512 Script removes the replication Distributor.
SQLDMORepScript_UninstallPublisher 2048 Script removes a Publisher.
SQLDMORepScript_UninstallReplication 2097152 Script removes replication.

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.

To script the creation of a single pull subscription, call the Script method using SQLDMORepScript_PullSubscriptionCreation on a TransPullSubscription or MergePullSubscription object. To script the removal of a single pull subscription, call the Script method using SQLDMORepScript_PullSubscriptionDeletion on a TransPullSubscription or MergePullSubscription object.

To script the creation of pull subscriptions in the TransPullSubscriptions or MergePullSubscriptions collection, call the Script method using SQLDMORepScript_PullSubscriptionCreation. To script the removal of pull subscriptions from the TransPullSubscriptions or MergePullSubscriptions collection, call the Script method using SQLDMORepScript_PullSubscriptionDeletion.

To script the creation of or dropping pull subscriptions in a database, call the Script method using SQLDMORepScript_PullSubscriptionCreation on a ReplicationDatabase object. To script the removal of pull subscriptions from a database, call the Script method using SQLDMORepScript_PullSubscriptionDeletion on a ReplicationDatabase object.

To script the creation of pull subscriptions on a server, call the Script method using SQLDMORepScript_PullSubscriptionCreation on a ReplicationDatabases collection or Subscriber object. To script the removal of pull subscriptions from a server, call the Script method using SQLDMORepScript_PullSubscriptionDeletion on a ReplicationDatabases collection or Subscriber object.

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

Note  SQL-DMO object scripting methods are fully compatible with an instance of 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 an instance of SQL Server 7.0. Where provided, you can use optional scripting arguments, such as SQLDMOScript2_NoFG to remove some syntax of an instance of SQL Server 7.0.

See Also

Scripting Replication