简体   繁体   中英

MS SQL Transactional Replication - Skipping Error while applying snapshot at the subscriber

I tried finding this on the internet but could not find anything regarding it. There are ways to skip errors in the Distribution agent but nothing with respect to skipping Errors while applying Snapshot.

My Question: I have a Multi Publisher Single Subscriber setup. While setting up replication, the Snapshot of the first Publisher is successfully delivered to the subscriber. The snapshot of the consecutive Publishers is successfully generated but fails while applying it to the subscriber. The failure is due to Primary Key violation . Is there a way to skip errors while the snapshot is being applied on the subscriber?

Environment:

  • Publisher: Microsoft SQL Server 2008 R2 (SP2) - (X64)
  • Distributor: Microsoft SQL Server 2014 (SP2) (KB3171021) - (X64)
  • Subscriber: Microsoft SQL Server 2008 R2 (SP3-OD) (KB3144114) - (X64)

I have tried identifying the tables and records which are causing this issue but there are over 100 such tables having hundreds of records each.

Since replication is a client requirement, I don't have much control over the schema and the data in it.

It sounds like something in your setup is incorrect, which is leading to multiple tables from different publishers trying to insert rows into the same subscriber table, hence the duplicate key records.

If the different publishers all have the same copy of the same table, you only want to publish it from one of them.

If the different publishers all have different copies of the same table, you want them to each have their own subscriber tables.

Otherwise you'll end up missing a lot of rows in your subscriber (because different publishers are using the same key for rows that are actually different) or hitting weird replication errors. Just skipping the errors would result in having incorrect data-- and I'm guessing that's one of the client requirements as well.

One option that I have used in the past to simplify replication topography and management:

  • One subscriber database per publication
  • Never grant write access to users to these databases
  • Grant read access via another database which uses synonyms or views

This can make management simpler down the road as well. If you need to re-initialize a single database, you have the option to restore it from backup and generally more flexibility than if your subscribers are all sharing the same database.

Just for completeness, I should probably point you to the Books Online entry from Skipping Errors in Transactional Replication . But to be clear, I think this would be a mistake, as you'd end up with incorrect data -- and that's probably not what anyone wants.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM