sp_addpublication_snapshot (Transact-SQL)
SQL Server 2012
Creates the Snapshot Agent for the specified publication. This stored procedure is executed at the Publisher on the publication database.
Security Note
|
|---|
|
When configuring a Publisher with a remote Distributor, the values supplied for all parameters, including job_login and job_password, are sent to the Distributor as plain text. You should encrypt the connection between the Publisher and its remote Distributor before executing this stored procedure. For more information, see Enable Encrypted Connections to the Database Engine (SQL Server Configuration Manager). |
sp_addpublication_snapshot [ @publication= ] 'publication'
[ , [ @frequency_type= ] frequency_type ]
[ , [ @frequency_interval= ] frequency_interval ]
[ , [ @frequency_subday= ] frequency_subday ]
[ , [ @frequency_subday_interval= ] frequency_subday_interval ]
[ , [ @frequency_relative_interval= ] frequency_relative_interval ]
[ , [ @frequency_recurrence_factor= ] frequency_recurrence_factor ]
[ , [ @active_start_date= ] active_start_date ]
[ , [ @active_end_date= ] active_end_date ]
[ , [ @active_start_time_of_day= ] active_start_time_of_day ]
[ , [ @active_end_time_of_day= ] active_end_time_of_day ]
[ , [ @snapshot_job_name = ] 'snapshot_agent_name' ]
[ , [ @publisher_security_mode = ] publisher_security_mode ]
[ , [ @publisher_login = ] 'publisher_login' ]
[ , [ @publisher_password = ] 'publisher_password' ]
[ , [ @job_login = ] 'job_login' ]
[ , [ @job_password = ] 'job_password' ]
[ , [ @publisher = ] 'publisher' ]
-- To avoid storing the login and password in the script file, the values -- are passed into SQLCMD as scripting variables. For information about -- how to use scripting variables on the command line and in SQL Server -- Management Studio, see the "Executing Replication Scripts" section in -- the topic "Programming Replication Using System Stored Procedures". DECLARE @publicationDB AS sysname; DECLARE @publication AS sysname; DECLARE @login AS sysname; DECLARE @password AS sysname; SET @publicationDB = N'AdventureWorks'; SET @publication = N'AdvWorksProductTran'; -- Windows account used to run the Log Reader and Snapshot Agents. SET @login = $(Login); -- This should be passed at runtime. SET @password = $(Password); -- Enable transactional or snapshot replication on the publication database. EXEC sp_replicationdboption @dbname=@publicationDB, @optname=N'publish', @value = N'true'; -- Execute sp_addlogreader_agent to create the agent job. EXEC sp_addlogreader_agent @job_login = @login, @job_password = @password, -- Explicitly specify the use of Windows Integrated Authentication (default) -- when connecting to the Publisher. @publisher_security_mode = 1; -- Create a new transactional publication with the required properties. EXEC sp_addpublication @publication = @publication, @status = N'active', @allow_push = N'true', @allow_pull = N'true', @independent_agent = N'true'; -- Create a new snapshot job for the publication, using a default schedule. EXEC sp_addpublication_snapshot @publication = @publication, @job_login = @login, @job_password = @password, -- Explicitly specify the use of Windows Integrated Authentication (default) -- when connecting to the Publisher. @publisher_security_mode = 1; GO

Security Note