sp_attachsubscription

Transact-SQL Reference

Transact-SQL Reference

sp_attachsubscription

Attaches an existing subscription database to any Subscriber. This stored procedure is executed at the new Subscriber on the master database.

Syntax

sp_attachsubscription [ @dbname = ] 'dbname'
    , [ @filename = ] 'filename'
    [ , [ @subscriber_security_mode = ] 'subscriber_security_mode' ]
    [ , [ @subscriber_login = ] 'subscriber_login' ]
    [ , [ @subscriber_password = ] 'subscriber_password' ]

Arguments

[@dbname = ] 'dbname'

Is the string that specifies an existing database by name. dbname is sysname, with no default.

[@filename = ] 'filename'

Is the name and physical location of the primary MDF (master data file). file name is nvarchar(260), with no default.

[@subscriber_security_mode = ] 'subscriber_security_mode'

Is the security mode of the Subscriber to use when connecting to a Subscriber when synchronizing. subscriber_security_mode is int, with a default of NULL. If 0, the security mode is SQL Server Authentication. If 1, the security mode is Windows Authentication.

[@subscriber_login = ] 'subscriber_login'

Is the Subscriber login name to use when connecting to a Subscriber when synchronizing. subscriber_login is sysname, with a default of NULL. If subscriber_security_mode is 0, this parameter must be specified.

[@subscriber_password = ] 'subscriber_password'

Is the Subscriber password. subscriber_password is sysname, with a default of NULL. If SubscriberSecurityMode is 0, this parameter must be specified. If a subscriber password is used, it is automatically encrypted.

Return Code Values

0 (success) or 1 (failure)

Remarks

sp_attachsubscription is used in snapshot replication, transactional replication, and merge replication.

A subscription cannot be attached to the publication if the publication retention period has expired. If a subscription with an elapsed retention period is specified, an error will occur either when the subscription is attached or when it is first synchronized. Publications with a publication retention period of 0 (never expire) are ignored.

Permissions

Only members of the sysadmin fixed server role or db_owner fixed database role can execute sp_attachsubscription.

See Also

Attachable Subscription Databases

System Stored Procedures