Quantcast
Channel: SQL Server Replication forum
Viewing all articles
Browse latest Browse all 4054

Transnational Replication -- The transaction ended in the trigger. The batch has been aborted

$
0
0

Hello All,

When i am trying to configure Transnational replication for 3TB of database manually i am getting below error message when ever i perform any Alter Table statement after i configure replication.

Msg 3609, Level 16, State 2, Line 14
The transaction ended in the trigger. The batch has been aborted

Steps Followed :

1. Configure Publication Manually.
2. Change Subscription to "Initialization from Backup Files".
3. Perform Full Backup and Subsequent 2 Log backups.
4. Then run SP_AddSubscription to Initialization from Backup.

Every thing works fine with out any errors. All Distributor, Log reader agent jobs are created. I get above error message only when i perform any ALTER table statement once replication is set up. My Subscriber is Readonly.

Surprisingly i get same error message even if run ALTER statement in SUBSCRIBER directly from SSMS.

I created below SP to generate replication script dynamically.
CREATE PROC [dbo].[Create_Replication] @Database_Name sysname , @Publication_Name varchar(20) = Null
AS
BEGIN
	--  Declare and Set values to Local variables
	Declare @DB_Name sysname
	Declare @Pub_Name varchar(20)

	SET @DB_Name = @Database_Name
	IF @Publication_Name IS NULL
		SET @Pub_Name = @DB_Name
	ELSE
		SET @Pub_Name = @Publication_Name

	PRINT 'USE ' + @DB_Name
	PRINT 'GO'

	--Set Publication property to True
	PRINT 'PRINT ''Set Publication property to True'''
	Print 'EXEC sp_replicationdboption @dbname = N''' + @DB_Name + ''', @optname = N''publish'', @value = N''true'''
	PRINT 'GO'
	PRINT ''
	-- Add Log Reader Agent
	PRINT 'PRINT ''Add Log Reader Agent'''
	PRINT 'EXEC '+ @DB_Name+'.sys.sp_addlogreader_agent @job_login = null, @job_password = null, @publisher_security_mode = 1'
	PRINT 'GO'
	PRINT ''

	-- Add Transcational Publication.
	PRINT 'PRINT ''Add Transcational Publication'''
	PRINT 'EXEC sp_addpublication @publication = N''' + @DB_Name + '''
		, @description = N''Transactional publication of database' + @DB_Name + ' from Publisher ' +  @@SERVERNAME +'''
		, @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''false''
			, @autogen_sync_procs = N''false''
			, @allow_queued_tran = N''false''
			, @allow_dts = N''false''
			, @replicate_ddl = 1
			, @allow_initialize_from_backup = N''true''
			, @enabled_for_p2p = N''false''
			, @enabled_for_het_sub = N''false'''
	PRINT 'GO'

	--Add SnapShot Agenet.
	PRINT 'PRINT ''Add SnapShot Agenet'''
	PRINT 'exec sp_addpublication_snapshot @publication = N''' + @Pub_Name + '''
			, @frequency_type = 1
			, @frequency_interval = 0
			, @frequency_relative_interval = 0
			, @frequency_recurrence_factor = 0
			, @frequency_subday = 0
			, @frequency_subday_interval = 0
			, @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'
	PRINT 'GO'

	PRINT 'EXEC sp_grant_publication_access @publication = N''' + @DB_Name + ''', @login = N''distributor_admin'''
	PRINT 'GO'

	PRINT ''
	-- Adding Articles
	Declare @addar nvarchar(max)
	Declare @Tbl varchar(250)
	DECLARE tbl_cursor CURSOR FOR
	Select distinct Name from sys.tables where is_ms_shipped = 0 and name not like 't_properties_%' and OBJECTPROPERTY(OBJECT_ID,'TableHasPrimaryKey') = 1

	OPEN tbl_cursor
	FETCH NEXT from tbl_cursor into @Tbl

	WHILE @@FETCH_STATUS = 0
	BEGIN
	--- Add Articles to Publication.
	PRINT 'PRINT ''Working on Table ' + @Tbl + ''''
	PRINT 'USE ' + @DB_Name

	select @addar =  'Exec sp_addarticle @publication = N''QAFORUMJobs''
		, @article = N''' + t.name + '''
		, @source_owner = N''' + s.name + '''
		, @source_object = N'''+ t.name + '''
		, @type = N''logbased''
		, @description = N''
		, @creation_script = N''
		, @pre_creation_cmd = N''drop''
		, @schema_option = 0x000000000803509F
		, @identityrangemanagementoption = N''manual''
		, @destination_table = N''' + t.name + '''
		, @destination_owner = N''dbo''
		, @status = 24
		, @vertical_partition = N''false''
		, @ins_cmd = N''CALL [sp_MSins_' + s.name + t.name + ']''
		, @del_cmd = N''CALL [sp_MSdel_' + s.name +  t.name + ']''
		, @upd_cmd = N''SCALL [sp_MSupd_' + s.name +  t.name + ']'''
	from sys.tables as  t   inner join sys.schemas as s on t.schema_id = s.schema_id where t.name = @Tbl
	 Print @addar
	 PRINT 'GO'
	 Print ''
	 FETCH NEXT from tbl_cursor into @Tbl
	 END

	 CLOSE tbl_cursor
	DEALLOCATE tbl_cursor
END

GO
2. Subscription creation Script.
EXEC sp_addsubscription
@publication = N' ',
@subscriber = N' ',
@destination_db = N' ',
@sync_type = N'initialize with backup',
@backupdevicetype='Disk',
@backupdevicename='z:\Backup\log_2.trn',
@subscription_type = N'push',
@update_mode = N'read only'



 


Viewing all articles
Browse latest Browse all 4054

Trending Articles