script execution in replication

  • Hi,

    is there anyway to execute script automatically on publisher after initialization. does sp_addscriptexec execute script on subscriber only??

  • Yes this can be added as a script for post snapshot which will be applied at the subscriber.

    This can be found in SSMS under the properties of the publication in the "Snapshot" section.

    Alternative it can be added programmatically like so:

    declare @post_script_loc NVARCHAR(1000)

    SET @post_script_loc = 'X:\MyScript.sql'

    exec sp_addpublication @publication = N'pub1', @description = N'Transactional publication of database database1', @sync_method = N'native', @retention = 0, @allow_push = N'true', @allow_pull = N'true', @allow_anonymous = N'true', @enabled_for_internet = N'false', @snapshot_in_defaultfolder = N'true', @compress_snapshot = N'false', @ftp_port = 21, @ftp_login = N'anonymous', @allow_subscription_copy = N'false', @add_to_active_directory = N'false', @repl_freq = N'continuous', @status = N'active', @independent_agent = N'true', @immediate_sync = N'true', @allow_sync_tran = N'false', @autogen_sync_procs = N'false', @allow_queued_tran = N'false', @allow_dts = N'false', @replicate_ddl = 1, @allow_initialize_from_backup = N'false', @enabled_for_p2p = N'false', @enabled_for_het_sub = N'false',@post_snapshot_script = @post_script_loc

    MCITP SQL 2005, MCSA SQL 2012

  • Thanks for the reply, when we define post initialization script, it runs only on subscribers, what if i want to run few permission related script in publisher only?

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply