Recently I faced very interesting scenario where for a database both change data capture and transactional replication was enabled. As per MS documentation, both features can work together but we need to keep few things in mind while implementing both features together on a database.
Coming to my case, although change data capture job was running successfully but transactional replication’s log reader agent job was going into retry with below error messages.
2021-08-20 10:17:57.073 Status: 0, code: 20011, text: 'The process could not execute 'sp_repldone/sp_replcounters' on 'ServerName'.'.
2021-08-20 10:17:57.073 The process could not execute 'sp_repldone/sp_replcounters' on 'ServerName'.
2021-08-20 10:17:57.073 Status: 0, code: 22903, text: 'Another connection is already running 'sp_replcmds' for Change Data Capture in the current database.'.
2021-08-20 10:17:57.073 Status: 0, code: 22017, text: 'The process could not set the last distributed transaction.'.
2021-08-20 10:17:57.073 Status: 0, code: 22037, text: 'The process could not execute 'sp_repldone/sp_replcounters' on 'ServerName'.'.
As per MS documentation, ” When both features are enabled on the same database, the Log Reader Agent calls sp_replcmds. This agent populates both the change tables and the distribution database tables.” In other words, log reader agent job is responsible for both transactional replication and change data capture and separate CDC capture job is not required.
Solution was to delete “cdc.DatabaseName_capture” job and let log reader agent populate CDC tables.
Here one point is worth to mention that in this case log reader agent was running on remote distributor server and not on local distributor which allowed both CDC capture job and log reader agent job to be created else SQL server does not allow both jobs to be created on same server else SQL does not allow both log reader agent job and CDC capture job to be created on same server for same database.
Will write another article to explain above scenario.
Hope this information helps you!!
Happy Learning!!