0% found this document useful (0 votes)
154 views4 pages

Transaction Replication - Violation of PRIMARY

This document discusses troubleshooting a violation of a primary key constraint error that occurred during transactional replication. The error was caused by a duplicate value being inserted on the subscriber that did not match the value on the publisher. The solution involved using the sequence number from the error and a stored procedure to identify the problematic command. The row on the subscriber with the duplicate value was then deleted to resolve the conflict and allow replication to proceed.

Uploaded by

hanuman sqlboy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
154 views4 pages

Transaction Replication - Violation of PRIMARY

This document discusses troubleshooting a violation of a primary key constraint error that occurred during transactional replication. The error was caused by a duplicate value being inserted on the subscriber that did not match the value on the publisher. The solution involved using the sequence number from the error and a stored procedure to identify the problematic command. The row on the subscriber with the duplicate value was then deleted to resolve the conflict and allow replication to proceed.

Uploaded by

hanuman sqlboy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL Notes From

The Underground Transaction Replication –


Violation of PRIMARY
SQL Links
KEY constraint
Posted by staggerlee011 on July 8, 2015 in Transactional Replication,
About Me
Troubleshooting | Leave a comment
Curah

We ran into an issue in our pre-prod environment last week where transnational replication
Categories wasn’t processing any data changes from publisher to subscriber.

70-461 (1) Looking at Replication monitor we had a error similar to this:


@Local_Variables (1)

Active Directory (3)

Alias's (1)

Atlassian (3)

Attach DB (1)

AWS (1)

AWS RDS (1)


Command attempted:
Backup & Restore (14) if @@trancount > 0 rollback tran
BCP (1) (Transaction sequence number: 0x00000024000002F0000400000000, Command ID: 1)
Error messages:
BIDS (2)
Violation of PRIMARY KEY constraint ‘PK__t1__3213E83FBA2CFEA2’. Cannot insert duplicate
BIDS Helper (1) key in object ‘dbo.t1’. The duplicate key value is (3). (Source: MSSQLServer, Error number:
BitBucket Server (3) 2627)
Get help: http://help/2627
BPOTW (81)
Violation of PRIMARY KEY constraint ‘PK__t1__3213E83FBA2CFEA2’. Cannot insert duplicate
By Example (19) key in object ‘dbo.t1’. The duplicate key value is (3). (Source: MSSQLServer, Error number:
Central Management Server 2627)
(8) Get help: http://help/2627

CHECKDB (7)

Code (1)  

Codecademy (1) and you can see the outstanding commads in the “Undistributed Commands”

CodePlex (1)

Collations (1)

Con២�guration (3)

Curah (7)

Daily Dashboard (5)

Data Quality Services (1)


 
Database Design Series (2)
The problem is that a table on the subscriber has been updated or inserted into data that
Database Lifecycle con២�icts with what the publisher has. the ២�x is pretty simple.
Management (DLM) (3)
First copy the seq_no from the error and paste it into the below query
DBA Gamei២�cation (2)
1 /* Copy the seq_no from Replication Monitor  */
DBATools (1) 2 ‐‐ 0x00000024000002F0000400000000
3  
DBCC (1) 4 /* QUERY 1 */
5 /* Gather information on Primary Key constraint error */
DHCP (1) 6 SELECT  art.publisher_id ,
7         art.publisher_db ,
Disaster Recovery (2) 8         art.publication_id ,
9         art.article ,
Download (11) 10         art.article_id  ,
11         art.destination_object  ,
Enterprise Policy 12         art.source_owner  ,
13         art.source_object 
Management Framework (8) 14 FROM    distribution.dbo.MSarticles AS art
15         JOIN distribution.dbo.MSrepl_commands AS com 
Error Log (3) 16         ON art.Article_id = com.Article_id
17 WHERE   com.xact_seqno = 0x00000024000002F0000400000000
Event Viewer (1) 18  
19  
Exams (2) 20 </pre>
21 <pre>
Excel (11)
Which results in:
Extended Events (2)

Extended Property (1)

Frameworks (2)

GIT (2)

GitHub (3)

GPO (1)
From this we can get the rest of the information we need to run sp_browsereplcmds. 
High Availability (1)
1 </pre>
HTML / CSS (1)
2 <pre>/* Populate with details from Query 1*/
3 EXEC distribution.dbo.sp_browsereplcmds 
Import Export Wizard (1) 4      @xact_seqno_start = '0x00000024000002F0000400000000' ,
5      @xact_seqno_end = '0x00000024000002F0000400000000' , 
Indexes (1) 6      @publisher_database_id = 1 , 
7      @article_id = 1 , 
Installs and Patching (5) 8      @command_id = 1 

Instance Maintenance (2) This returns what we need to resolve the issue

Instant File Initialization (2)

Jenkins (5)

Kerberos (3)
The Command Column
Least Privilage (5)

Linked Server (1)

Log Shipping (2) {CALL [sp_MSins_dbot1] (3,’insert pub’)}

MAPT (1)

Marked Transacion (1)  

MDW (1) From here we can query the subscriber table and delete the row with ID 3 that has data not
matching the publisher.  (In my test example you can see i manually entered a record called
Monitoring (1)
“insert sub” with an ID 3 into the subscriber, which con២�icts with the publisher row which is ID
MSDB (3) 3 data “insert pub”.

NUnit (1)

Octopus Deploy (1)

Outlook (4)

Pester (3)
So to resolve the issue we simply need to delete the the subscriber row
Podcasts (1)

Policy Based Management 1 USE repSub


2 GO
(9) 3  
4 DELETE FROM t1
PowerShell (57) 5 WHERE id = 3
PowerShell Desired State
Con២�guration (DSC) (1)

Pro២�ler (2)
After deleting the row, you just need to wait for replication to sync, and you will see
PsExec (1)
the “Undistributed Commands” go down to 0 again and the “Distributor To Subscriber History”
PSInfo (1) should show it as Running.

RedGate (1)

Replication (4)

Roles (1)

Scheduled Task (1)

Schema (1)

Script (2)

Security (9)

Server Side Trace (2)

Service Broker (1)

Severity (1)

SharePoint (4)
Advertisements
SharePoint Designer 2013
(1)

SharePoint Online (1)

shrink២�le (1)

Slack (2)

Source Control (1)

sp_attach_single_២�le_db (1)

sp_help_revlogin (1)

SQL Agent (10)

SQL Community (6)


Share this:
SQL Events (2)

SQL Nexus (1)  Twitter  Facebook

SQL Server (19)


 Like
SQL Server 2005 (1) Be the first to like this.

SQL Server Alerts (1)


Related
SQL Server Upgrade (1)

SQL Server Version (4) Table Variables vs Temp By Example : Transactional Transaction Log File is ២�lling
Tables Replication Sync with up on a database with
SQLBits (1) In "Table Variables" Backup log_reuse_wait_desc set to
In "By Example" replication
sqlcmd (2)
In "Replication"
sqlps (2)

SQLPX (1)

SQLSaturday (1)

sqlserverbuilds.blogspot.co.uk Transactional Replication Troubleshooting


(4)
SSDT-BI (2)

SSIS (8)

SSIS Reporting Pack (1)


← BPOTW 2015-07-03 BPOTW 2015-07-10 →
SSMS (10)

SSRS (13)

Suspect Mode (1)

SysInternals (2)

T-SQL (23)

Leave a Reply
Table Variables (1)

Team Foundation Server (1)

Temp Tables (1)


Enter your comment here...
TempDB (2)

Tips and Tricks (71)

Transactional Replication (3)

Transparent Data
Encryption (1)

Troubleshooting (10)
Blog at WordPress.com.
Troubleshooting Tools (1)

Undocumented SQL Stored


Procedures (1)

Unit Test (2)

Users (1)

Using Excel VBA to Export


SQL Data Series (3)

VBA (3)

Visual Studio (3)

Windows OS (3)

XML (2)

xp_cmdshell (3)

Year in Review (2)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy