Search code examples
sql-servertransactional-replicationazure-sql-managed-instance

Cannot get Log Reader Agent to run 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

Here is the output of MSlogreader_history table:

enter image description here

This is the command I used to add the log reader agent:

EXEC sys.sp_addlogreader_agent @job_login = '<login1>', @job_password = '<pwd>', @publisher_security_mode = 0, @publisher_login = N'<login1>', @publisher_password = '<pwd>'

Where <login1> is a Sql user with sysadmin privs.

I even addded -OutputVerboseLevel 2 to the log reader agent properties, but the output did not change.

Here is replmonitor :

enter image description here

Full tsql script used:

USE master
GO

EXEC sp_adddistributor @distributor = @@SERVERNAME, @password = NULL
GO
EXEC sp_adddistributiondb @database = N'distribution'
    , @min_distretention = 0
    , @max_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'
    , @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'
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

Solution

  • 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 associated with the publication, so I had about 20 old log reader agent jobs existing/running. Once I removed all the obsolete jobs, it worked as expected.