Forum Discussion

gyvkoff's avatar
gyvkoff
Brass Contributor
Aug 13, 2024
Solved

Log Reader Agent throwing errors on Azure SQL Managed Instance

I configured Azure SQL Managed Instance for transactional replication, it is a publisher with local distributor. I got it set up and the snapshot agent runs successfully, but the log reader agent is throwing errors:

 

    The last step did not log any message! (Source: MSSQL_REPL, Error number: MSSQL_REPL22037)
    Get help: http://help/MSSQL_REPL22037

 

 

I tried setting up with TSQL script as well as via replication wizard. Still no luck with the logreader agent.

 

Note - this instance of MI was migrated from on-premise. I verified that the replAgentUser was created and does exist.

 

 

 

 

USE master
GO

EXEC sp_adddistributor  = @@SERVERNAME, @password = NULL
GO
EXEC sp_adddistributiondb @database = N'distribution'
    , @min_distretention = 0
    , _distretention = 72
    , @history_retention = 48
    , @deletebatchsize_xact = 5000
    , @deletebatchsize_cmd = 2000
    , @security_mode = 1
GO

EXEC sp_adddistpublisher @publisher = @@SERVERNAME
    , @distribution_db = N'distribution'
    , @security_mode = 0
    , @login = '<login>'
    , @password = '<password>'
    , @working_directory = N'\\<name>.file.core.windows.net\replshare'
    , @storage_connection_string = N'DefaultEndpointsProtocol=https;AccountName=<name>;AccountKey=<key>;EndpointSuffix=core.windows.net'
GO

EXEC sp_replicationdboption @dbname = N'db1'
    , @optname = N'publish'
    , @value = N'true'
GO

USE [db1]
GO
-- Adding the transactional publication
EXEC sp_addpublication @publication = N'pub1'
    , @description = N'Transactional publication'
    , @sync_method = N'concurrent'
    , @retention = 0
    , @allow_push = N'true'
    , @allow_pull = N'true'
    , @allow_anonymous = N'true'
    , @enabled_for_internet = N'false'
    , _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'
    , _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'
GO

EXEC sys.sp_changelogreader_agent @job_login = '<login>'
    , @job_password = '<password>'
    , @publisher_security_mode = 0
    , @publisher_login = N'<login>'
    , @publisher_password = '<password>'
GO

EXEC sp_addpublication_snapshot @publication = N'pub1'
    , @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 = '<login>'
    , @job_password = '<password>'
    , @publisher_security_mode = 0
    , @publisher_login = N'<login>'
    , @publisher_password = '<password>'
GO

EXEC sp_addarticle @publication = N'pub1'
    , @article = N'table1'
    , @source_owner = N'dbo'
    , @source_object = N'table1'
    , @type = N'logbased'
    , @description = N''
    , @creation_script = N''
    , @pre_creation_cmd = N'drop'
    , @schema_option = 0x00000000080350DF
    , @identityrangemanagementoption = N'none'
    , @destination_table = N'table1'
    , @destination_owner = N'dbo'
    , @status = 24
    , @vertical_partition = N'false'
    , @ins_cmd = N'CALL [sp_MSins_dbotable1]'
    , @del_cmd = N'CALL [sp_MSdel_dbotable1]'
    , @upd_cmd = N'SCALL [sp_MSupd_dbotable1]'
GO

EXEC sp_startpublication_snapshot @publication = N'pub1';
GO

 

 

 

 

Looking at the results of MSlogreader_history table, all changes are being replicated, however there are many runstatus = 6, which means failure.

 

 

  • This issue has been resolved - the issue is I was dropping/re-creating via scripts in our non-prod environment. When doing cleanup, I did not remove the replication Sql Agent jobs, so I had about 20 log reader agent jobs running. Once I removed all the obsolete jobs, it worked as expected.

1 Reply

  • gyvkoff's avatar
    gyvkoff
    Brass Contributor
    This issue has been resolved - the issue is I was dropping/re-creating via scripts in our non-prod environment. When doing cleanup, I did not remove the replication Sql Agent jobs, so I had about 20 log reader agent jobs running. Once I removed all the obsolete jobs, it worked as expected.

Resources