<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>REPLTalk covers Using and Tuning SQL Replication</title><link>http://blogs.msdn.com/b/repltalk/</link><description /><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>Cannot Replicate “Stored Procedure Execution” when CDC is Enabled</title><link>http://blogs.msdn.com/b/repltalk/archive/2013/04/28/cannot-replicate-stored-procedure-execution-when-cdc-is-enabled.aspx</link><pubDate>Sun, 28 Apr 2013 22:22:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10414623</guid><dc:creator>ReplTalk</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/repltalk/rsscomments.aspx?WeblogPostID=10414623</wfw:commentRss><comments>http://blogs.msdn.com/b/repltalk/archive/2013/04/28/cannot-replicate-stored-procedure-execution-when-cdc-is-enabled.aspx#comments</comments><description>&lt;h1&gt;Cannot Replicate “Stored Procedure Execution” when CDC is Enabled&lt;/h1&gt;  &lt;p&gt; Taiyebali Zakir&lt;b&gt; | &lt;/b&gt;Support Escalation Engineer&lt;b&gt; |&lt;/b&gt; MS SQL Server CTS&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Replicate Execution of Stored Procedure and CDC:   &lt;br /&gt;=====================================&lt;/p&gt;  &lt;p&gt;With Transactional Replication you can replicatethe&amp;#160; execution of the Stored Procedure like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/6177.clip_5F00_image001_5F00_38901EB9.jpg"&gt;&lt;img title="clip_image001" style="display: inline; background-image: none;" border="0" alt="clip_image001" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/2330.clip_5F00_image001_5F00_thumb_5F00_4C3D084D.jpg" width="563" height="307" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This has several advantages as discussed in this article: &lt;a href="http://msdn.microsoft.com/en-us/library/ms152754.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms152754.aspx&lt;/a&gt; . &lt;/p&gt;  &lt;p&gt;When you enable Change Data Capture (CDC) at the Database level, replication of the stored procedure execution will NOT work. This is By Design. Change Data Capture (CDC) does not support tracking at stored procedure execution level, which means individual rows logged by stored procedure execution need to be flagged with REPLICATE bit, which makes it impossible for Transactional Replication to replicate only the stored procedure execution.&amp;#160; As a result, ‘stored proc execution’ will work only when Transactional Replication is enabled and CDC is not enabled. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10414623" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/CDC/">CDC</category></item><item><title>Exploration into “Row was not found”</title><link>http://blogs.msdn.com/b/repltalk/archive/2013/01/16/exploration-into-row-was-not-found.aspx</link><pubDate>Wed, 16 Jan 2013 19:16:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10385639</guid><dc:creator>ReplTalk</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/repltalk/rsscomments.aspx?WeblogPostID=10385639</wfw:commentRss><comments>http://blogs.msdn.com/b/repltalk/archive/2013/01/16/exploration-into-row-was-not-found.aspx#comments</comments><description>&lt;h1&gt;Exploration into “Row was not found”&lt;/h1&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Chris Skorlinski   &lt;br /&gt;Microsoft SQL Server Escalation Services.&lt;/p&gt;  &lt;p&gt;“The row was not found at the Subscriber when applying the replicated command.” errors reported by the SQL Replication Distribution Agent can often be some of the hardest issues to troubleshoot.&amp;#160; With great satisfaction I was able to uncover this mysterious error for one of my customers. &lt;/p&gt;  &lt;p&gt;In the customers SQL Replication topology they’re consolidating 2 databases from a single Publisher into 1 database on the Subscriber.&amp;#160; The published tables going into different “schema” or groups on the Subscriber.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Database A, Publication A into Subscriber schema A.{table}     &lt;br /&gt;Database B, Publication B into Subscriber schema B.{table}&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;They subscriber tables are unique only by the “schema” or group name.&amp;#160; For this topology, (2 into 1) is possible, however, to make this work “special” handling is required or Distribution Agents will fail with “missing data” and/or “invalid data” in the Subscriber.&amp;#160; &lt;/p&gt;  &lt;h2&gt;Here is why:&lt;/h2&gt;  &lt;p&gt;By default SQL Server Replication creates stored procedures on the subscriber to update the subscriber tables.&amp;#160; In my example I’m replicating the CUSTOMER table.&amp;#160; The default stored procedure created by Replication to update the subscriber is called [dbo].[sp_MSupd_dboCustomer]. As you can see there is no A or B schema naming.&amp;#160; Therefore each publication will use the same stored procedure name on the subscriber, however, the whichever stored procedure is created LAST will get ALL of the data changes.&amp;#160; &lt;/p&gt;  &lt;p&gt;If I first create A publication, the stored procedure [dbo].[sp_MSupd_dboCustomer] updates&amp;#160; [A].[Customer] table.&amp;#160; Next if I create the B publication and push to the same subscriber database, the stored procedure created by B publication is created with the same name as A publication, over writing the A stored procedure.&amp;#160; As result &lt;b&gt;ALL&lt;/b&gt;, yes &lt;b&gt;ALL&lt;/b&gt; changes from both A and B are routed to the [B].[Customer] table.&amp;#160; Not only is A missing inserts, those inserts are being apply to B.Customer table.&lt;/p&gt;  &lt;p&gt;create procedure [dbo].[sp_MSupd_dboCustomer]   &lt;br /&gt;update &lt;b&gt;[A]&lt;/b&gt;&lt;b&gt;.&lt;/b&gt;&lt;b&gt;[&lt;/b&gt;Customer] set    &lt;br /&gt;where [CustomerID] = @pkc1&lt;/p&gt;  &lt;p&gt;create procedure [dbo].[sp_MSupd_dboCustomer]   &lt;br /&gt;update &lt;b&gt;[B]&lt;/b&gt;.[Customer] set    &lt;br /&gt;where [CustomerID] = @pkc1&lt;/p&gt;  &lt;h2&gt;&lt;b&gt;Solution&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;/h2&gt;  &lt;p&gt;To correct this problem ALL publications need to be DROPPED and re-created with their own UNIQUE stored procedures on the subscriber.&amp;#160; You can accomplish this via the Replication Wizard by editing the “INS/UPD/DEL stored procedure” names under the “Statement Delivery”.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/3365.image_5F00_7A503E12.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/0726.image_5F00_thumb_5F00_64A5DFA8.png" width="345" height="302" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Or by modifying the CREATE PUBLICATION script, then sp_addarticle command to specify a unique name for each of the INS, DEL, and UPD commands.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/1778.clip_5F00_image004_5F00_27550514.jpg"&gt;&lt;img style="display: inline; background-image: none;" title="clip_image004" border="0" alt="clip_image004" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/8228.clip_5F00_image004_5F00_thumb_5F00_7D918A20.jpg" width="336" height="174" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;-- Adding the transactional articles (Publication A)&lt;/p&gt;  &lt;p&gt;exec sp_addarticle @publication = N'A', @article = N'Customer', … , @ins_cmd = N'CALL [sp_MSins_A_Customer]', @del_cmd = N'CALL [sp_MSdel_A_Customer]', @upd_cmd = N'SCALL [sp_MSupd_A_Customer]'&lt;/p&gt;  &lt;p&gt;GO&lt;/p&gt;  &lt;p&gt;-- Adding the transactional articles (Publication B)&lt;/p&gt;  &lt;p&gt;exec sp_addarticle @publication = N'B', @article = N'Customer', … , @ins_cmd = N'CALL [sp_MSins_B_Customer]', @del_cmd = N'CALL [sp_MSdel_B_Customer]', @upd_cmd = N'SCALL [sp_MSupd_B_Customer]'&lt;/p&gt;  &lt;p&gt;GO&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;After these changes 2 stored procedures for updating the subscriber tables will be created, one from each publication updating only that publications data.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10385639" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/Distributor/">Distributor</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/Replication/">Replication</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/ReplTalk/">ReplTalk</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/Best+Practices/">Best Practices</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/SQL+Agent/">SQL Agent</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/Features/">Features</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/Error/">Error</category></item><item><title>Notes on Log Reader Parameters MaxCmdsInTran and ReadBatchSize</title><link>http://blogs.msdn.com/b/repltalk/archive/2012/10/08/notes-on-log-reader-parameters-maxcmdsintran-and-readbatchsize.aspx</link><pubDate>Mon, 08 Oct 2012 18:37:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10357454</guid><dc:creator>ReplTalk</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/repltalk/rsscomments.aspx?WeblogPostID=10357454</wfw:commentRss><comments>http://blogs.msdn.com/b/repltalk/archive/2012/10/08/notes-on-log-reader-parameters-maxcmdsintran-and-readbatchsize.aspx#comments</comments><description>&lt;h1&gt;Notes on Log Reader Parameters MaxCmdsInTran and ReadBatchSize&lt;/h1&gt;  &lt;p&gt;Jose Moreira B. Neto   &lt;br /&gt;Microsoft SQL Server Escalation Services&lt;/p&gt;  &lt;h6&gt;From SQL Server BOL we have:&lt;/h6&gt;  &lt;p&gt;&lt;b&gt;-ReadBatchSize&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Is the maximum number of transactions read out of the transaction log of the publishing database per processing cycle, with a default of 500. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;-MaxCmdsInTran&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Specifies the maximum number of statements grouped into a transaction as the Log Reader writes commands to the distribution database. Using this parameter allows the Log Reader Agent and Distribution Agent to divide large transactions (consisting of many commands) at the Publisher into several smaller transactions when applying commands at the Subscriber. Specifying this parameter can reduce contention at the Distributor and reduce latency between the Publisher and Subscriber. Because the original transaction is applied in smaller units, the Subscriber can access rows of a large logical Publisher transaction prior to the end of the original transaction, breaking strict transactional atomicity. The default is &lt;b&gt;0&lt;/b&gt;, which preserves the transaction boundaries of the Publisher. This parameter does not apply to Oracle Publishers.&lt;/p&gt;  &lt;h6&gt;What you should take into consideration:&lt;/h6&gt;  &lt;p&gt;&lt;b&gt;MaxCmdsInTran&lt;/b&gt; was offered to customers as a way to decrease latency from the publisher to subscriber for very large transactions. It does this by breaking transactional consistency, and breaking up a single large transaction into smaller transactions. You may see poor logreader performance with low settings of MaxCmdsInTran because it causes the logreader to deliver less data into the distribution database per log harvesting “batch”. In other words, there is some fixed overhead cost of delivering a batch, so with respect to throughput, you probably want your batch size to be as large as possible. Lower MaxCmdsInTran values will increase latency. &lt;/p&gt;  &lt;p&gt;A larger batch though can cause blocking, timeouts and increased transaction log size on the subscriber. Many customers work around blocking and deadlocks on the subscriber due to the locks held by the extended transaction when the change is replicated to the subscriber by implementing MaxCmdsInTran.&lt;/p&gt;  &lt;p&gt;MaxCmdsInTran was never designed to be always turned on. It exists in the product to work around cases where someone accidentally performed a large number of DML operations in a single transaction (causing delay in distribution of commands until the entire transaction is in distribution database, locks being held, etc.). If the customer is routinely falling into this situation, they should serious look at their applications and ways to reduce transaction size.&lt;/p&gt;  &lt;p&gt;Irrespective of ReadBatchSize, if you set a low value for MaxCmdsInTran the log reader needs to write small chunks to the distribution db and that will cause latency compared to writing one big chunk at once&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Readbatchsize&lt;/b&gt; determines how many transactions to harvest from the transaction log per processing cycle. &lt;b&gt;MaxCmdsInTran&lt;/b&gt; determines the maximum number of commands on a single transaction, possibly breaking transaction ACID. Suppose readbatch size is 10, and each transaction has 1,000 commands, in this example the log reader will harvest 10,000 commands contained in 10 transactions. These 10,000 commands will be applied to the subscriber as 10 individual transactions. If MaxCmdsInTran is also added to the agent profile and set to 500, there will now be 20 transactions to be applied to the subscriber, each with 500 commands, hence breaking the original transaction scope.&lt;/p&gt;  &lt;h6&gt;Summary&lt;/h6&gt;  &lt;p&gt;I would recommend not using maxcmdsintran at all since it was designed to be used temporarily for a short time in rare cases. If you see logreader going slow, try to modify your app to reduce transaction size, if transaction size is small you can then use ReadBatchSize to speed up the log reader. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10357454" width="1" height="1"&gt;</description></item><item><title>How to show pending Merge Replication changes</title><link>http://blogs.msdn.com/b/repltalk/archive/2012/08/22/how-to-show-pending-merge-replication-changes.aspx</link><pubDate>Wed, 22 Aug 2012 01:10:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10342169</guid><dc:creator>ReplTalk</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/repltalk/rsscomments.aspx?WeblogPostID=10342169</wfw:commentRss><comments>http://blogs.msdn.com/b/repltalk/archive/2012/08/22/how-to-show-pending-merge-replication-changes.aspx#comments</comments><description>&lt;h1&gt;How to show pending Merge Replication changes&lt;/h1&gt;  &lt;p&gt;Jonathan Clark   &lt;br /&gt;Microsoft SQL Server Escalation Services&lt;/p&gt;  &lt;p&gt;SQL Server &lt;a href="http://msdn.microsoft.com/en-us/library/ms186795"&gt;sp_showpendingchanges&lt;/a&gt; is used to determine how many changes need to be moved to a subscriber or uploaded to a publisher.&amp;#160; You can use these steps to “roll your own” and pull similar data.&lt;/p&gt;  &lt;p&gt;To tackle this problem from the meta data can be a bit daunting, but there are some ways to get an idea of how many changes are left for a specific table.&amp;#160; You can combine what you find for all the tables in a publication and get an estimate for how many changes remain to be synchronized.&lt;/p&gt;  &lt;p&gt;If you have multiple publications that you are watching then your first stop will be in the sysMergePublications table.&amp;#160; Query this table to find the pubid of the publication that you want to monitor.&amp;#160; An example would be simply:&amp;#160; select pubid,* from sysmergepublications&lt;/p&gt;  &lt;p&gt;With an output like this&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/6406.clip_5F00_image002_5F00_337584F5.jpg"&gt;&lt;img style="display: inline; background-image: none;" title="clip_image002" border="0" alt="clip_image002" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/2625.clip_5F00_image002_5F00_thumb_5F00_329D1F0B.jpg" width="587" height="36" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next get your list of article nicknames for the publication from the sysMergeArticles table:&amp;#160; select nickname,* from sysmergearticles where pubid = '22C4781D-E6BC-400B-BC27-A4DB70A0D182'&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/1526.clip_5F00_image004_5F00_1FE82554.jpg"&gt;&lt;img style="margin: 0px; display: inline; background-image: none;" title="clip_image004" border="0" alt="clip_image004" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/5417.clip_5F00_image004_5F00_thumb_5F00_0D332B9D.jpg" width="244" height="66" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So now you are ready to count the changes for these articles that still need to be synchronized.&amp;#160; To do this we need to check the progress “watermark” of generations (groups of changes) sent down to the individual subscribers.&amp;#160; We store this watermark in the sysMergeSubscriptions table as the sentgen column.&amp;#160; You could get this using a query like this:&amp;#160; select sentgen, * from sysmergesubscriptions where pubid = '22C4781D-E6BC-400B-BC27-A4DB70A0D182' AND pubid &amp;lt;&amp;gt; subid&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/8475.clip_5F00_image006_5F00_57BA6977.jpg"&gt;&lt;img style="display: inline; background-image: none;" title="clip_image006" border="0" alt="clip_image006" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/5824.clip_5F00_image006_5F00_thumb_5F00_373329C5.jpg" width="292" height="39" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So now you know that for this particular subscriber, the last generation sent was generation #4.&amp;#160; You need to discover how many generations exist in the metadata greater than #4 and how many changes those generations contain.&amp;#160; To do this, you could use a query like this:&lt;/p&gt;  &lt;p&gt;select mc.tablenick, COUNT (*) as changes from MSmerge_contents mc&lt;/p&gt;  &lt;p&gt;where mc.generation &amp;gt; 4 &lt;/p&gt;  &lt;p&gt;group by mc.tablenick&lt;/p&gt;  &lt;p&gt;A few additions to have the current sentgen passed in as a variable and return your actual table names and you end up with something like this:&lt;/p&gt;  &lt;p&gt;declare @sentgen int =&lt;/p&gt;  &lt;p&gt;(select sentgen from sysmergesubscriptions &lt;/p&gt;  &lt;p&gt;where subid = '7E4942FB-A5D4-45CF-AB87-9D5566C1609A')&lt;/p&gt;  &lt;p&gt;select ma.name, COUNT (*) as changes from MSmerge_contents mc&lt;/p&gt;  &lt;p&gt;join sysmergearticles ma on (ma.nickname = mc.tablenick)&lt;/p&gt;  &lt;p&gt;where mc.generation &amp;gt; @sentgen&lt;/p&gt;  &lt;p&gt;group by ma.name&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/4834.clip_5F00_image008_5F00_44993CCB.jpg"&gt;&lt;img style="display: inline; background-image: none;" title="clip_image008" border="0" alt="clip_image008" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/7802.clip_5F00_image008_5F00_thumb_5F00_2411FD19.jpg" width="200" height="85" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This tells you how many changes are remaining to be sent for each individual table to a specific subscriber.&amp;#160; The subscriber was specified by its subid which I got from sysmergesubscriptions.&amp;#160; In this case I have more than 2 million changes for the table named Artists and only 1 change for Table_1.&lt;/p&gt;  &lt;p&gt;Really all you need is the last query, but I thought I’d take you through the data so that it makes sense.&amp;#160; This way you are armed with some information and could potentially modify it or write your own unique query.&amp;#160; &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10342169" width="1" height="1"&gt;</description></item><item><title>Initialization of Merge Replication subscriber fails with primary key violation</title><link>http://blogs.msdn.com/b/repltalk/archive/2012/07/30/initialization-of-merge-replication-subscriber-fails-with-primary-key-violation.aspx</link><pubDate>Mon, 30 Jul 2012 23:04:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10334972</guid><dc:creator>ReplTalk</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/repltalk/rsscomments.aspx?WeblogPostID=10334972</wfw:commentRss><comments>http://blogs.msdn.com/b/repltalk/archive/2012/07/30/initialization-of-merge-replication-subscriber-fails-with-primary-key-violation.aspx#comments</comments><description>&lt;h1&gt;Initialization of Merge Replication subscriber fails with primary key violation&lt;/h1&gt;  &lt;p&gt;Troy Moen   &lt;br /&gt;Microsoft SQL Server Escalation Services&lt;/p&gt;  &lt;p&gt;We encountered an unusual timing problem while pushing a Snapshot down to a merge subscriber.&amp;#160; We don’t expect many to encounter this problem, after all we’ve only seen it once in 15 years.&amp;#160; We wanted to share this as a learning opportunity as it illustrates a classic application\thread synchronization problem. &lt;/p&gt;  &lt;h3&gt;Scenario&lt;/h3&gt;  &lt;p&gt;Customer has Merge Replication running and need to reinitialize 1 subscriber.&amp;#160; Updates occur on both the Publisher and Subscriber.&amp;#160; At the time, we believed all subscriber updates were being redirected to the publisher, but as you’ll see, we were wrong.&lt;/p&gt;  &lt;p&gt;During the re-initialization the Merge Agent failed with the following message.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Error messages:&lt;/b&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;· The merge process was unable to deliver the snapshot to the Subscriber. If using Web synchronization, the merge process may have been unable to create or write to the message file. When troubleshooting, restart the synchronization with verbose history logging and specify an output file to which to write. (Source: MSSQL_REPL, Error number: MSSQL_REPL-2147201001)     &lt;br /&gt;Get help: &lt;a href="http://help/MSSQL_REPL-2147201001"&gt;http://help/MSSQL_REPL-2147201001&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;· The process could not bulk copy into table '&amp;quot;dbo&amp;quot;.&amp;quot;Table_1&amp;quot;'. (Source: MSSQL_REPL, Error number: MSSQL_REPL20037)     &lt;br /&gt;Get help: &lt;a href="http://help/MSSQL_REPL20037"&gt;http://help/MSSQL_REPL20037&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;· Batch send failed (Source: MSSQLServer, Error number: 0)     &lt;br /&gt;Get help: &lt;a href="http://help/0"&gt;http://help/0&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;Violation of PRIMARY KEY constraint 'PK_Table_1'. Cannot insert duplicate key in object 'dbo.Table_1'. (Source: MSSQLServer, Error number: 2627)     &lt;br /&gt;Get help: &lt;a href="http://help/2627"&gt;http://help/2627&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;If we started with an empty table and loaded rows from the Publisher how could we possibly get a “duplicate key”?&amp;#160; Did the duplicate data already exists in the saved BCP data from the Publisher?&amp;#160; We checked and it did NOT!!&lt;/p&gt;  &lt;p&gt;We looked at the subscriber table and notice it contained 1 rows with Primary Key value 1, but this was a different row then 1 from the BCP data we’re trying to load.&amp;#160; From where did this data originate?&amp;#160; Looking closer at the data we determined it was inserted only moments ago directly on the Subscriber from Subscriber’s application, which yes, we thought was stopped, but was still trying to insert data.&amp;#160; The application log shows it failing with “table not found” right up to the point where the table got created by the Merge Agent, then pop, it gets inserted.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Consider the following:&lt;/b&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;A publication exists with one table “Table_1” containing 100 rows.&lt;/li&gt;    &lt;li&gt;A user marks the subscription for re-initialization.&lt;/li&gt;    &lt;li&gt;A snapshot is generated of table, which contains max primary key value of 100.&lt;/li&gt;    &lt;li&gt;The Merge Agent begins application of the snapshot.&lt;/li&gt;    &lt;ol&gt;     &lt;li&gt;Table is dropped from Subscriber&lt;/li&gt;      &lt;li&gt;New empty table structure, with default starting identity value 1 is created&lt;/li&gt;   &lt;/ol&gt;    &lt;li&gt;Split millisecond before Merge Agent can execute Bulk Insert from the Publisher rows, the subscriber client inserts row into the subscriber.&amp;#160; This is assigned identity value 1.&lt;/li&gt;    &lt;li&gt;Merge Agent start bulk inserts from previously saved Publisher data containing identity values 1 – 100, it fails on the 1st row as identity 1 already exists.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Under the right conditions, the above example can result in a primary key violation.&lt;/p&gt;  &lt;h3&gt;Solution:&lt;/h3&gt;  &lt;p&gt;Disable clients from entering data into the subscriber database during that time. In most cases the “window” in which duplicate data could be inserted is very small, which varies depending on subscriber performance at the time. In my testing, only a few seconds maximum had passed before the trigger was created, and thus stopped any chance of duplicate data being added.&amp;#160; &lt;/p&gt;  &lt;p&gt;Another creative solution was to create a TRIGGER as part of the table creation to abort any user activity until after the Merge Agent bulk loads existing data, then remove the trigger to if you will, open the spigot and allow data changes to flow.&amp;#160; While creative, it takes a while to get all the detail in place for this to happen.&amp;#160; The first option is much easier.&amp;#160; Let’s take a look at this creative solution from a high level. The Merge Agent will follow these steps when applying the snapshot after a subscription has been marked for re-initialization:&lt;/p&gt;  &lt;p&gt;1. Drop the replicated table on the subscriber, provided “Action if name is in use” is set to “Drop existing” in the article properties.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/2072.clip_5F00_image002_5F00_51C05189.jpg"&gt;&lt;img style="display: inline; background-image: none;" title="clip_image002" border="0" alt="clip_image002" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/5633.clip_5F00_image002_5F00_thumb_5F00_5C1175E9.jpg" width="378" height="160" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;2. Create the replicated table on the subscriber.&lt;/p&gt;  &lt;p&gt;3. Apply a trigger disabling DML operations on the table in question:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;create trigger [dbo].[MSmerge_disabledml_9F571C3241264DA6972D846C0A738A71] on [dbo].[Table_1] for update, insert, delete&lt;/p&gt;    &lt;p&gt;not for replication&lt;/p&gt;    &lt;p&gt;as&lt;/p&gt;    &lt;p&gt;set nocount on&lt;/p&gt;    &lt;p&gt;if @@trancount &amp;gt; 0 rollback tran&lt;/p&gt;    &lt;p&gt;raiserror (20092, 16, -1, '[dbo].[Table_1]')&lt;/p&gt;    &lt;p&gt;return&lt;/p&gt;    &lt;p&gt;GO&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;4. BCP the snapshot data into the table.&lt;/p&gt;  &lt;p&gt;5. Remove the disable DML trigger.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10334972" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/Merge/">Merge</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/Not+for+Replication/">Not for Replication</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/Bulk+Insert/">Bulk Insert</category></item><item><title>Distribution Agent is blocking users on Subscriber while replicating INSERT, UPDATE, and DELETE statements.</title><link>http://blogs.msdn.com/b/repltalk/archive/2012/04/24/distribution-agent-is-blocking-users-on-subscriber-while-replicating-insert-update-and-delete-statements.aspx</link><pubDate>Tue, 24 Apr 2012 19:02:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10297300</guid><dc:creator>ReplTalk</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/repltalk/rsscomments.aspx?WeblogPostID=10297300</wfw:commentRss><comments>http://blogs.msdn.com/b/repltalk/archive/2012/04/24/distribution-agent-is-blocking-users-on-subscriber-while-replicating-insert-update-and-delete-statements.aspx#comments</comments><description>&lt;h1&gt;Distribution Agent is blocking users on Subscriber while replicating INSERT, UPDATE, and DELETE statements.&lt;/h1&gt;  &lt;p&gt;Chris Skorlinski   &lt;br /&gt;Microsoft SQL Server Escalation Services&lt;/p&gt;  &lt;p&gt;In the middle of a huge phased migration from SQL 2000 to SQL 2008 we noticed the SQL 2008 publisher\distributor was causing blocking when replicating data changes to the SQL 2000 subscriber.&lt;/p&gt;  &lt;p&gt;We discovered the SQL Server 2005\2008\2012 Distribution Agent was configured to replicate as native SQL commands instead of default parameterized stored procedures.&amp;#160; This option is controlled by the @ins_cmd = N'SQL', @del_cmd = N'SQL', @upd_cmd = N'SQL'&amp;#160; settings for sp_addarticle.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;delete from [dbo].[build_pricing] where [effort_code] = 'ALFKI'&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;When this is sent to the subscriber, the Distribution Agent converts this to sp_executesql such as following in attempt to optimize the execution.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;exec sp_executesql N'delete from [dbo].[build_pricing] where [effort_code] = @P1 N'@P1 nvarchar(5)&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;By default, the Distribution Agent passed parameters are nvarchar() data types. If the subscriber data type is char() and not nvarchar(), the Query Optimizer will perform a SCAN and CONVERT rows on the table values to match the passed parameter value data type. Results is high IO hit, large number of locks, high memory usage, long blocking.&lt;/p&gt;  &lt;p&gt;We also verified the high IO demands of a single row update or delete statement by examining the query plan.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;1&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 1&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; |--Parallelism(Gather Streams)     &lt;br /&gt;1&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 8&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; |--Index Scan(OBJECT:([dbo].[build_pricing]….Convert([effort_code])….&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This query plan shows 8 parallel streams (MaxDop = 8) was used to Scan (read) the Index while Converting char(5) [effort_code] data type to match the @P1 nvarchar(5)”.&amp;#160; For a single row update or delete and NO conversion the expected query plan would be an INDEX SEEK with 5 not 50,000 reads.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;“where [effort_code] = @P1 N'@P1 nvarchar(5)”&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;If you enable &lt;a href="http://blogs.msdn.com/b/repltalk/archive/2010/07/13/using-verbose-history-agent-profile-while-troubleshooting-replication.aspx"&gt;Verbose History&lt;/a&gt; You may also see Distribution WRITE taking much longer then READS.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Time to Apply Cmds (ms)&amp;#160;&amp;#160; : 1016331&amp;#160; Cmds/Sec&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 2.54&amp;#160; &lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;Time to Retrieve Cmds (ms): 6269&amp;#160; Cmds/Sec&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : 411.39&amp;#160;&amp;#160;&amp;#160; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Adding &amp;quot;-T 1&amp;quot; to the Distribution Agent Job Properties reverted the behavior to SQL 2000 which does not attempt to optimize the statements using sp_executesql, but instead submits them directly as SQL INSERT, UPDATE, and DELETE statements.&amp;#160; In testing the IO overhead dropped from 50K READS to 5, no latency, little or no blocking.&lt;/p&gt;  &lt;p&gt;Another option would be to replicated the data using the default Replication Stored Procedures instead of SQL commands.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Verified sp_addarticle the STATUS=0 and CMD='SQL'     &lt;br /&gt;&lt;a href="http://blogs.msdn.com/b/chrissk/archive/2009/05/08/troubleshooting-slow-distribution-agent-performance-in-sql-2005-2008.aspx"&gt;http://blogs.msdn.com/b/chrissk/archive/2009/05/08/troubleshooting-slow-distribution-agent-performance-in-sql-2005-2008.aspx&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10297300" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/Transactional/">Transactional</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/sp_5F00_executesql/">sp_executesql</category></item><item><title>How to set HistoryVerboseLevel Profile for all Agent</title><link>http://blogs.msdn.com/b/repltalk/archive/2012/04/09/how-to-set-historyverboselevel-profile-for-all-agent.aspx</link><pubDate>Mon, 09 Apr 2012 23:35:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10292060</guid><dc:creator>ReplTalk</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/repltalk/rsscomments.aspx?WeblogPostID=10292060</wfw:commentRss><comments>http://blogs.msdn.com/b/repltalk/archive/2012/04/09/how-to-set-historyverboselevel-profile-for-all-agent.aspx#comments</comments><description>&lt;h1&gt;How to set HistoryVerboseLevel Profile for all Agent&lt;/h1&gt;  &lt;p&gt;Chris Skorlinski   &lt;br /&gt;Microsoft SQL Server Escalation Services&lt;/p&gt;  &lt;p&gt;This is a follow up post to my article Using &lt;a href="http://blogs.msdn.com/b/repltalk/archive/2010/07/13/using-verbose-history-agent-profile-while-troubleshooting-replication.aspx"&gt;“Verbose history agent profile.” while troubleshooting Replication&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Using SQL Server Management Studio you can set a default profile for all Replication Agents.&amp;#160; In this walk through I’ll change ALL Merge Agents default to use the “Verbose History Agent Profile”.&lt;/p&gt;  &lt;p&gt;In SSMS, right click the Replication folder and select Distributor Properties. Near the bottom of the dialog select “Profile Defaults”.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/1106.image_5F00_03D0429F.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/2843.image_5F00_thumb_5F00_3F23A85D.png" width="312" height="111" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Select Merge Agent page, then select “Verbose history agent profile”.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/0284.image_5F00_028BA9C0.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/3240.image_5F00_thumb_5F00_28815A16.png" width="338" height="160" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This profile, similar to the default, has HistoryVerboseLevel = 3 to record detailed Merge history data in the MSmerge_history table in the Distribution database.&amp;#160; To apply this new profile setting to ALL Merge Agent select “Change Existing Agents” then click OK.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/5086.image_5F00_40A4C471.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/1106.image_5F00_thumb_5F00_5BDD1D72.png" width="336" height="138" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;While troubleshooting Replication you may want to increase the “History Retention”. Increasing DETAIL and keeping longer history will grow your distribution database.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/1185.image_5F00_141B948B.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/5481.image_5F00_thumb_5F00_13432EA1.png" width="339" height="79" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/0020.image_5F00_3DAF5FBE.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/6557.image_5F00_thumb_5F00_2AFA6607.png" width="334" height="83" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10292060" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/Merge/">Merge</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/MSmerge_5F00_history/">MSmerge_history</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/HistoryVerboseLevel/">HistoryVerboseLevel</category></item><item><title>Specify all articles when subscribing to a publication using concurrent snapshot processing.</title><link>http://blogs.msdn.com/b/repltalk/archive/2012/04/04/specify-all-articles-when-subscribing-to-a-publication-using-concurrent-snapshot-processing.aspx</link><pubDate>Wed, 04 Apr 2012 21:47:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10290934</guid><dc:creator>ReplTalk</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/repltalk/rsscomments.aspx?WeblogPostID=10290934</wfw:commentRss><comments>http://blogs.msdn.com/b/repltalk/archive/2012/04/04/specify-all-articles-when-subscribing-to-a-publication-using-concurrent-snapshot-processing.aspx#comments</comments><description>&lt;h1&gt;Specify all articles when subscribing to a publication using concurrent snapshot processing.&lt;/h1&gt;  &lt;p&gt;Chris Skorlinski   &lt;br /&gt;Microsoft SQL Server Escalation Services&lt;/p&gt;  &lt;p&gt;I recently encountered this error when setting up Transactional Replication via SQL scripts.&lt;/p&gt;  &lt;p&gt;Msg 14100, Level 16, State 1, Procedure sp_MSrepl_addsubscription, Line 533   &lt;br /&gt;Specify all articles when subscribing to a publication using concurrent snapshot processing.&lt;/p&gt;  &lt;p&gt;Looking at my create Publication script I see the default @sync_method = N'concurrent' being set in sp_addpublication.&amp;#160; Nothing I want to change here.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/0383.image_5F00_7658A181.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/6131.image_5F00_thumb_5F00_4EB22557.png" width="344" height="106" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Further in my script I see the call to sp_addsubscription.&amp;#160; From the BOL, this syntax look correct.&amp;#160; I’m running sp_addsubscription once for each article for this subscriber.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/5141.image_5F00_1BE21EE3.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/1351.image_5F00_thumb_5F00_7B5ADF30.png" width="344" height="102" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/4075.image_5F00_05AC0391.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/5460.image_5F00_thumb_5F00_13121697.png" width="345" height="82" /&gt;&lt;/a&gt;&lt;/p&gt;    &lt;p&gt;While the script looks correct, I wondered what the script would look like using default setting created by the Replication Wizard.&amp;#160; To test, I recreated the publication using the Wizard, then scripted out the publication.&amp;#160; I noticed Replication Wizard used had only 1 call to sp_addsubscription with option @article = N'all'.&lt;/p&gt; &lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/2818.image_5F00_3254BD6A.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/3404.image_5F00_thumb_5F00_3FBAD070.png" width="350" height="85" /&gt;&lt;/a&gt;  &lt;p&gt;Now the error makes sense.&amp;#160; When using Current Snapshot Processing I need to make 1 call to sp_addsubscription&amp;#160; with option and specify ALL articles for this subscriber.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10290934" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/Transactional/">Transactional</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/sp_5F00_addpublication/">sp_addpublication</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/sp_5F00_addsubscription/">sp_addsubscription</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/concurrent+snapshot/">concurrent snapshot</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/sp_5F00_MSrepl_5F00_addsubscription/">sp_MSrepl_addsubscription</category></item><item><title>Replicating Non-Clustered Indexes Improves Subscriber Query Performance</title><link>http://blogs.msdn.com/b/repltalk/archive/2012/04/03/replicating-non-clustered-indexes-improves-subscriber-query-performance.aspx</link><pubDate>Tue, 03 Apr 2012 16:40:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10290427</guid><dc:creator>ReplTalk</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/repltalk/rsscomments.aspx?WeblogPostID=10290427</wfw:commentRss><comments>http://blogs.msdn.com/b/repltalk/archive/2012/04/03/replicating-non-clustered-indexes-improves-subscriber-query-performance.aspx#comments</comments><description>&lt;h1&gt;Replicating Non-Clustered Indexes Improves Subscriber Query Performance&lt;/h1&gt;  &lt;p&gt;&lt;b&gt;Jared Poché, MCSE, MCDBA     &lt;br /&gt;&lt;/b&gt;SQL Server Sr. Support Escalation Engineer    &lt;br /&gt;Product Support Services (PSS) - Charlotte, NC&lt;/p&gt;  &lt;p&gt;One of the advantages of replication is that subscribing servers can be used for reporting thereby offloading RO query activity from the Publisher. Recently I worked on a performance case on such a replication subscriber, which would have been prevented with a simple change to the article properties for this publication.&amp;#160; We discovered the nonclustered indexes were missing from the subscriber.&lt;/p&gt;  &lt;p&gt;Indexes are key to the performance of SQL Server, but only clustered key indexes are replicated by default. Unique constraints are replicated by default, so their indexes will also be created on subscribers, but nonclustered indexes are not replicated by default.&amp;#160; While setting up transaction replication on a database, we can change the default settings for articles on the Articles window to include nonclustered indexes. &lt;/p&gt;  &lt;p&gt;Once the necessary tables and other articles have been selected, choose Article Properties and Set Properties of All Table Articles.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/0167.image_5F00_7D0D73B8.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/6837.image_5F00_thumb_5F00_0A0753CA.png" width="402" height="343" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This page shows us a number of settings for indexes, constraints, and so on. Find the &lt;strong&gt;Copy Nonclustered Indexes&lt;/strong&gt; setting, set this option to true, and click OK. This will cause all nonclustered indexes on the publisher to be included in the snapshot for delivery on the Subscribers. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/3113.clip_5F00_image002_5F00_3B268E6A.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-34-30-metablogapi/3704.clip_5F00_image002_5F00_thumb_5F00_2152583B.png" width="305" height="414" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Changing the article options will effectively create indexes on all subscribers with only a few clicks. Also, if a new snapshot is taken for the publication and applied to the subscribers, any indexes created directly on those subscribers will be removed.&amp;#160; If all indexes are not needed, alternatively, you can create selective indexes directly on a subscriber. However, it reduces administrative overhead to change the option directly in the replication settings for the article.&lt;/p&gt;  &lt;p&gt;MSDN References:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en/sqlreplication/thread/51512117-b53d-429b-8c3d-84d9a925126e"&gt;http://social.msdn.microsoft.com/Forums/en/sqlreplication/thread/51512117-b53d-429b-8c3d-84d9a925126e&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://technet.microsoft.com/en-us/library/ms175980.aspx"&gt;http://technet.microsoft.com/en-us/library/ms175980.aspx&lt;/a&gt; (sp_changearticle)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10290427" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/Performance/">Performance</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/nonclustered+indexes/">nonclustered indexes</category><category domain="http://blogs.msdn.com/b/repltalk/archive/tags/sp_5F00_changearticle/">sp_changearticle</category></item><item><title>Marking Identity Columns as “Not For Replication” in existing Publication</title><link>http://blogs.msdn.com/b/repltalk/archive/2012/03/06/marking-identity-columns-as-not-for-replication-in-existing-publication.aspx</link><pubDate>Tue, 06 Mar 2012 00:53:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10278079</guid><dc:creator>ReplTalk</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/repltalk/rsscomments.aspx?WeblogPostID=10278079</wfw:commentRss><comments>http://blogs.msdn.com/b/repltalk/archive/2012/03/06/marking-identity-columns-as-not-for-replication-in-existing-publication.aspx#comments</comments><description>&lt;h1&gt;Marking Identity Columns as “Not For Replication” in existing Publication&lt;/h1&gt;  &lt;p&gt;Chris Skorlinski   &lt;br /&gt;Microsoft SQL Server Escalation Services&lt;/p&gt;  &lt;p&gt;We encounter a problem today with a Distribution Agent failing with “Row Not Found” when pushing an UPDATE to a Subscriber.&amp;#160; Reaching the problem we discovered the Subscriber was created using a Backup\Restore from the Publisher and had Identity Columns.&amp;#160; The Identity Columns had “Not For Replication” set to NO, which flags the Distribution Agent to “renumber” (i.e. reseed) data as it is Replication to the Subscriber.&lt;/p&gt;  &lt;p&gt;For example:&amp;#160; Row 100 inserted at Publisher,&amp;#160; but is renumbered by the Distribution Agent to row 20 at the Subscriber.&amp;#160; Later same row 100 is edited on the Publisher.&amp;#160; The Distribution Agent looks for but is unable to find row 100 and fails with “row not found”.&amp;#160; Instead we want the Distribution Agent to use the same value from the Publisher.&amp;#160; For this we need to enable the “Not For Replication” setting on the Identity Column on the Publisher table.&lt;/p&gt;  &lt;p&gt;If you try and change the Publisher table design while data exists you get error which prevents saving changes.&amp;#160; To work around this problem you can use the stored procedure below to change the “Not For Replication” setting for all tables in the database then reinitialize the subscriber.&lt;/p&gt;  &lt;h4&gt;Change identity setting for all tables in the database:&lt;/h4&gt;  &lt;pre class="csharpcode"&gt;EXEC sp_msforeachtable @command1 = &lt;span class="rem"&gt;'&lt;/span&gt;
&lt;span class="kwrd"&gt;declare&lt;/span&gt; @int int
&lt;span class="kwrd"&gt;set&lt;/span&gt; @int =object_id(&lt;span class="str"&gt;&amp;quot;?&amp;quot;&lt;/span&gt;)
EXEC sys.sp_identitycolumnforreplication @int, 1'&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10278079" width="1" height="1"&gt;</description></item></channel></rss>