10

I have transactional replication running between two databases. I fear they have fallen slightly out of sync, but I don't know which records are affected. If I knew, I could fix it manually on the subscriber side.

SQL Server is giving me this message:

The row was not found at the Subscriber when applying the replicated command. (Source: MSSQLServer, Error number: 20598)

I've looked around to try to find out what table, or even better what record is causing the issue, but I can't find that information anywhere.

The most detailed data I've found so far is:

Transaction sequence number: 0x0003BB0E000001DF000600000000, Command ID: 1

But how do I find the table and row from that? Any ideas?

8 Answers 8

11

This gives you the table the error is against

use distribution
go

select * from dbo.MSarticles
where article_id in (
    select article_id from MSrepl_commands
    where xact_seqno = 0x0003BB0E000001DF000600000000)

And this will give you the command (and the primary key (ie the row) the command was executing against)

exec sp_browsereplcmds 
@xact_seqno_start = '0x0003BB0E000001DF000600000000', 
@xact_seqno_end = '0x0003BB0E000001DF000600000000'
9

I'll answer my own question with a workaround I ended up using.

Unfortunately, I could not figure out which table was causing the issue through the SQL Server replication interface (or the Event Log for that matter). It just didn't say.

So the next thing I thought of was, "What if I could get replication to continue even though there is an error?" And lo and behold, there is a way. In fact, it's easy. There is a special Distribution Agent profile called "Continue on data consistency errors." If you enable that, then these types of errors will just be logged and passed on by. Once it is through applying the transactions and potentially logging the errors (I only encountered two), then you can go back and use RedGate SQL Data Compare (or some other tool) to compare your two databases, make any corrections to the subscriber and then start replication running again.

Keep in mind, for this to work, your publication database will need to be "quiet" during the part of the process where you diff and fix the subscriber database. Luckily, I had that luxury in this case.

1
  • 2
    To do this through SSMS right-click on Replication -> Distributor Properties. Then click on Profile Defaults. You can create a new profile with the -SkipErrors value. Or just check "Continue on data consistency errors." and select Change Existing Agents.
    – Trevor
    Dec 21, 2013 at 2:49
3

If your database is not prohibitively large, I would stop replication, re-snapshot and then re-start replication. This technet article describes the steps.

If it got out of sync due to a user accidently changing data on the replica, I would set the necessary permissions to prevent this.

This replication article is worth reading.

3
  • Yeah, I'm trying to avoid that since the tables are really large. We'll see if I have to end up going there.
    – jeremcc
    Feb 19, 2009 at 23:03
  • Do you have the RedGate Data Compare tool? (it has a 14 day trial) That would at least let you find the rows quickly. Feb 19, 2009 at 23:16
  • Yep, that's exactly what I'm using. :-) The problem is that the current diff tells me x rows are missing (since replication is lagging), but I don't know which one is the culprit. I think I've found the workaround though. It has to do with a "SkipErrors" flag on the distributor. I'll post it soon.
    – jeremcc
    Feb 19, 2009 at 23:19
1

Use this query to find out the article that is out of sync:

USE [distribution]

select * from dbo . MSarticles 
where article_id IN ( SELECT Article_id from MSrepl_commands 
where xact_seqno = 0x0003BB0E000001DF000600000000)
0

of course if you check the error when the replication fails it also tells you which record is at fault and you could extract that data from the core system and just insert it on the subscriber.

This is better than skipping errors as with the SQL Data Compare it will lock the table for the comparison and if you have millions of rows this can take a long time to run.

Tris

0

Changing the profile to "Continue on data consistency errors" won't always work. Obviously it reduces or nullifies an error, but you won't get the whole proper data. It will skip the rows by which an error occurs, and hence you fail to get accurate data.

0

the following checks resolve my problem

  • check that all the replication SQL Agents jobs are working fine and if not start them.
    • in my case it was stopped because of some killed session occurred a few hours before by Some DBA because of blocking issue
  • after a very short time all data in subscription were updated and no other error in replication monitor
  • in my case all above queries did not returned nothing
0

This error usually comes when particular record does not exists on subscriber and a update or delete command executed for same record on primary server and which got replicated on subscriber as well.

As this records does not exists on subscriber, replication throws an error " Row Not Found"

Solution of this error to make replication work back to the normal running state:

We can check with following query, whether request at publisher was of update or delete statement:

USE [distribution]

SELECT *
FROM   msrepl_commands 
WHERE  publisher_database_id = 1
       AND command_id = 1
       AND xact_seqno = 0x00099979000038D6000100000000

We can get artical id information from above query, which can be passed to below proc:

EXEC Sp_browsereplcmds
  @article_id = 813,
  @command_id = 1,
  @xact_seqno_start = '0x00099979000038D60001',
  @xact_seqno_end = '0x00099979000038D60001',
  @publisher_database_id = 1

Above query will give information about, whether it was a update statement or delete statement.

  1. In Case of Delete Statement

That record can be directly deleted from msrepl_commands objects so that replication wont make retry attempts for the record

DELETE FROM msrepl_commands
WHERE  publisher_database_id = 1
       AND command_id =1
       AND xact_seqno = 0x00099979000038D6000100000000 
  1. In case of update statement:

You need to insert that record manually from publisher DB to subscriber DB:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.