<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Edwin M SarmientoFixing PRIMARY KEY constraint issues in SQL Server 2005 Replication &#8211; Edwin M Sarmiento</title>
	<atom:link href="https://www.edwinmsarmiento.com/fixing-primary-key-constraint-issues-in-sql-server-2005-replication/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.edwinmsarmiento.com</link>
	<description>Intentional Excellence</description>
	<lastBuildDate>Mon, 13 Apr 2026 21:00:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">84283043</site>		<item>
		<title>Fixing PRIMARY KEY constraint issues in SQL Server 2005 Replication</title>
		<link>https://www.edwinmsarmiento.com/fixing-primary-key-constraint-issues-in-sql-server-2005-replication/</link>
		<comments>https://www.edwinmsarmiento.com/fixing-primary-key-constraint-issues-in-sql-server-2005-replication/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 23:07:00 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[SQL Server 2005 Replication]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/2009/01/06/fixing-primary-key-constraint-issues-in-sql-server-2005-replication</guid>

				<description><![CDATA[I must admit that I had to stay away from replication for quite a while since most of the work I&#8217;ve done in my previous job has a lot to do with disaster recovery. Nonetheless, I&#8217;m presented with new challenges every single day which I need to face. I got notified for an error regarding [&#8230;]]]></description>
					<content:encoded><![CDATA[<p><span style="font-family:arial;">I must admit that I had to stay away from replication for quite a while since most of the work I&#8217;ve done in my previous job has a lot to do with disaster recovery. Nonetheless, I&#8217;m presented with new challenges every single day which I need to face. I got notified for an error regarding a transactional replication issue between two SQL Server 2005 instances. The error went something like this</span></p>
<p><span style="font-family:trebuchet ms;font-size:85%;color:#cc0000;"><em><strong>Replication-Replication Distribution Subsystem: agent INSTANCE-db-Publication-SUBSCRIBER_INSTANCE-21 failed. Violation of PRIMARY KEY constraint &#8216;PK_Whatever&#8217;. Cannot insert duplicate key in object &#8216;dbo.table1&#8217;</strong></em></span></p>
<p><span style="font-family:arial;">The error message simply says that replication between the publisher and the subscriber could not push thru due to an existing record in the subscription that is causing a violation of the PRIMARY KEY constraint. Either a record is manually inserted in the subscriber or its just an annoying application which is not properly configured. Here&#8217;s how you can fix this</span></p>
<ol>
<ol>
<li><span style="font-family:Arial;">Open Replication Monitor and check for the publication that is causing the error. You should see some error messages in the details that display something about the transaction sequence number, publisher id and command id values </span></li>
<li><span style="font-family:Arial;">Next, you retrieve the command associated with the transaction sequence number using the system stored procedure <a href="http://msdn.microsoft.com/en-us/library/ms176109(SQL.90).aspx">sp_browsereplcmds</a>. This will return a result set of the replicated commands stored in the Distribution database at the Distributor. The query should look something like this </span></li>
</ol>
</ol>
<p><span style="font-family:lucida grande;font-size:85%;color:#cc0000;"><em><strong>EXEC Distribution..sp_browsereplcmds @xact_seqno_start = &#8216;0x000B5103000043B7000700000000&#8217; ,@xact_seqno_end = &#8216;0x000B5103000043B7000700000000&#8217;,@command_id =2 , @publisher_database_id = 1</strong></em></span><br />
<span style="font-family:arial;">This will give you an idea on the possible INSERT/UPDATE/DELETE statement that is inside this transaction. Based on the error message, we are looking at either an INSERT or an UPDATE statement.</span></p>
<ul>
<li><span style="font-family:Arial;">Next, run a SELECT query on the subscriber instance against the table specified in the subscription passing the values you retrieved from the <strong><span style="font-size:85%;">sp_browsereplcmds</span></strong> system stored procedure. </span></li>
<li><span style="font-family:arial;">If the record already exists, simply delete the record since it will be written over by the replication (of course, this is not always the case and would depend on your business requirements)</span></li>
</ul>
<p>&nbsp;</p>
<p><span style="font-family:Arial;">This is just an overview of what you can do when you see such errors in replication. There are a few more articles and tips to help you get by from this <a href="http://www.replicationanswers.com/default.asp">website</a> by Paul Ibison</span></p>
<div class="blogger-post-footer"><img decoding="async" src="https://blogger.googleusercontent.com/tracker/92377218009570869-3490343680557734416?l=bassplayerdoc.blogspot.com" alt="" width="1" height="1" /></div>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/fixing-primary-key-constraint-issues-in-sql-server-2005-replication/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">148</post-id>	</item>
	</channel>
</rss>