The process could not execute ‘sp_repldone/sp_replcounters’

Share this Post

Anurag Sharma | Microsoft SQL Server Escalation Services

Log Reader fails with below error message

The process could not execute ‘sp_repldone/sp_replcounters’ on ‘SQLGUY’. (Source: MSSQL_REPL, Error number: MSSQL_REPL20011)
Get help:
The log scan number (23:49:3) passed to log scan in database ‘PUBLISHER’ is not valid. This error may indicate data corruption or that the log file (.ldf) does not match the data file (.mdf). If this error occurred during replication, re-create the publication. Otherwise, restore from backup if the problem results in a failure during startup.  (Source: MSSQLServer, Error number: 9003)
Get help:
The process could not set the last distributed transaction. (Source: MSSQL_REPL, Error number: MSSQL_REPL22017)
Get help:
The process could not execute ‘sp_repldone/sp_replcounters’ on ‘SQLGUY’. (Source: MSSQL_REPL, Error number: MSSQL_REPL22037)
Get help:

Common Causes
  1. The last LSN in Transaction Log is less than what the LSN Log Reader is trying to find. An old backup may have been restored on top of Published Database. After the restore, the new Transaction Log doesn’t contain the data now distributor & subscriber(s) have.
  2. Database corruption.
How to fix this
  1. Ensure database consistency by running DBCC CHECKDB on the database.
  2. If an old backup was restored on top of published database then use sp_replrestartIf going back to the most recent transaction log backup is not an option then execute sp_replrestart  on publisher in published database. This stored procedure is used when the highest log sequence number (LSN) value at the Distributor does match the highest LSN value at the Publisher.

    This stored procedure will insert compensating LSNs (No Operation) in the publisher database log file till one the compensating LSN becomes more than the highest distributed LSN in distribution database for this published database. After this it inserts this new high LSN in the msrepl_transactions table in the distribution database and executes sp_repldone on published database to update the internal structures to mark a new starting point for log reader agent.

    Ensure that the log reader agent is stopped and there is no incoming transactions on the published database, when this SP is executed.

  3. Since transactions may have been lost, we recommend to reinitialize the subscriber(s) and/or recreate publication/subscription(s).  For large databases consider using “Initialize from Backup” as discussed in SQL Book Online.
How to prevent this issue in future

Use sync with backup option in SQL Server.

Share this Post

About: ReplTalk

4 thoughts on “The process could not execute ‘sp_repldone/sp_replcounters’”

  1. I had a similar issue but in my case it was the distribution database that became corrupted, not the database I wanted to replicate.

  2. for any accidental DBAs that find this…it works. If you say moved a log file while repl was running you might think the log file is corrupt. if dbcc checkdb is good then do not rebuild the log files! this works!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.