How to troubleshoot error 20598 "The row was not found at the Subscriber when applying the replicated command"

Applies to: Microsoft SQL Server 2005 Developer EditionMicrosoft SQL Server 2005 Enterprise EditionMicrosoft SQL Server 2005 Standard Edition More

This article describes how to troubleshoot error 20598 "The row was not found at the Subscriber when applying the replicated command" in transactional replication.

How to troubleshoot

To troubleshoot this issue, following these steps:
  1. In the replication monitor on the Distribution Agent for the subscriber, extract the transaction sequence number and command ID that encountered the error:

    Error Message

    Note You can obtain the same transaction sequence number from the distributor server by using the following query:

    Get error message from query
  2. Extract the commands that map to the transaction sequence number on the distributor server. Use the transaction sequence number from step 1 as the parameter for this command:

    Get the command
  3. From the output of step 2, identify the command that is failing by using the command ID from step 1. Refer to the command_id column in the result set.
  4. Validate the article information on the publisher. Use the article ID that you obtain from step 2, and check the details of the article that you are trying to update:

    Check the details
  5. Validate the primary key on the publisher.

    You have two pieces of information: the table on which you are trying to perform the update, and the primary key value. You can query the table by using the primary key value, and locate the row on the publisher database. For example:
    SELECT * FROM tbl_sample WHERE column_name = <primary_key_value>
  6. Check the problem at the subscriber.

    Execute the same query on the subscriber database, and compare it to the result that you receive from the publisher database.

Workaround


To work around this issue, use the following two methods:
  • Manually insert the missing row at the subscriber. This may enable the Distribution Agent to retry the failed command and move forward with the replication. 

    Note There may be other rows that are missing and that have to be manually inserted at the subscriber if there are more failures.
  • Instruct the Distribution Agent to skip this error and continue to replicate the rest of the changes. The Distribution Agent accepts the skiperrors parameter. You can use this parameter to pass error code 20598. This may keep the replication setup intact while you wait for an opportunity to manually synchronize the missing rows.

    Note You have to carefully evaluate the downstream effects of referential integrity and the triggers that are present on the affected table before you continue.

More Information


Data collection to investigate the cause of this issue

If this problem occurs repeatedly, you should collect the following data for analysis by the Microsoft SQL Server support team so that they can try to identify the cause of the problem:
  • The backup of the distribution database when this problem occurs. (This should be after the error is reported and before the subscription is reinitialized.)
  • Transaction log backups of the publisher and the subscriber. (These should be for at least the 24 hours that led up to the time of the problem.)
  • Profiler traces that show the activity of the replication agents on the publisher, the subscriber, and the distributor. (Please make sure that the profiler is running even before the problem starts. Ideally, you want to start the profiler around the same time as the reindex job start time.)
  • Outputs from the previous five steps for identifying the affected table and the primary key value that is missing
  • Output of the catalog views from both the publisher and the subscriber databases:
    • sys.partitions 
    • sys.allocation_units 
    • sys.objects
  • Verbose outputs of replication agent logs

Known issues that are addressed

The following problems occur in older versions of SQL Server:

Status


Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

References