You are here:Home » tsql » Configuration of Transaction replication with updatable subscrption

Configuration of Transaction replication with updatable subscrption

--Script to configure Transaction replication with updatable subscrption
------------------------------------------------------------------------

-- Enabling the replication database
use master
exec sp_replicationdboption @dbname = N'Replsub', @optname = N'publish', @value = N'true'
GO

exec [Replsub].sys.sp_addlogreader_agent @job_login = null, @job_password = null, @publisher_security_mode = 0, @publisher_login = N'sa', @publisher_password = N''
GO
exec [Replsub].sys.sp_addqreader_agent @job_login = null, @job_password = null, @frompublisher = 1
GO
-- Adding the transactional publication
use [Replsub]
exec sp_addpublication @publication = N'TranRepl', @description = N'Transactional publication with updatable subscriptions of database ''Replsub'' from Publisher ''InstanceName''.', @sync_method = N'concurrent', @retention = 0, @allow_push = N'true', @allow_pull = N'true', @allow_anonymous = N'false', @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'false', @allow_sync_tran = N'true', @autogen_sync_procs = N'true', @allow_queued_tran = N'true', @allow_dts = N'false', @conflict_policy = N'pub wins', @centralized_conflicts = N'true', @conflict_retention = 14, @queue_type = N'sql', @replicate_ddl = 1, @allow_initialize_from_backup = N'false', @enabled_for_p2p = N'false', @enabled_for_het_sub = N'false'
GO


exec sp_addpublication_snapshot @publication = N'TranRepl', @frequency_type = 4, @frequency_interval = 1, @frequency_relative_interval = 1, @frequency_recurrence_factor = 0, @frequency_subday = 8, @frequency_subday_interval = 1, @active_start_time_of_day = 0, @active_end_time_of_day = 235959, @active_start_date = 0, @active_end_date = 0, @job_login = null, @job_password = null, @publisher_security_mode = 1
exec sp_grant_publication_access @publication = N'TranRepl', @login = N'sa'
GO


-- Adding the transactional articles
use [Replsub]
exec sp_addarticle @publication = N'TranRepl', @article = N'testreplpr', @source_owner = N'dbo', @source_object = N'testreplpr', @type = N'logbased', @description = N'', @creation_script = N'', @pre_creation_cmd = N'drop', @schema_option = 0x0000000008035CDF, @identityrangemanagementoption = N'none', @destination_table = N'testreplpr', @destination_owner = N'dbo', @status = 24, @vertical_partition = N'false', @ins_cmd = N'CALL [dbo].[sp_MSins_dbotestreplpr]', @del_cmd = N'VCALL [dbo].[sp_MSdel_dbotestreplpr]', @upd_cmd = N'VCALL [dbo].[sp_MSupd_dbotestreplpr]'
GO

-- Adding the transactional subscriptions
use [Replsub]
exec sp_addsubscription @publication = N'TranRepl', @subscriber = N'InstanceName', @destination_db = N'Repl', @subscription_type = N'Push', @sync_type = N'automatic', @article = N'all', @update_mode = N'failover', @subscriber_type = 0
exec sp_addpushsubscription_agent @publication = N'TranRepl', @subscriber = N'InstanceName', @subscriber_db = N'Repl', @job_login = null, @job_password = null, @subscriber_security_mode = 1, @frequency_type = 64, @frequency_interval = 1, @frequency_relative_interval = 1, @frequency_recurrence_factor = 0, @frequency_subday = 4, @frequency_subday_interval = 5, @active_start_time_of_day = 0, @active_end_time_of_day = 235959, @active_start_date = 0, @active_end_date = 0, @dts_package_location = N'Distributor'
-- To make this subscription functional, you must also execute sp_link_publication at the Subscriber.
GO