<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8436612531636428647</id><updated>2012-01-25T23:39:18.708+05:30</updated><category term='How to drop all the user databases in one GO'/><title type='text'>Yukon-Katmai Discussion</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>81</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-9195669550763178138</id><published>2012-01-18T10:32:00.002+05:30</published><updated>2012-01-18T10:45:22.541+05:30</updated><title type='text'>Replication : Latency but no Latency</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I am sure those of you who have been through the replication latency issues know that these issues are not easy to crack .Gaining expertise in Replication especially issues related to latency cannot be learned or taught in a class.&lt;br /&gt;&lt;br /&gt;Mostly, issues related to latency are due to :&lt;br /&gt;&lt;br /&gt;1: Blocking on DIST/PUB/SUB&lt;br /&gt;2: High Resource consumption : CPU,Storage,Memory&lt;br /&gt;3: Network issues&lt;br /&gt;4: Huge size of Distribution database (msrepl_transactions and msrepl_comands)&lt;br /&gt;5: Transaction log of publisher is huge (too many VLFs) causing log reader latency .&lt;br /&gt;&lt;br /&gt;-I am sharing this one with you where actually there was no latency due to any of these as I&lt;br /&gt;&amp;nbsp;mentioned&amp;nbsp;above.&lt;br /&gt;-There was no blocking&lt;br /&gt;-CPU,memory and Diskes were doing good .&lt;br /&gt;-There was no network issue&lt;br /&gt;-We shrunk the publisher database which did not help us at all .&lt;br /&gt;-Cleanup job was running fine .We ran update stats with full scan on&amp;nbsp;msrepl_transactions and&lt;br /&gt;&amp;nbsp; msrepl_comands which did not help either .&lt;br /&gt;&lt;br /&gt;When latency started piling up , we first had a look at the log reader and distributor agent history in distribution database but could not get much information due to another issue (out of scope of this post) because of which the log reader history was not showing up and distributor history was showing that almost no data is coming to subscriber ..Normally every 5 mins the throughput of logreader and distribution agent threads (reader and writer threads) are written in to mslogreader_history and msdistribution_history system tables .But we were getting false entries there .&lt;br /&gt;&lt;br /&gt;We had no choice but to take the verbose log for distribution and log reader agents .From the logs it was clear that the log reader agent was delivering more than 1000 commands/sec while distribution agent was delivering less than 100 cmds/sec .&lt;br /&gt;&lt;br /&gt;We were totally clue less because :&lt;br /&gt;- Log Reader was running at its usual speed .So there was no issue with the Publisher .Nor there was any issue in pumping the data to&amp;nbsp;Distributor.The log Reader Verbose log cleared it .So this was ruled out .&lt;br /&gt;&lt;br /&gt;- Data from Distributor to Subscriber was slow .But we were not able to find out whether its slow in reading the data from distribution db or slow in pumping the data to the subscriber .db .What we could clearly see was that there was almost no activity on the subscriber .&lt;br /&gt;&lt;br /&gt;-No Resource bottlenecks .Its just that something was stopping the data to flow from distributor to subscriber .This was like when we see an hour glass where there is a lot of sand at the top but the hole is so small that very less can go out of it .&lt;br /&gt;&lt;br /&gt;I then saw the distribution verbose logs again and found that there were very frequent entries related to committing the transactions .The 5 similar sentences in 5 continuous lines were not very much clear but I could feel that something related to committing transactions was happening .But still very unclear .These entries were repeating in a group of 5-6 very frequently .The time consumption was around 2 seconds for each spell of 5-6 entries .&lt;br /&gt;&lt;br /&gt;This gave us some hint and we immediately jumped to the Distribution agent profile to see if someone has not modified any setting which might be causing this issue.We did a mistake again because we just right clicked replication &amp;gt;&amp;gt; Distributor properties &amp;gt;&amp;gt; agent profiles &amp;gt;&amp;gt; Distribution agent .This was looking fine .&lt;br /&gt;&lt;br /&gt;&lt;b&gt;However, one of our&amp;nbsp;colleagues opened up the profile of the distribution agent that was giving us the issue&amp;nbsp;&amp;nbsp;.This was the right way guys .We needed to do this .&lt;/b&gt;&amp;nbsp;We found that &amp;nbsp;-CommitBatchSize (default Value 100) and -CommitBatchThreshold(default Value 1000)&amp;nbsp;values were changed to 10 each .&lt;br /&gt;&lt;br /&gt;We then changed it back to the default and recycled the Distribution Agent .Thats it , the story ends here .&lt;br /&gt;Due to this the rate at which the transactions were delivered at 1 cmd/transaction .&lt;br /&gt;&lt;br /&gt;Even though it was a small setting that caused us slogging for hours , but the experience of working on the replication latency issue when there was actually no resource bottleneck (I call it as false latency) was amazing ..&lt;br /&gt;&lt;br /&gt;Cheers and Happy Learning ..&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-9195669550763178138?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/9195669550763178138/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=9195669550763178138&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/9195669550763178138'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/9195669550763178138'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2012/01/replication-latency-but-no-latency.html' title='Replication : Latency but no Latency'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-5844424678663028681</id><published>2012-01-14T13:29:00.001+05:30</published><updated>2012-01-14T13:29:34.047+05:30</updated><title type='text'>Can restoring a database to another instance reduce Index fragmentation of underlying tables ?</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;Answer is NO ..but to come to this conclusion , I had to spend some time .One of my&amp;nbsp;colleagues came to me with this question .My instant answer was a clear NO ...But then I asked him with a curiosity the reason for asking this question .As per him the nightly index reorg job that should run for a very long time , finished in just 3 hours .Also we cannot check the index fragmentation since it takes around 2 hours .Our tables are huge ..&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;I thought of 3 reasons :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;1) Since there is a logic in our job to do&amp;nbsp;re-org&amp;nbsp;only if there is certain level of fragmentation , that day there might be no index coming in the rebuild category.This&amp;nbsp;possibility was less but cannot be ruled out .&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;2) The restore actually&amp;nbsp;reshuffled&amp;nbsp;the pages and in that attempt cleared out some leaf level fragmentation .I remembered that restores take more time than backups .So I started believing this .&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;3) There might be some Re-org activity happening during the time the backups were happening .The backup might have a copy of well re-orged pages and this might have resulted in a less fragmented database .&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;I first started off with point 2 and soon realized that I was not correct .This did not take me much time .For point one , we added the log in the job so that as the job finishes , it creates the log which we can read .But this will take time to generate.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;Now , I was left with option 3 .I had the table with &amp;gt; 99% fragmentation and&amp;nbsp;24085822 rows&lt;/span&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&amp;nbsp;.The table size was around 4GB . DBCC Showcontig output is shared below :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;DBCC SHOWCONTIG scanning 'stats_test' table...&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;Table: 'stats_test' (711673583); index ID: 1, database ID: 6&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;TABLE level scan performed.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Pages Scanned................................: &lt;b&gt;268007&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Extents Scanned..............................: &lt;b&gt;33569&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Extent Switches..............................: &lt;b&gt;268005&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Avg. Pages per Extent........................: 8.0&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Scan Density [Best Count:Actual Count].......: 12.50% [33501:268006]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Logical Scan Fragmentation ..................: 99.22%&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Extent Scan Fragmentation ...................: 0.01%&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Avg. Bytes Free per Page.....................: 3334.3&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Avg. Page Density (full).....................: 58.81%&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;DBCC execution completed. If DBCC printed error messages, contact your system administrator.&lt;/span&gt;&lt;br /&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;I then ran Index Reorg and noticed percent_complete column in sys.dm_exec_requests DMV .When it reached 46% , I kicked off the backup of the database .&lt;/div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;Now let me restore the backup .....fingers crossed :) ....&lt;/div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;DBCC SHOWCONTIG scanning 'stats_test' table...&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;Table: 'stats_test' (711673583); index ID: 1, database ID: 6&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;TABLE level scan performed.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Pages Scanned................................: 158633&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Extents Scanned..............................: 19862&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Extent Switches..............................: 19866&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Avg. Pages per Extent........................: 8.0&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Scan Density [Best Count:Actual Count].......: 99.81% [19830:19867]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Logical Scan Fragmentation ..................: 0.15%&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Extent Scan Fragmentation ...................: 3.47%&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Avg. Bytes Free per Page.....................: 51.2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;- Avg. Page Density (full).....................: 99.37%&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: Verdana, sans-serif;"&gt;DBCC execution completed. If DBCC printed error messages, contact your system administrator.&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;Mystery solved ....&lt;/div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Verdana, sans-serif;"&gt;Happy learning ..&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-5844424678663028681?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/5844424678663028681/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=5844424678663028681&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5844424678663028681'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5844424678663028681'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2012/01/can-restoring-database-to-another.html' title='Can restoring a database to another instance reduce Index fragmentation of underlying tables ?'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-5017499488819229091</id><published>2012-01-13T12:25:00.000+05:30</published><updated>2012-01-25T23:39:18.713+05:30</updated><title type='text'>Replicating SP execution : Issue in SQL Server 2005 SP3 CU2 .Works fine in SQL 2008 SP1</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;posting after a long time gap and might still have not posted until yesterday when I got to know how smart Replication is .&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Brief Summary :&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;We have a very large OLTP&amp;nbsp;environment where millions of small queries do inserts and updates (No deletes) .The same is replicated to other subscribers .the data is so much that most of the time we firefight latency . So&amp;nbsp;because&amp;nbsp;of the size of the data we started archiving ,which also started deleting the data in batches from OLTP&amp;nbsp;environment and replicating the same to the subscribers .This further added to latency for obvious reasons.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;So to reduce latency ,we started thinking of &lt;b&gt;replicating the execution of Stored Proc&lt;/b&gt; that deletes the rows in batches .No, I am not trying to say the just because we can replicate the SP execution , that the replication is smart .This feature is quite old now and perhaps you all might be aware of this already.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Issue that we thought we might face :&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;We already have had all the required tables added as articles in the respective publications .And now if we add the Stored procedures in the publication then we thought Replication will try to update and insert the data twice . For example Lets say there are 2 articles in the publication .The first one is a table (lets say REPL_TAB) and the second one is a SP (say REPL_SP) .REPL_SP deletes x rows from REPL_TAB.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Now, if we execute REPL_SP , we thought that it should affect the Subscriber table twice .One when the SP deletes the rows and two , since the rows are being deleted REPL_TAB should also replicate the same .So we thought this might not work .We then thought of creating another publication with this SP added as an article but had same reservations .&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;But logically , I thought that Log Reader agent should pickup the command from the T-Log and should be smart enough to replicate it once .I mean if I run EXEC XYZ which deletes 10 rows in a table ABC ,then it should only replicate EXEC XYZ and not the delete command because the rows are being deleted from the table and that table is also an article in the same or for that sake different publication .&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;I first tested this in SQL Server 2005 SP3 CU2 and got it partially working .In the same publication If I have &amp;nbsp;both the articles the executing the stored procedure will fill &lt;b&gt;msrepl_commands&lt;/b&gt; and &lt;b&gt;merepl_transactions&lt;/b&gt; with 1 row each .But If there are 2 publications with one article in each and I execute the SP to delete x rows its replicated twice .First 1 command and 1 transactions and then x commands and 1 transactions .Distribution history confirms the same .&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;I then tested the same on SQL Server 2008 SP1 and it worked like a charm .Below is the proof of concept for your reference :&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Test 1:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;We have 2 publications on Adventureworks database .One is publishing a table and the other is a stored procedure execution (by default Stored procedure execution is not enabled).Stored Procedure Del_stats_scan, deletes top 10 rows from table dbo.Stats_State in the Publisher database Adventureworks)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;SQL Server verion :&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Microsoft SQL Server 2008 (SP1) - 10.0.2531.0 Evaluation Edition on Windows XP SP3&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;Publisher database :&lt;/b&gt; Adventureworks&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;|_&lt;b&gt;Table :&lt;/b&gt;dbo.Stats_State&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;|_&lt;b&gt;SP:&lt;/b&gt;dbo.del_stats_scan&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;|_&lt;b&gt;Publication :&lt;/b&gt;ADV_Table&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;|&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;|_&lt;b&gt;Article :&lt;/b&gt;dbo.Stats_State&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;|_&lt;b&gt;Publication:&lt;/b&gt;ADV_SP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;|_&lt;b&gt;Article :&lt;/b&gt;dbo.del_stats_scan&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;Subscriber Database :&lt;/b&gt; ADV_SUB&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;|_&lt;b&gt;Table :&lt;/b&gt;dbo.Stats_State&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;|_&lt;b&gt;SP:&lt;/b&gt;dbo.del_stats_scan&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;b&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Jobs :&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Log Reader Agents &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;:1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Snapshot Agent &amp;nbsp; &amp;nbsp; &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;:2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Distribution Agent &amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;:2&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Replication is in synchronization :&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Queries fired on publisher DB :&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;div style="color: black; font-weight: bold;"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Query 1&lt;/span&gt;&lt;/div&gt;&lt;div style="color: black;"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;delete top (10) from dbo.stats_test&lt;/span&gt;&lt;/div&gt;&lt;div style="color: black;"&gt;&lt;div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;Results :&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Data replicated only once .The second Distribution agent did not Do anything . The reason you are seeing 2 transactions in log reader is because both are same images .Log Reader for one database is only ONE .&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;Fire these queries to find out what is being replicated :&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;select * from distribution.dbo.MSrepl_commands&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;select * from distribution.dbo.MSrepl_transactions&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="color: black;"&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;Query 2 :&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;exec del_stats_scan&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;b&gt;Results :&lt;/b&gt;Data Replicated only once.Only the SP executed and replicated .The other distribution agent did not do any thing . The reason you are seeing 2 transactions in log reader is because both are same images. Log Reader for one database is only ONE .&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family: 'Trebuchet MS', sans-serif;"&gt;&lt;div&gt;Run these queries to find out what has been replicated&lt;/div&gt;&lt;div&gt;select COUNT(*) 'No. of rows in Repl_cmds' from distribution.dbo.MSrepl_commands&lt;/div&gt;&lt;div&gt;select COUNT(*) 'No. of rows in Repl_Trans'from distribution.dbo.MSrepl_transactions&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Test 2:&lt;/div&gt;&lt;div&gt;We have 1 publication on Adventureworks database with 2 articles.One article is publishing a table and the other article is publishing the stored procedure execution (by default Stored procedure execution is not enabled).&lt;/div&gt;&lt;div&gt;Stored Procedure Del_stats_scan, deletes top 10 rows from table dbo.Stats_State in the Publisher database (Adventureworks).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;SQL Server verion :&lt;/b&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;Microsoft SQL Server 2008 (SP1) - 10.0.2531.0 Evaluation Edition on Windows XP SP3&lt;/div&gt;&lt;div&gt;&lt;b&gt;Publisher database :&lt;/b&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;Adventureworks&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;|_Table :dbo.Stats_State&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;|_SP:dbo.del_stats_scan&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;|_Publication :ADV_Table&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;|_Article :dbo.Stats_State&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt;  &lt;/span&gt;|_Article :dbo.del_stats_scan&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Subscriber Database : ADV_SUB&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;|_Table :dbo.Stats_State&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;|_SP:dbo.del_stats_scan&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Jobs :&lt;/div&gt;&lt;div&gt;Log Reader Agents &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;:1&lt;/div&gt;&lt;div&gt;Snapshot Agent &amp;nbsp; &amp;nbsp; &lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;:1&lt;/div&gt;&lt;div&gt;Distribution Agent &amp;nbsp;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;:1&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Repeat Test 1 and 2 and see the results .&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Conclusion :&lt;/b&gt;&lt;/div&gt;&lt;div&gt;SQL Server 2008 Replication(log Reader) is smart enough and replicate data only once from the transaction log to Distributor .Distributor then distributes the command to the subscriber.There is a bug in SQL Server 2005 SP3 CU2 where the second test works fine but not the first test and replicate twice if we execute the SP. You will have to find out which CU in 2005 fixed this or might want to directly apply SP4.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Happy Learning .&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-5017499488819229091?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/5017499488819229091/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=5017499488819229091&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5017499488819229091'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5017499488819229091'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2012/01/replicating-sp-execution-issue-in-sql.html' title='Replicating SP execution : Issue in SQL Server 2005 SP3 CU2 .Works fine in SQL 2008 SP1'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-8411940459267483512</id><published>2011-07-22T13:49:00.000+05:30</published><updated>2012-01-15T20:08:22.459+05:30</updated><title type='text'>What does resourcedb contain ?</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Many a times this question has been asked (either in interviews or just out of curiosity) that what does resourcedb contain and why is it so important to SQL Server ?&lt;br /&gt;&lt;br /&gt;Normally we can't see it and hence can't use it .However, there is a way you can use resource database .&lt;b&gt;But be careful. If you mess up anything you might end up paying a heavy cost.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Since we are discussing about this ,there is one more point that I would like to touch here .Starting from SQL 2005 there are no system tables but DMVs for us to query .However, if you query sys.objects and filter it on type ='S' ,you will notice a lot of system tables listed in the output .So there are system tables and we can see them .But if you try to query them ,you will get an annoying 208 error stating that the object does not exist which is not correct.So in this post we will see how to query resource database and also in a similar manner other system and user database .&lt;br /&gt;&lt;br /&gt;Let us see how can we use resource database and also query system tables.Start SQL Server with -m switch ( in single user mode ) . There are 2 ways :&lt;br /&gt;&lt;br /&gt;1) Through services console (after adding &lt;b&gt;-m&lt;/b&gt; do not click on &lt;b&gt;OK&lt;/b&gt; but click on &lt;b&gt;start&lt;/b&gt; )&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-ilwJJ9kqB9Y/TikumOnjQ-I/AAAAAAAAA4Q/9H_YGTxR_fA/s1600/untitled.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://3.bp.blogspot.com/-ilwJJ9kqB9Y/TikumOnjQ-I/AAAAAAAAA4Q/9H_YGTxR_fA/s400/untitled.JPG" width="350" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;2) Through DOS prompt&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-yLyceTYOyZw/TikumKV5j8I/AAAAAAAAA4Y/5-57Y2UGnVY/s1600/untitled1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="66" src="http://1.bp.blogspot.com/-yLyceTYOyZw/TikumKV5j8I/AAAAAAAAA4Y/5-57Y2UGnVY/s400/untitled1.JPG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Once SQL Server has been started in single user mode , we can make only one connection . We will connect to SQL Server using DAC .DAC option can only be used in sqlcmd utility and not in OSQL or ISQL .Again there are two ways to do this .But before trying to attempt for DAC connection make sure you have enabled &lt;b&gt;remote admin connection&lt;/b&gt; option via &lt;b&gt;sp_configure&lt;/b&gt; (you can see the run value of 1):&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-vqUovNOxGJs/TikumfaRceI/AAAAAAAAA4g/odj2lRlPZFk/s1600/untitled2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="104" src="http://2.bp.blogspot.com/-vqUovNOxGJs/TikumfaRceI/AAAAAAAAA4g/odj2lRlPZFk/s400/untitled2.JPG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;1) connecting to SQL Server with DAC (using SQLCMD) using -A option&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-f7UNgMtj7BY/TikumSo4FLI/AAAAAAAAA4o/lbb5pQMMFwU/s1600/untitled3.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="59" src="http://1.bp.blogspot.com/-f7UNgMtj7BY/TikumSo4FLI/AAAAAAAAA4o/lbb5pQMMFwU/s400/untitled3.JPG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;2)Connecting via MGT Studio&lt;br /&gt;Open Management studio , It will prompt you to enter the instance name .  Just before the instance name add &lt;b&gt;admin&lt;/b&gt;: &lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-rkcYU_rVhio/TikumuYGTQI/AAAAAAAAA4w/hGcw-TpLFQs/s1600/untitled4.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="303" src="http://4.bp.blogspot.com/-rkcYU_rVhio/TikumuYGTQI/AAAAAAAAA4w/hGcw-TpLFQs/s400/untitled4.JPG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;you might or might not get this error :&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-IdvK3Um6xdU/Tiku0UxYxpI/AAAAAAAAA44/xhxX_ImivLg/s1600/untitled5.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="102" src="http://1.bp.blogspot.com/-IdvK3Um6xdU/Tiku0UxYxpI/AAAAAAAAA44/xhxX_ImivLg/s400/untitled5.JPG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;If you get this error then click OK ( this error window will go away ) and then instead of &lt;b&gt;Connect&lt;/b&gt; click on &lt;b&gt;cancel &lt;/b&gt;.&lt;br /&gt;you will see a clean screen like below :&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-9F0jr_Fmbls/Tiku0t7TtmI/AAAAAAAAA5A/h7b5Q04JEBE/s1600/untitled6.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="231" src="http://1.bp.blogspot.com/-9F0jr_Fmbls/Tiku0t7TtmI/AAAAAAAAA5A/h7b5Q04JEBE/s400/untitled6.JPG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Click on new query &lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-KH6E5Nd64go/Tiku0sUhD5I/AAAAAAAAA5I/k144Mx2G3uQ/s1600/untitled7.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="26" src="http://3.bp.blogspot.com/-KH6E5Nd64go/Tiku0sUhD5I/AAAAAAAAA5I/k144Mx2G3uQ/s400/untitled7.JPG" width="338" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;You will again see the same connection popup :&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-jlKxlzaYMV0/Tiku1B5OXgI/AAAAAAAAA5Q/8HQxY-OIGXg/s1600/untitled8.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="303" src="http://2.bp.blogspot.com/-jlKxlzaYMV0/Tiku1B5OXgI/AAAAAAAAA5Q/8HQxY-OIGXg/s400/untitled8.JPG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;This time click on connect and it will work :) .A new query window will open even though you will not see the databases in the left hand side pane but the connection is there and working ...&lt;br /&gt;&lt;br /&gt;Run the query 'use mssqlsystemresource' and press F5 :) ...It will work :&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-N2PQz8nUyDU/Tiku1V9P3VI/AAAAAAAAA5Y/APOLsyAOuxA/s1600/untitled9.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="151" src="http://4.bp.blogspot.com/-N2PQz8nUyDU/Tiku1V9P3VI/AAAAAAAAA5Y/APOLsyAOuxA/s400/untitled9.JPG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Also if you query sys.sysdbreg sytem table (an alternative for sys.sysdatabases DMV )you will see the resource database :&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-SMjuUjhmRrw/Tiku8BrX3tI/AAAAAAAAA5g/hHhDD8Vq0yg/s1600/untitled10.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="310" src="http://3.bp.blogspot.com/-SMjuUjhmRrw/Tiku8BrX3tI/AAAAAAAAA5g/hHhDD8Vq0yg/s400/untitled10.JPG" width="250" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;This database is currently in read-only mode (trust me :-) ) . If you want to cross check this run &lt;b&gt;dbcc shrinkdatabase (mssqlsystemresource)&lt;/b&gt; and you will get to know .&lt;br /&gt;You can set it to read_write mode though by running : &lt;b&gt;alter database mssqlsystemresource set read_write&lt;/b&gt;.Now the very fact that this table is Read-Only and that we cannot take the backup of this database ,proves that this database might not contain very important information ...if you query the tables you will see that certain static information is stored which the engine might be using from time to time .Something like we store the values in a temp table or a variable .So coming back to the original question , resource database contain a lot of static information which the engine might need from time to time for its internal use .&lt;br /&gt;&lt;br /&gt;At the end you might ask  "&lt;b&gt;Whats the need to touch the system tables in the database ?&lt;/b&gt;"&lt;br /&gt;&lt;b&gt;The answer is :&lt;/b&gt; We normally do not need to do this (especially Resource DB ) but there are other databases (system as well as user ) having some information we can use to resolve some issues (by updating those tables as needed ). And to resolve those issues , we need to login in this way ....&lt;br /&gt;&lt;br /&gt;Hope you have found it interesting .But remember , BE VERY CAREFUL WHEN YOU TRY TO PLAY AROUND WITH SYSTEM TABLES (as i said in the beginning).&lt;br /&gt;Happy Learning !!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-8411940459267483512?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/8411940459267483512/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=8411940459267483512&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/8411940459267483512'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/8411940459267483512'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2011/07/what-does-resourcedb-contain.html' title='What does resourcedb contain ?'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-ilwJJ9kqB9Y/TikumOnjQ-I/AAAAAAAAA4Q/9H_YGTxR_fA/s72-c/untitled.JPG' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-5301841688261696572</id><published>2011-06-26T11:16:00.000+05:30</published><updated>2011-06-26T11:16:02.340+05:30</updated><title type='text'>Replication :Archiving partitioned and non-Partitioned tables (Without removing the articles from the publications)</title><content type='html'>Recently there was a request on the MSDN forums where the poster wanted to archive the replicated partitioned tables in the publisher database . I think it would be good to share the solution with everyone in this forum as well .&lt;br /&gt;In this post we will see :&lt;br /&gt;&lt;b&gt;&lt;br /&gt;Part 1) archiving the replicated non-partitioned (normal) tables .&lt;br /&gt;Part 2) archiving the replicated partitioned tables .&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;At the end ,you will notice one nice to know feature of partitioned tables .&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Part 1) Archiving the replicated non-partitioned (normal) tables .&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Publisher :&lt;/b&gt; DB2Migration&lt;br /&gt;&lt;b&gt;Subscriber :&lt;/b&gt; DB2Migration_Sub&lt;br /&gt;&lt;b&gt;Replication Topology :&lt;/b&gt; Transactional Replication &lt;br /&gt;&lt;b&gt;Articles :&lt;/b&gt; dbo.Test&lt;br /&gt;&lt;b&gt;Other details :&lt;/b&gt; Both tables have 10000 rows each after first synchronization.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-n4nLHOiYBjI/Tga_idyUQXI/AAAAAAAAA2U/8R6ZOLT66GU/s1600/untitled.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="181" width="382" src="http://2.bp.blogspot.com/-n4nLHOiYBjI/Tga_idyUQXI/AAAAAAAAA2U/8R6ZOLT66GU/s400/untitled.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Now we need to archive the test table in publisher database but want to keep the Subscriber untouched i.e. the rows in subscriber should not change .For this example we will delete all the rows of the publisher table .&lt;br /&gt;&lt;br /&gt;How should we do it ?&lt;br /&gt;If I delete any row on publisher , the same will be replicated to subscriber . One way might be to stop the log reader agent and then delete the rows .After this , I can fire sp_repldone on the publisher and start the logreader agent .yes this is perfectly achievable . Here we go ...&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-iRCIm5P9ADM/Tga_is7ceBI/AAAAAAAAA2c/puAE0WKuarI/s1600/untitled1.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="191" width="400" src="http://3.bp.blogspot.com/-iRCIm5P9ADM/Tga_is7ceBI/AAAAAAAAA2c/puAE0WKuarI/s400/untitled1.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-GkPUzqaN1eM/Tga_iogp8BI/AAAAAAAAA2k/VS1XRndhnwc/s1600/untitled2.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="36" width="400" src="http://4.bp.blogspot.com/-GkPUzqaN1eM/Tga_iogp8BI/AAAAAAAAA2k/VS1XRndhnwc/s400/untitled2.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;DBCC opentran will show :&lt;/b&gt;&lt;br /&gt;No active open transactions.&lt;br /&gt;DBCC execution completed. If DBCC printed error messages, contact your system administrator.&lt;br /&gt;&lt;br /&gt;We will enable the LogReader agent now and will see that there are no transactions to be replicated.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-LHW6fZmqB9g/Tga_izXG93I/AAAAAAAAA2s/Kz0erAJYh2g/s1600/untitled3.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="191" width="400" src="http://2.bp.blogspot.com/-LHW6fZmqB9g/Tga_izXG93I/AAAAAAAAA2s/Kz0erAJYh2g/s400/untitled3.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Select count * from both the tables will show 0( zero ) and 10000 rows respectively .&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-K9ugUHOt7q0/Tga_jZenFtI/AAAAAAAAA20/s-XW_bXAbnk/s1600/untitled4.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="196" width="386" src="http://1.bp.blogspot.com/-K9ugUHOt7q0/Tga_jZenFtI/AAAAAAAAA20/s-XW_bXAbnk/s400/untitled4.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;After this we will insert 1000 rows in publisher table ( we need to be careful as the tables have primary key).As a result the subscriber now, has 11000 rows and publisher has 1000 rows .&lt;i&gt;This is going to be costly when there will be millions of rows because delete (or update or insert )is a logged activity&lt;/i&gt;.There is one more drawback and perhaps more critical.The log reader agent is one per database .So if there are more than one publications on the same database and we run sp_repldone , then we will hurt other subscriptions and publications .So we have to be careful. Other way is to truncate the table (after moving the data to an archived table) but replicated tables cannot be truncated (&lt;b&gt;why ???&lt;/b&gt;.....simple , truncate is a non-logged activity and log-reader agent reads the log file to find the transactions marked for replication using sp_replcmds).So to truncate the table ,you need to remove the article from the publication .If you want to do that the steps are :&lt;br /&gt;&lt;br /&gt;*******TEST THIS BEFORE IMPLEMENTING IT IN PRODUCTION********&lt;br /&gt;1) Stop the log reader agent and distribution agent &lt;br /&gt;2) Drop the article(s) from the publication &lt;br /&gt;3) Archive the table to another table ( this will be a logged activity ) by Bulk insert or BCP or import export wizard &lt;br /&gt;4) Truncate the table 5) Add the article again &lt;br /&gt;6) Change the properties of all the articles in the publication properties to "Keep existing object unchanged" for option action "if name is in use " .This is the most important step and please cross check it a few times to make sure that "Keep existing object unchanged " is set &lt;br /&gt;6) generate the snapshot again ....&lt;br /&gt;7) start the log reader agent and distribution agent and initiate the new snapshot ....&lt;br /&gt;*******TEST THIS BEFORE IMPLEMENTING IT IN PRODUCTION********&lt;br /&gt;Trust me .you are done :) ..But don't you think its lengthy and a bit risky ..Now lets see something new ...&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Part 2) Archiving the replicated partitioned tables .&lt;/b&gt;&lt;br /&gt;Let us first create 2 new databases &lt;b&gt;followed by&lt;/b&gt; creating partition functions &lt;b&gt;followed by&lt;/b&gt; partition schemes &lt;b&gt;followed by&lt;/b&gt; partitioned tables &lt;b&gt;followed by&lt;/b&gt; inserting data in the tables .&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;--creating database and filegroups&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;create database test&lt;br /&gt;GO &lt;br /&gt;ALTER DATABASE test ADD FILEGROUP [second] &lt;br /&gt;GO &lt;br /&gt;ALTER DATABASE test ADD FILEGROUP [third] &lt;br /&gt;GO &lt;br /&gt;ALTER DATABASE test ADD FILEGROUP [forth] &lt;br /&gt;GO &lt;br /&gt;ALTER DATABASE test ADD FILEGROUP [fifth] &lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;--Adding new files to the filegroups &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;USE [master] &lt;br /&gt;GO &lt;br /&gt;ALTER DATABASE test ADD FILE ( NAME = N'test2', FILENAME = N'C:\Program Files\Microsoft SQL Server\test2.ndf' , SIZE = 2048KB , FILEGROWTH = 1024KB ) TO FILEGROUP [second] &lt;br /&gt;GO&lt;br /&gt;ALTER DATABASE test ADD FILE ( NAME = N'test3', FILENAME = N'C:\Program Files\Microsoft SQL Server\test3.ndf' , SIZE = 2048KB , FILEGROWTH = 1024KB ) TO FILEGROUP [third] &lt;br /&gt;GO &lt;br /&gt;ALTER DATABASE test ADD FILE ( NAME = N'test4', FILENAME = N'C:\Program Files\Microsoft SQL Server\test4.ndf' , SIZE = 2048KB , FILEGROWTH = 1024KB ) TO FILEGROUP [forth] &lt;br /&gt;GO &lt;br /&gt;ALTER DATABASE test ADD FILE ( NAME = N'test5', FILENAME = N'C:\Program Files\Microsoft SQL Server\test5.ndf' , SIZE = 2048KB , FILEGROWTH = 1024KB ) TO FILEGROUP [fifth] &lt;br /&gt;GO &lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;--The following partition function will partition a table or index into four partitions.&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;USE test&lt;br /&gt;GO &lt;br /&gt;CREATE PARTITION FUNCTION [PF_test](int) AS RANGE LEFT FOR VALUES (1,100,1000) &lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;-- Creating partition scheme &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;use test &lt;br /&gt;GO &lt;br /&gt;IF NOT EXISTS (SELECT * FROM sys.partition_schemes WHERE name = N'PS_test') &lt;br /&gt;create PARTITION SCHEME [PS_test] AS PARTITION [PF_test] TO ([second],[third],[forth],[fifth]) &lt;br /&gt;&lt;i&gt;--[Note if you want to have one filegroup for all the files then : create PARTITION SCHEME [PS_test] AS PARTITION [PF_test] All TO ([secondary]) ]&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;--creating table with constraint and assigning a partition scheme to it &lt;/i&gt;&lt;/b&gt; &lt;br /&gt;create table test (dummy [int] primary key constraint test_c check ([dummy] &gt; 0 and [dummy] &lt;=20000)) on ps_test (dummy) &lt;i&gt;&lt;b&gt;--inserting values &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;declare @val int&lt;br /&gt;set @val=1000&lt;br /&gt;while (@val &gt; 0)&lt;br /&gt;begin &lt;br /&gt;insert into test..test values (@val)&lt;br /&gt;set @val=@val-1&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;On Subscriber we will only create the same filegroups and add files to them :&lt;br /&gt;&lt;i&gt;&lt;b&gt;--creating database and filegroups&lt;/b&gt;&lt;/i&gt; &lt;br /&gt;create database test_sub&lt;br /&gt;GO &lt;br /&gt;ALTER DATABASE test_sub ADD FILEGROUP [second] &lt;br /&gt;GO &lt;br /&gt;ALTER DATABASE test_sub ADD FILEGROUP [third] &lt;br /&gt;GO &lt;br /&gt;ALTER DATABASE test_sub ADD FILEGROUP [forth] &lt;br /&gt;GO &lt;br /&gt;ALTER DATABASE test_sub ADD FILEGROUP [fifth] &lt;br /&gt;GO &lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;--Adding new files to the filegroups&lt;/b&gt;&lt;/i&gt; &lt;br /&gt;USE [master] &lt;br /&gt;GO &lt;br /&gt;ALTER DATABASE test_sub ADD FILE ( NAME = N'test_sub2', FILENAME = N'C:\Program Files\Microsoft SQL Server\test_sub_sub2.ndf' , SIZE = 2048KB , FILEGROWTH = 1024KB ) TO FILEGROUP [second] &lt;br /&gt;GO&lt;br /&gt;ALTER DATABASE test_sub ADD FILE ( NAME = N'test_sub3', FILENAME = N'C:\Program Files\Microsoft SQL Server\test_sub_sub3.ndf' , SIZE = 2048KB , FILEGROWTH = 1024KB ) TO FILEGROUP [third] &lt;br /&gt;GO &lt;br /&gt;ALTER DATABASE test_sub ADD FILE ( NAME = N'test_sub4', FILENAME = N'C:\Program Files\Microsoft SQL Server\test_sub_sub4.ndf' , SIZE = 2048KB , FILEGROWTH = 1024KB ) TO FILEGROUP [forth] &lt;br /&gt;GO &lt;br /&gt;ALTER DATABASE test_sub ADD FILE ( NAME = N'test_sub5', FILENAME = N'C:\Program Files\Microsoft SQL Server\test_sub_sub5.ndf' , SIZE = 2048KB , FILEGROWTH = 1024KB ) TO FILEGROUP [fifth] &lt;br /&gt;GO &lt;br /&gt;&lt;br /&gt;Once you are done create the publication on database TEST and the add the article TEST.Once Its done, the Test_Pub Publication is ready to publish.After this we will create the Subscription on this publication .Our subscriber database is test_sub.Once the initial snapshot is synchronized you will see the following values :&lt;br /&gt;&lt;br /&gt;&lt;i&gt;select OBJECT_ID('test..test')&lt;br /&gt;select OBJECT_ID('test_sub..test')&lt;br /&gt;select * from test.sys.partitions where object_id in (2105058535) order by partition_number &lt;br /&gt;select * from test_sub.sys.partitions where object_id in (133575514) order by partition_number &lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-upX0jVSVtBQ/Tga_wONcyoI/AAAAAAAAA28/ngZt5aEhofQ/s1600/untitled5.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="165" width="400" src="http://1.bp.blogspot.com/-upX0jVSVtBQ/Tga_wONcyoI/AAAAAAAAA28/ngZt5aEhofQ/s400/untitled5.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;So as of now everything is as per plan . The data is synchronized in the correct partitions .Now if we need to archive the publisher table we can try the same old approach that we used in stage 1 .However , we will try something new here .That something new is &lt;i&gt;&lt;b&gt;SWITCHING OF PARTITIONS&lt;/b&gt;&lt;/i&gt; in the table .I will not explain what does it means because you will see it in few seconds(or you can refer BOL) .&lt;br /&gt;&lt;br /&gt;&lt;b&gt;--Lets first create the archive table on publisher .Its the replica of the original test table&lt;/b&gt; &lt;br /&gt;create table test..test_archive (dummy [int] primary key constraint test_c_a check ([dummy] &gt; 0 and [dummy] &lt;=20000)) on ps_test (dummy) &lt;b&gt;--Switching the partitions from test to test_archive table on publication&lt;/b&gt;&lt;br /&gt;ALTER TABLE test..test SWITCH PARTITION 1 TO test_archive Partition 1;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;Msg 21867, Level 16, State 1, Procedure sp_MStran_altertable, Line 259&lt;br /&gt;ALTER TABLE SWITCH statement failed. The table '[dbo].[test]' belongs to a publication which does not allow switching of partitions&lt;br /&gt;&lt;br /&gt;Oopsss , What happened...Yes , that is true , we cannot switch the partitions for the replicated table , unless ..........we explicitly allow partition switching for the publisher :&lt;br /&gt;&lt;i&gt;sp_changepublication 'test_pub' ,@property='allow_partition_switch',@value='true'&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;You will get this message&lt;br /&gt;&lt;i&gt;The publication has updated successfully.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;--Switching the partitions from test to test_archive table on publication. This is for partition number 1 . We have 4 partitions.&lt;/b&gt;&lt;br /&gt;ALTER TABLE test..test SWITCH PARTITION 1 TO test_archive Partition 1;&lt;br /&gt;GO&lt;br /&gt;ALTER TABLE test..test SWITCH PARTITION 2 TO test_archive Partition 2;&lt;br /&gt;GO&lt;br /&gt;ALTER TABLE test..test SWITCH PARTITION 3 TO test_archive Partition 3;&lt;br /&gt;GO&lt;br /&gt;ALTER TABLE test..test SWITCH PARTITION 4 TO test_archive Partition 4;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;Now , just check the number of rows in the tables test and test_archive on publisher test and the test table on subscriber test_sub:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-MtXme3Dr0YI/Tga_wPVJy3I/AAAAAAAAA3E/GY0Kk5VTIZY/s1600/untitled6.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="150" width="400" src="http://2.bp.blogspot.com/-MtXme3Dr0YI/Tga_wPVJy3I/AAAAAAAAA3E/GY0Kk5VTIZY/s400/untitled6.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;Thats the magic :)..Did you also notice that we did not create any partitions for the test_archive table .Lets query the syspartition DMV and notice the partitions in test_archive table .&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-TS_3qZHNR_s/Tga_wsXqZDI/AAAAAAAAA3M/vOKhJB0jMCQ/s1600/untitled7.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="214" width="400" src="http://1.bp.blogspot.com/-TS_3qZHNR_s/Tga_wsXqZDI/AAAAAAAAA3M/vOKhJB0jMCQ/s400/untitled7.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;Thats the beauty .&lt;i&gt;You did not have to delete or truncate a single row.Nor did you remove the article or stopped any agent .&lt;/i&gt; Now if you add rows to table TEST it will be replicated to subscriber as usual .lets try this by inserting 1000 rows in table test in the publisher and then check the subscriber table &lt;br /&gt;&lt;b&gt;--inserting new values in test table ( in publisher database )&lt;/b&gt;&lt;br /&gt;declare @val int&lt;br /&gt;set @val=2000&lt;br /&gt;while (@val &gt; 1000)&lt;br /&gt;begin &lt;br /&gt;insert into test..test values (@val)&lt;br /&gt;set @val=@val-1&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-7sflyJeyRF4/Tga_w4HSWlI/AAAAAAAAA3U/bvy4iApVdYQ/s1600/untitled8.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="155" width="400" src="http://2.bp.blogspot.com/-7sflyJeyRF4/Tga_w4HSWlI/AAAAAAAAA3U/bvy4iApVdYQ/s400/untitled8.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Suggestions are welcome as we are here to help each other technicaly grow.Happly learning&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-5301841688261696572?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/5301841688261696572/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=5301841688261696572&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5301841688261696572'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5301841688261696572'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2011/06/replication-archiving-partitioned-and.html' title='Replication :Archiving partitioned and non-Partitioned tables (Without removing the articles from the publications)'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-n4nLHOiYBjI/Tga_idyUQXI/AAAAAAAAA2U/8R6ZOLT66GU/s72-c/untitled.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-2622147044385619700</id><published>2011-06-18T17:23:00.000+05:30</published><updated>2011-06-18T17:23:53.392+05:30</updated><title type='text'>ORA-00942: table or view does not exist .</title><content type='html'>The complete error is :&lt;br /&gt;select  xactts, subguid  from MSrepl7 where pubsrv = ? and pubdb = ? and indagent = 0 and subtype = 0 &lt;br /&gt;ORA-00942: table or view does not exist &lt;br /&gt;&lt;br /&gt;We were setting up heterogeneous replicaton between SQL and Oracle 9i.This was done successfully.But when we tried synchronize the Articles (actually we were replicating only a view)we got stuck at this error.&lt;br /&gt;&lt;br /&gt;It was clear that the error is coming from the subscriber .But we were not replicating the object &lt;b&gt;: &lt;/b&gt;&lt;b&gt;MSrepl7&lt;/b&gt; and we dont know whether this is a table or view .Since we were not replicating it , I was sure that this is a table or view that replication is creating .I saw a KB article which talks about this table for DB2 : http://support.microsoft.com/KB/313332 .&lt;br /&gt;&lt;br /&gt;Later I found from other oracle subscribers that MSrepl7 is nothing but a replica of msreplication_subscriptions table in SQL Server subscribers. This table is looked up and matched with msrepl_transactions .The columns that are compared are transaction_timestamp in MSrepl7 with xact_seqno in msrepl_transactions table .&lt;br /&gt;&lt;br /&gt;moving forward we wanted to find why this table does not exist on the subscriber . I suspected that it should be created while Subscription setup or while we reinitialize subscription or while synchronizing . &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To see if its really being created I enabled tracing on Distribution agent since its this job which is failing . &lt;br /&gt;&lt;b&gt;-Output C:\Temp\OUTPUTFILE.txt -Outputverboselevel 2. &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Ran the Agent again which failed with same error .checked the file: &lt;br /&gt;&lt;br /&gt;&lt;SNIP&gt; &lt;br /&gt;OLE DB Subscriber 'ERPDEV.WORLD': &lt;b&gt;create table MSrepl7&lt;/b&gt; (pubsrv  varchar2 (128), pubdb  varchar2 (128), publcn   varchar2 (128), indagent number (1, 0),subtype number (10, 0), dstagent  varchar2 (100),timecol date,descr  varchar2 (255), xactts raw (16), updmode number (3, 0), agentid  raw (16), subguid  raw (16), subid  raw (16), immsync number (1, 0)) &lt;br /&gt;&lt;br /&gt;Connecting to Distributor 'MCMSMESVS1.distribution' &lt;br /&gt;[4/21/2010 1:32:46 AM]MCMSMESVS1.distribution: {call master..sp_MScheck_agent_instance(N'MCMSMESVS1-MES-ERPDEV.WORLD-1', 10)} &lt;br /&gt;OLE DB Subscriber 'ERPDEV.WORLD': &lt;b&gt;select  xactts, subguid  from MSrepl7 where pubsrv = ? and pubdb = ? and indagent = 0 and subtype = 0 &lt;br /&gt;Agent message code 20046. ORA-00942: table or view does not exist &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;[4/21/2010 1:32:46 AM]MCMSMESVS1.distribution: {call sp_MSadd_distribution_history(1, 6,  ?, ?, 0, 0, 0.00, 0x01, 1, ?, -1, 0x01, 0x01)} &lt;br /&gt;&lt;b&gt;Adding alert to msdb..sysreplicationalerts: ErrorId = 12, &lt;/b&gt;&lt;br /&gt;&lt;/SNIP&gt; &lt;br /&gt;&lt;br /&gt;This means that the table is being created.But its not there .Strange. &lt;br /&gt;&lt;br /&gt;To check whats happening ,I connected to Oracle server and tried to create a test table .... &lt;br /&gt;&lt;br /&gt;&lt;SNIP&gt; &lt;br /&gt;Connected to: &lt;br /&gt;Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production &lt;br /&gt;With the Partitioning, OLAP and Oracle Data Mining options &lt;br /&gt;JServer Release 9.2.0.8.0 - Production &lt;br /&gt;&lt;br /&gt;SQL&gt; create table test(t int); &lt;br /&gt;create table test(t int) &lt;br /&gt;* &lt;br /&gt;ERROR at line 1: &lt;br /&gt;ORA-01031: insufficient privileges &lt;br /&gt;&lt;br /&gt;&lt;/SNIP&gt;&lt;br /&gt;&lt;br /&gt;Looks like when we start synchronizing it does not create sufficient objects at Oracle side due to permission issue .Sadly , SQL also does not throw any errors that we cannot create the object due to permission issue (might not have put the Try catch for this error). &lt;br /&gt;&lt;br /&gt;So,I requested the Oracle DBA in charge of this to give the appropriate permissions to the login that is executing the distribution agent job and execute the Distributor job again . &lt;br /&gt;&lt;br /&gt;BINGO ........the issue was resolved ...hope this blog helps someone someday ..&lt;br /&gt;&lt;br /&gt;Regards&lt;br /&gt;Abhay&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-2622147044385619700?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/2622147044385619700/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=2622147044385619700&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/2622147044385619700'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/2622147044385619700'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2011/06/ora-00942-table-or-view-does-not-exist.html' title='ORA-00942: table or view does not exist .'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-4947468995899529600</id><published>2011-06-18T16:44:00.000+05:30</published><updated>2011-06-18T16:44:29.876+05:30</updated><title type='text'>What should we do first : Try to find the solution or try to find the Problem</title><content type='html'>Had I been asked this question a few years ago , I would have said "I would search for a solution" .&lt;br /&gt;&lt;br /&gt;Most of us do this i.e.we first try to find the solution .Sometimes we succeed but most of the times we do not.After many unsuccessful attempts I realized that the step to find the solution goes through another step first, and that is Finding the problem .Not going deep in to it .&lt;br /&gt;&lt;br /&gt;A couple of months back one of my collegue came to me with a problem " There is a job that fails on every Monday" .This job takes some values from somewhere and inserts it in SQL Server tables.The error was :&lt;br /&gt;&lt;b&gt;Msg 241, Level 16, State 1, Line 2&lt;/b&gt; &lt;br /&gt;&lt;b&gt;Conversion failed when converting datetime from character string.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Earlier ,my collegue explained the client that this is not a SQL issue and suggested the poor client to touch base with the application team .But the client was not a fool .He said that there is some problem in SQL Server and he don't want to go to DEV without proof.He is not a techie though.&lt;br /&gt;&lt;br /&gt;What Should I do , Google it or BING it :-) .we did not do that .&lt;br /&gt;you can see this message in sysmessages . [select * from sys.messages where message_id=241]&lt;br /&gt;&lt;br /&gt;We decided to reproduce the issue and with in 15 mins , we proved that the format in which Date is entered at the application level should be incorrect and datetime datatype is not recognizing it .&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Repro of the issue&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Repro 1&lt;/b&gt;&lt;br /&gt;declare @date datetime ,@string char(100)&lt;br /&gt;select @date =getdate()&lt;br /&gt;set @string =@date&lt;br /&gt;&lt;br /&gt;Command(s) completed successfully.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Repro 2&lt;/b&gt;&lt;br /&gt;declare @date datetime ,@string char(100)&lt;br /&gt;select @date ='28/07/2010'&lt;br /&gt;set @string =@date&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Msg 242, Level 16, State 3, Line 2&lt;br /&gt;The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;So we are near as this error is almost similar to 241 , but not the same.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Repro 3&lt;/b&gt;&lt;br /&gt;declare @date datetime ,@string char(100)&lt;br /&gt;select @date ='2010/07/28'&lt;br /&gt;set @string =@date&lt;br /&gt;&lt;br /&gt;Command(s) completed successfully.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Repro 4&lt;/b&gt;&lt;br /&gt;declare @date datetime ,@string char(100)&lt;br /&gt;select @date =NULL &lt;i&gt;&lt;-- assuming someone might be putting NULL in date and since NULL can be anything, it might not be a CHAR and we will get the error.&lt;/i&gt;&lt;br /&gt;set @string =@date&lt;br /&gt;select @string&lt;br /&gt;Command(s) completed successfully. &lt;-- We did not &lt;b&gt;Repro 5&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;declare @date datetime ,@string char(100)&lt;br /&gt;select @date ='NULL'&lt;br /&gt;set @string =@date&lt;br /&gt;select @string&lt;br /&gt;&lt;br /&gt;Msg 241, Level 16, State 1, Line 2&lt;br /&gt;Conversion failed when converting datetime from character string.&lt;br /&gt;&lt;i&gt;here we got the error .&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Repro 6&lt;/b&gt;&lt;br /&gt;declare @date datetime ,@string char(100)&lt;br /&gt;select @date ='NULL'&lt;br /&gt;&lt;br /&gt;&lt;i&gt;This is more clear &lt;/i&gt;&lt;br /&gt;Msg 241, Level 16, State 1, Line 2&lt;br /&gt;Conversion failed when converting datetime from character string.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;So the reason could be :&lt;/b&gt;&lt;br /&gt;The application adds single quotes to any entry .For example NULL will be converted to 'NULL' and 2010/07/28 will be converted to '2010/07/28' . In this case 'NULL' will give 241 but the date will be absolutely correct and will not throw error when inserted in the table (inside SQL Server).&lt;br /&gt;&lt;br /&gt;Conclusion :&lt;br /&gt;Always try to look for the reason behind the error/issue first rather jumping for solutions here and there .It might take time but you will learn more .&lt;br /&gt;&lt;br /&gt;Regards &lt;br /&gt;Abhay&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-4947468995899529600?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/4947468995899529600/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=4947468995899529600&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4947468995899529600'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4947468995899529600'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2011/06/what-should-we-do-first-try-to-find.html' title='What should we do first : Try to find the solution or try to find the Problem'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-5399294588561434151</id><published>2011-06-18T16:30:00.001+05:30</published><updated>2011-06-18T16:31:55.412+05:30</updated><title type='text'>Immediate Sync option in Transactional Replication : Good or Bad ..</title><content type='html'>Around 4 months back we faced a latency issue in replication. We used tracer tokens and found that the distribution agent was lagging behind .Before I go forward, let me explain you that the distribution agent has 2 threads .Reader thread reads the value from the MSrepl_transactions table (this activity happens in parallel with the log reader agent where the rows are pumped in to the msrepl_transactions table) from distributor database and the writer thread apply those commands to the subscriber . &lt;br /&gt;&lt;br /&gt;To find out where we are getting delayed we configured the verbose logging with level 2 in the distribution agent job (http://support.microsoft.com/kb/312292). In the output we saw that there is a good time gap after the sp_MSget_repl_commands command is fired and the next command .Now this command is fired to read the distribution database and populates the rows in the memory tables .These rows are then read by the writer thread and inserted into the subscriber database.&lt;br /&gt;&lt;br /&gt;In the verbose log you can also check the statistics which is fired every 5 mins (starting SQL Server 2005 ): &lt;br /&gt;•Cumulative Update 12 for SQL Server 2005 Service Pack 2 &lt;br /&gt;•Cumulative Update 5 for SQL Server 2008 &lt;br /&gt;•Cumulative Update 2 for SQL Server 2008 Service Pack 1&lt;br /&gt;&lt;br /&gt;you will see data between these lines &lt;br /&gt;&lt;br /&gt;*************STATISTICS SINCE AGENT STARTED *******************&lt;br /&gt;[data]&lt;br /&gt;***************************************************************************&lt;br /&gt;&lt;br /&gt;It was clear that the  reader thread was taking a lot of time in retrieving the rows as compared to the writer thread writing those commands to the subscriber database .&lt;br /&gt;&lt;br /&gt;The next stage is to check the msrepl_transactions and msrepl_commands tables .We checked the number of rows in those tables and found that there a millions of rows which are replicated but still showing up in the in those tables . This was strange . We checked the cleanup job and found that the job was running fine .&lt;br /&gt;&lt;br /&gt;So whats the issue ? Why the job is not removing the replicated rows ??&lt;br /&gt;upon digging deep , we found that the DBA selected the &lt;b&gt;"Create a snapshot immediately and keep the snapshot available to initialize subscriptions"&lt;/b&gt; option when he configured the replication .As a result Replication is suppose to keep all the transactions cached in the Distribution database for the entire Retention Period.You will also see all the snapshot files in the snapshot folder on the distributor .&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Why it happens :&lt;/b&gt; &lt;br /&gt;Every new subscriber that is added with in the subscription retention period needs the initial snapshot and then the data from the logreader is applied over the snapshot that is accumulated in the distribution database. But the Snapshot gets OLD too as the database image changes from time to time .Therefore every time a new snapshot is needed first. Because of this option set, the same old snapshot is applied first and then all the remaining LogReader entries from the distribution database .That is the reason all the old transactions are kept till the subscription expires.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Why is it configured ?&lt;/b&gt;&lt;br /&gt;This command is configured in the environment where there is a need to create the subscription quite often and also if the snapshot increases in size quite considerab;y over the time .&lt;br /&gt;&lt;br /&gt;&lt;b&gt;How is it configured ?&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Commandline :&lt;/b&gt; &lt;br /&gt;via sp_addpublication &lt;--Check BOLGUI :&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/-tJdnuh5vJDM/TfyEcwJuXVI/AAAAAAAADoQ/zhEuCOndSCY/s1600/immediate_sync.JPG" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="291" width="320" src="http://4.bp.blogspot.com/-tJdnuh5vJDM/TfyEcwJuXVI/AAAAAAAADoQ/zhEuCOndSCY/s320/immediate_sync.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Drawback :&lt;/b&gt; &lt;br /&gt;Due to this option the size of Msrepl_transactions and Msrepl_commands increases ( which is more than normal) which slows up the synchronizations and clogs up the system.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;How to disable it ?&lt;/b&gt;&lt;br /&gt;EXEC sp_changepublication &lt;br /&gt;@publication = 'your_publication_name',&lt;br /&gt;@property = 'immediate_sync', &lt;br /&gt;@value = 'false' &lt;br /&gt;GO &lt;br /&gt;&lt;br /&gt;Happy Learning !!!!!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-5399294588561434151?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/5399294588561434151/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=5399294588561434151&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5399294588561434151'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5399294588561434151'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2011/06/immediate-sync-option-in-transactional.html' title='Immediate Sync option in Transactional Replication : Good or Bad ..'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-tJdnuh5vJDM/TfyEcwJuXVI/AAAAAAAADoQ/zhEuCOndSCY/s72-c/immediate_sync.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-9214416174570190630</id><published>2011-06-18T15:13:00.000+05:30</published><updated>2011-06-18T15:13:14.820+05:30</updated><title type='text'>Address translation: How Virtual Memory is mapped to Physical Memory</title><content type='html'>&lt;b&gt;Introduction&lt;/b&gt;&lt;br /&gt;We all know that data retrieval will be fast if the data pages are found in RAM .If the data pages are not in RAM, they are fetched into RAM from the disk. This causes a physical IO .The page remains in the RAM until it’s again kicked off to Disk.&lt;br /&gt;But the process and threads do not access the Physical memory (RAM) directly .Instead the RAM is accessed indirectly through Virtual Memory or Virtual address space (VAS) pointers. On a x86 operating system the number of such pointers in virtual memory that can point to physical memory is 4,294,967,296 (2^32) .This is equal to 4 GB .Out of this 4GB VAS pointers, 2GB worth of pointers are located in the Kernel address space and remaining 2GB in the User Address Space .It’s this 2GB of user address space which is used by the Processes and threads for their use and to map it to RAM. Other 2GB Kernel Address space is also mapped to RAM for the OS routines and APIs .So, normally on a 32 bit windows OS, SQL Server will use 2GB RAM (1.66GB Buffer Pool region and 384MB Mem2Leave region) .&lt;br /&gt;But what’s the need for Virtual memory when we have Physical memory and it is the real memory .Let me correlate this to a smart Bank. The bank started with $5000.A customer deposited $1000 and the bank will return $1100 after a year .after 1 month, Another customer deposited $2000 for 1 year and the Bank will return $2200 after a year. So the bank has now $8000 for around 2 years .Then someone took a loan of $3000 for 1 year and the bank will get $4000 after a year .In between if the earlier 2 clients want to withdraw their deposit before time, they can pay the penalty and Bank has sufficient money to give back from the initial investment .In reality the banks or the moneylenders keep revolving the money which they might not even have.&lt;br /&gt;&lt;br /&gt;I hope you have some idea now. The OS also works like this .It assures every process 4GB of memory .Right now there are 119 processes running on my laptop .If we go by this fact then the OS is ensuring 476 GB RAM to the processes .But I have only 2GB RAM on this laptop. That’s where the Virtual memory comes into picture .This 476 GB is actually a virtual memory address space and nothing else ; which does physically not exist .OS memory managers maps  this virtual memory to Physical memory (RAM) .During this process the Page file on the disk is also used if a thread needs more physical memory than available .&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-1Hjq2Rhafs0/Tfxx0tNDmWI/AAAAAAAAA10/pQWm0Z1DcFc/s1600/add_tr.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="388" src="http://4.bp.blogspot.com/-1Hjq2Rhafs0/Tfxx0tNDmWI/AAAAAAAAA10/pQWm0Z1DcFc/s400/add_tr.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Let’s skip discussing about AWE, /3GB, /USERVA and PAE for now as it will divert us from the topic which is to know how the Virtual addresses get translated to Physical addresses in RAM.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Address translation&lt;/b&gt; is the process of translating the virtual memory to physical memory.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-xfnGPpHQ2so/TfxzCT2y-8I/AAAAAAAAA18/vE8qK-eS6uU/s1600/add_tr1.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="376" src="http://2.bp.blogspot.com/-xfnGPpHQ2so/TfxzCT2y-8I/AAAAAAAAA18/vE8qK-eS6uU/s400/add_tr1.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Every Virtual Address has 3 components:&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;Page Directory Index :&lt;/b&gt; For each process the OS memory manager creates this directory to use it to map all the page tables for the process.The address of this directory in stored somewhere in the address space called as KProcess Block (Kernal Process Block). To keep this subject less complex I will not explain what Kprocess Block is .The CPU keeps track of this Page Directory Index via a register called as CR3 or Control Register 3 .This Register also resides in KProcess Block .So the CPU’s MMU knows where the Page Directory Index is located with the help of This register (MMU: &lt;b&gt; ttp://en.wikipedia.org/wiki/Memory_management_unit &lt;/b&gt; ).So the first 10 bits of the address space pointer has Page Directory Index value (there are a lot of page directory entries).This tells Windows which page table to use to locate the physical memory&lt;br /&gt;associated with the address.&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;Page Table Index&lt;/b&gt; : The second 10 bits of a 32-bit virtual address provide an index into this table and indicate which page table entry (PTE) contains the address of the page in physical memory to which the virtual address is mapped.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;The Byte Index:&lt;/b&gt; the last 12 bits of a 32-bit virtual address contain the byte offset on the physical memory page to which the virtual address refers. The system page size determines the number of bits required to store the offset. Since the system page size on x86 processors is 4K, 12 bits are required&lt;br /&gt;to store a page offset (4,096 = 2^12).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Let’s summarize it now:&lt;i&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;1. The CPU’s Memory Management Unit locates the page directory for the process using the special register mentioned above.&lt;br /&gt;2. The page directory index (from the first 10 bits of the virtual address) is used to locate the (P)age(D)irectory(E)ntry that identifies the page table needed to map the virtual address to a physical one.&lt;br /&gt;3. The page table index (from the second 10 bits of the virtual address) is used to locate the PTE that maps the physical location of the virtual memory page referenced by the address.&lt;br /&gt;4. The PTE is used to locate the physical page. If the virtual page is mapped to a page that is already in physical memory, the PTE will contain the page frame number (PFN) of the page in physical memory&lt;br /&gt;that contains the data in question. If the page is not in physical memory, the MMU raises a page fault, and the Windows page fault–handling code attempts to locate the page in the system paging file. If the page can be located, it is loaded into physical memory, and the PTE is updated to reflect its location. If it cannot be located and the translation is a user mode translation, an access violation occurs because the virtual address references an invalid physical address. If the page cannot be located and the translation is occurring in kernel mode, a bug check (also called a blue screen) occurs.&lt;br /&gt;&lt;br /&gt;How the Address translation happens with PAE in place:&lt;br /&gt;Everything is same as above except that:&lt;br /&gt;1)There is a new table which is above PDEs and PTEs .Its Page Directory Pointer Table.&lt;br /&gt;2)The PTEs and PDEs are 64 bit wide as compared to 32 bit wide when PAE is not enabled.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-9214416174570190630?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/9214416174570190630/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=9214416174570190630&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/9214416174570190630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/9214416174570190630'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2011/06/address-translation-how-virtual-memory.html' title='Address translation: How Virtual Memory is mapped to Physical Memory'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-1Hjq2Rhafs0/Tfxx0tNDmWI/AAAAAAAAA10/pQWm0Z1DcFc/s72-c/add_tr.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-686878286598497922</id><published>2011-06-18T14:58:00.001+05:30</published><updated>2011-06-18T15:04:47.784+05:30</updated><title type='text'>How to resolve setup errors when registry keys are missing (Failed to install and configure assemblies C:\Program Files (x86)\Microsoft SQL Server\90\NotificationServices\9.0.242\Bin\microsoft.sqlserver.notificationservices.dll in the COM+ catalog)</title><content type='html'>Hi Guys ,&lt;br /&gt;A couple of weeks back we had a setup issue where the SP3 setup was failing on Notification services and Client components .I am sharing my experience with you because it took us a lot of time to figure out that a few registry keys were missing .This explanation has 3 parts viz.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;First Part :&lt;/b&gt; Solution of the issue .&lt;br /&gt;&lt;b&gt;Second Part :&lt;/b&gt; Reproducing this issue and finding a solution in a better way so that the same type of process can be followed for other similar setup issues as well .&lt;br /&gt;&lt;b&gt;Third Part :&lt;/b&gt; 2 bugs (Unfortunately , I could not reproduce it on my machine, but repeatedly reproduced it on clients machine .Will still try on my machine and file them later.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;First Part : Issue and its solution .&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Issue&lt;/b&gt;&lt;br /&gt;As per the Security Bulitin MS09-004 we rasied a change to patch the DEV (and later would be Prod Servers)server to SQL Sevrer 2005 SP3 .Since we were failing on the DEV Server , we were not able to initiate the setup on Prod until the setup on Dev is resolved . Till then the Prod was under potential threat of SQL injection. The issue was that we were not able to upgrade SQL Server 2005 RTM (32 bit) to SQL Server 2005 SP3 (32 bit) on Windows Server 2008 (64 bit) .&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Error Messages&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Setup Errors :&lt;/b&gt;&lt;br /&gt;Failed to install and configure assemblies C:\Program Files (x86)\Microsoft SQL Server\90\NotificationServices\9.0.242\Bin\microsoft.sqlserver.notificationservices.dll in the COM+ catalog.&lt;br /&gt;Error: 2148734209&lt;br /&gt;Error message: Unknown error 0x80131501&lt;br /&gt;Error descrition: MSDTC was unable to read its configuration information. (Exception from HRESULT: 0x8004D027)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Errors in Application log :&lt;/b&gt;&lt;br /&gt;Unable to get the file name for the OLE Transactions Proxy DLL. Error Specifics: hr = 0x8004d027, &lt;br /&gt;d:\rtm\com\complus\dtc\dtc\xolehlp\xolehlp.cpp:176, CmdLine: C:\Windows\syswow64\MsiExec.exe   -Embedding 0E2EA3ADA5DC17201B521333814654B2 C, Pid:  3484&lt;br /&gt;&lt;br /&gt;Failed to read the name of the default transaction manager from the registry. Error Specifics: hr = 0x00000002,   &lt;br /&gt;d:\rtm\com\complus\dtc\dtc\xolehlp\xolehlp.cpp:382, CmdLine: C:\Windows\syswow64\MsiExec.exe -Embedding 0E2EA3ADA5DC17201B521333814654B2 C, Pid: 3484&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Errors in SQL Server :&lt;/b&gt; &lt;br /&gt;QueryInterface failed for "ITransactionDispenser": 0x8004d027(XACT_E_UNABLE_TO_READ_DTC_CONFIG).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Client Environment Details&lt;/b&gt;&lt;br /&gt;SQL Server 2005 RTM 32 bit Standard Edition (WOW mode)&lt;br /&gt;Windows 2008 64 bit Standard &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Troubleshooting done&lt;/b&gt;&lt;br /&gt;-&gt; The setup was failing only for Notification services and Client tools .Rest all components were successfully upgraded to SP3 .&lt;br /&gt;-&gt; Found the Both Notification services and Client tools were failing because of same error :&lt;br /&gt;&lt;br /&gt;---------------------------------------------------------------------------Product                   : Client Components&lt;br /&gt;Product Version (Previous): 1399&lt;br /&gt;Product Version (Final)   : &lt;br /&gt;Status                    : Failure&lt;br /&gt;Log File                  : C:\Program Files (x86)\Microsoft SQL Server\90\Setup Bootstrap\LOG\Hotfix\SQLTools9_Hotfix_KB955706_sqlrun_tools.msp.log&lt;br /&gt;Error Number              : 29549&lt;br /&gt;Error Description         : MSP Error: 29549  Failed to install and configure assemblies c:\Program Files (x86)\Microsoft SQL Server\90\NotificationServices\9.0.242\Bin\microsoft.sqlserver.notificationservices.dll in the COM+ catalog. Error: -2146233087&lt;br /&gt;Error message: Unknown error 0x80131501&lt;br /&gt;Error description: MSDTC was unable to read its configuration information. (Exception from HRESULT: 0x8004D027)&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;---------------------------------------------------------------------------Product                   : Notification Services&lt;br /&gt;Product Version (Previous): 1399&lt;br /&gt;Product Version (Final)   : &lt;br /&gt;Status                    : Failure&lt;br /&gt;Log File                  : C:\Program Files (x86)\Microsoft SQL Server\90\Setup Bootstrap\LOG\Hotfix\SQLTools9_Hotfix_KB955706_sqlrun_tools.msp.log&lt;br /&gt;Error Number              : 29549&lt;br /&gt;Error Description         : MSP Error: 29549  Failed to install and configure assemblies c:\Program Files (x86)\Microsoft SQL Server\90\NotificationServices\9.0.242\Bin\microsoft.sqlserver.notificationservices.dll in the COM+ catalog. Error: -2146233087&lt;br /&gt;Error message: Unknown error 0x80131501&lt;br /&gt;Error description: MSDTC was unable to read its configuration information. (Exception from HRESULT: 0x8004D027)&lt;br /&gt;---------------------------------------------------------------------------&lt;br /&gt;-&gt; Detailed MSP logs showed that the error comes when MSDTC is trying to register the notification services using regsvcs&lt;br /&gt;&lt;b&gt;&lt;snip&gt;&lt;/b&gt;&lt;br /&gt;Error: 2148734209&lt;br /&gt;Error message: Unknown error 0x80131501&lt;br /&gt;Error descrition: MSDTC was unable to read its configuration information. (Exception from HRESULT: 0x8004D027)&lt;br /&gt;Error Code: -2146233087&lt;br /&gt;Windows Error Text:   Source File Name: sqlca\sqlassembly.cpp&lt;br /&gt;Compiler Timestamp: Sat Oct 25 08:47:00 2008&lt;br /&gt;Function Name: Do_sqlAssemblyRegSvcs&lt;br /&gt;Source Line Number: 155&lt;br /&gt;&lt;b&gt;&lt;/SNIP&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;-&gt; So the issue was with registering Notification Services DLL file which was common to both NS and Client components .As you can see RegSvcs was being called from inside the function Do_sqlAssemblyRegSvcs.&lt;br /&gt;&lt;br /&gt;-&gt; We then tried to manually register the microsoft.sqlserver.notificationservices.dll through command prompt :&lt;br /&gt;%windir%\Microsoft.NET\Framework64\v2.0.50727\RegSvcs.exe /fc "C:\Program Files (x86)\Microsoft SQL Server\90\NotificationServices\9.0.242\Bin\microsoft.sqlserver.notificationservices.dll" &lt;br /&gt;&lt;br /&gt;-&gt; This did not work and we were getting some other error .&lt;br /&gt;&lt;br /&gt;-&gt; Since COM+ Catalog was also showing up in the error ,I ran the SQL Server RTM setup and found the the SCC ( System configuration check ) is failing on COM + Catalog  requirements .&lt;br /&gt;-&gt;So,I checked the Component Services (DCOMCNFG) and found that there are no issues there .Everything was working fine .We also noticed that there were no errors related to COM components in the Application logs as well except the error related to MSDTC .The 32 bit COM components were also running fine .This was strange but made me believe that this error might be misleading .&lt;br /&gt;&lt;br /&gt;-&gt; We checked the SQL Sevrer errorlogs and found the same entry related to MSDTC , but in a slightly different manner :&lt;br /&gt;QueryInterface failed for "ITransactionDispenser": 0x8004d027XACT_E_UNABLE_TO_READ_DTC_CONFIG)&lt;br /&gt;&lt;br /&gt;-&gt; We also saw some errors related to MSDTC : &lt;br /&gt;Unable to get the file name for the OLE Transactions Proxy DLL. &lt;br /&gt;Error Specifics: hr = &lt;br /&gt;0x8004d027,d:\rtm\com\complus\dtc\dtc\xolehlp\xolehlp.cpp:176, CmdLine: C:\Windows\syswow64\MsiExec.exe   &lt;br /&gt;-Embedding -E2EA3ADA5DC17201B521333814654B2 C, Pid:  3484&lt;br /&gt;&lt;br /&gt;Failed to read the name of the default transaction manager from the registry. Error Specifics: hr = 0x00000002,   &lt;br /&gt;d:\rtm\com\complus\dtc\dtc\xolehlp\xolehlp.cpp:382, &lt;br /&gt;CmdLine: C:\Windows\syswow64\MsiExec.exe &lt;br /&gt;-Embedding 0E2EA3ADA5DC17201B521333814654B2 C, Pid: 3484&lt;br /&gt;&lt;br /&gt;-&gt; Now the picture was clear that MSDTC had issues for sure. Also the COM+ Catalog warning is related to MSDTC issue (I had resolved the same issue a few years back :&lt;b&gt;http://ms-abhay.blogspot.com/2009/10/msdtc-was-unable-to-read-its.html&lt;/b&gt;. But it was on Win server 2003)&lt;br /&gt;&lt;br /&gt;-&gt; The first error code is same 0x8004d027 but the second error code , which is coming before 0x8004d027 is 0x00000002  is nothing but telling us that there is some registry key missing ( there might be more ) . error 2 means "System cannot find the file specified".&lt;br /&gt;&lt;br /&gt;-&gt; Since we were not sure of which key was missing we decided to uninstall and reinstall MSDTC . This will automatically recreate all the missing registry keys.&lt;br /&gt;&lt;br /&gt;-&gt; But there was some more twist left. On windows Server 2008 we cannot simply uninstall MSDTC by using command "msdtc -uninstall" .We have to remove the MSDTC server role &gt;&gt; reboot the server &gt;&gt; re-add MSDTC in the Server roles.&lt;br /&gt;&lt;br /&gt;-&gt; We tried that ,but even after removing MSDTC from the server role , it was still showing as running in the services console .We tried a few times without success.&lt;br /&gt;&lt;br /&gt;-&gt; In between we also tried to repair .net framework 3.5 SP1 which did not help .&lt;br /&gt;&lt;br /&gt;-&gt; I also went through this article which talks about making sure that all the MSDTC related keys are present in the registry hive:       &lt;br /&gt;http://msdn.microsoft.com/en-us/library/dd300421(v=WS.10).aspx(This was the 1st step towards solution , although it did not work.)&lt;br /&gt;&lt;br /&gt;-&gt; However , the keys mentioned in this article were present in both WOW mode and normal mode in the Registry .&lt;br /&gt;&lt;br /&gt;-&gt; Then on my machine I tried to find the registries with the value "OLETransactionManagers". The first Key hit was : HKEY_CLASSES_ROOT\OLETransactionManagers&lt;br /&gt;&lt;br /&gt;-&gt; Since SQL Server was running in WOW mode on client's server , we tried to find  HKEY_CLASSES_ROOT\Wow6432Node\OLETransactionManagers key and got it in first attempt.&lt;br /&gt;&lt;br /&gt;-&gt; However , on my laptop this key had some values while there were no values on the Client side registry key (mentioned above).&lt;br /&gt;&lt;br /&gt;-&gt; We found that these 64 bit MSDTC registry keys were there but the 32 bit (WOW mode) registry keys related to MSDTC were missing . &lt;br /&gt;&lt;br /&gt;-&gt; We created these keys in WOW mode &lt;br /&gt;&lt;br /&gt;&lt;b&gt; HKEY_CLASSES_ROOT\Wow6432Node\OLETransactionManagers &lt;br /&gt;String value name = DefaultTM and value data=MSDTC&lt;br /&gt;&lt;br /&gt;HKEY_CLASSES_ROOT\Wow6432Node\OLETransactionManagers\MSDTC &lt;br /&gt;String value name=DLL and value data=MSDTCPRX.DLL&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;-&gt;We restarted MSDTC and SQL Server . We checked the SQL Server errorlogs and found that MSDTC related error is no longer showing and also the SQL Server SCC check was not showing that error related to COM+ Catalog any more.&lt;br /&gt;&lt;br /&gt;-&gt;This gave us some hope and with that hope we hoped that the setup will run successfully .This in turn did happen (",).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Second Part: Reproducing the error &lt;/b&gt;&lt;br /&gt;I reproduced this on my machine by removing all the keys from HKEY_CLASSES_ROOT\OLETransactionManagers&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-t6LbYf_muuc/Tfxm4lT9ihI/AAAAAAAAA0U/9F_0IcWB_7c/s1600/1.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="106" width="400" src="http://2.bp.blogspot.com/-t6LbYf_muuc/Tfxm4lT9ihI/AAAAAAAAA0U/9F_0IcWB_7c/s400/1.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;When I ran the setup it gave me the same warnings on SCC :&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-L5JOHtC5Np4/TfxmXgQeYWI/AAAAAAAAAz0/Dqlk2mZM6xI/s1600/2.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="346" width="379" src="http://3.bp.blogspot.com/-L5JOHtC5Np4/TfxmXgQeYWI/AAAAAAAAAz0/Dqlk2mZM6xI/s400/2.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-oE5FpEI3IbI/TfxmX9E-BsI/AAAAAAAAAz8/1NGQ2qz3mYI/s1600/2_1.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="205" width="365" src="http://4.bp.blogspot.com/-oE5FpEI3IbI/TfxmX9E-BsI/AAAAAAAAAz8/1NGQ2qz3mYI/s400/2_1.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;I will still go ahead with the setup and select only the client components to install :&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-H701VzZxp6Y/TfxmYPi32eI/AAAAAAAAA0E/8VsbSiRk1Xo/s1600/3.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="370" width="400" src="http://2.bp.blogspot.com/-H701VzZxp6Y/TfxmYPi32eI/AAAAAAAAA0E/8VsbSiRk1Xo/s400/3.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The setup will encounter this error:&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-HE68_oupJEs/TfxmYU_SHjI/AAAAAAAAA0M/XcxkgoMbGkg/s1600/4.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="126" width="400" src="http://2.bp.blogspot.com/-HE68_oupJEs/TfxmYU_SHjI/AAAAAAAAA0M/XcxkgoMbGkg/s400/4.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Let’s check the Application logs:&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-CY2hxvvh4ec/TfxnPQVYlnI/AAAAAAAAA0c/TxjLCbjzGtU/s1600/5.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="354" src="http://4.bp.blogspot.com/-CY2hxvvh4ec/TfxnPQVYlnI/AAAAAAAAA0c/TxjLCbjzGtU/s400/5.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;At this stage First let me introduce a tool that can show you how to find the missing registry key or if there are any permission related issues .I have been using this tool since long now .This tool is Procmon from sysinternals &lt;b&gt;http://technet.microsoft.com/en-us/sysinternals/bb896645"&lt;/b&gt;.We will use this tool to find the missing registry keys .However this tool captures a lot of information of all the processes .So we need to first PAUSE it as soon as we launch it .&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-_oo5WFo5Whs/TfxnPv-HG5I/AAAAAAAAA0k/N_GZg-9ngFg/s1600/6.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="81" width="400" src="http://4.bp.blogspot.com/-_oo5WFo5Whs/TfxnPv-HG5I/AAAAAAAAA0k/N_GZg-9ngFg/s400/6.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Now, we will find the process ID of MSIEXEC.exe from Task Manager since as per the Application logs its the msiexec command that is failing:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-Op0OBZNLS-s/TfxnP-2XMGI/AAAAAAAAA0s/kbXGjWgcXuw/s1600/7.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="388" src="http://1.bp.blogspot.com/-Op0OBZNLS-s/TfxnP-2XMGI/AAAAAAAAA0s/kbXGjWgcXuw/s400/7.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;I will now filter it on those 3 PIDs&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-8wDQh2aq1Gg/TfxnQXCEJqI/AAAAAAAAA00/SIm_xEsR6h0/s1600/8.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="73" width="400" src="http://4.bp.blogspot.com/-8wDQh2aq1Gg/TfxnQXCEJqI/AAAAAAAAA00/SIm_xEsR6h0/s400/8.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-YioAWph9Hmw/TfxnRPn3o9I/AAAAAAAAA08/8wGFm9mDCkE/s1600/9.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="251" width="400" src="http://2.bp.blogspot.com/-YioAWph9Hmw/TfxnRPn3o9I/AAAAAAAAA08/8wGFm9mDCkE/s400/9.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Once it’s done, uncheck the PAUSE icon (the magnifying glass) and click on the retry option on the setup window. Quickly after that ,again PAUSE the Procmon by clicking on the magnifying glass icon. Notice the output in the Procmon. You will see a lot of different keys there .We now need to delete not necessary entries:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-CdN-DJvvQb4/TfxnlBr9KRI/AAAAAAAAA1E/61Bohxn5y_A/s1600/10.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="251" width="400" src="http://4.bp.blogspot.com/-CdN-DJvvQb4/TfxnlBr9KRI/AAAAAAAAA1E/61Bohxn5y_A/s400/10.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Right click on SUCCESS and select:&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-OHGVCwn2CaI/TfxnlAr-UHI/AAAAAAAAA1M/RHW5w5aLlp0/s1600/11.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="208" width="173" src="http://1.bp.blogspot.com/-OHGVCwn2CaI/TfxnlAr-UHI/AAAAAAAAA1M/RHW5w5aLlp0/s400/11.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Right click on RegOpenKey and select:&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-V1_vbVi3na4/TfxnlQxiY_I/AAAAAAAAA1U/gEtEP82lgeE/s1600/12.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="208" width="198" src="http://2.bp.blogspot.com/-V1_vbVi3na4/TfxnlQxiY_I/AAAAAAAAA1U/gEtEP82lgeE/s400/12.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;You are now left with only 6 keys to look at(You can follow the same steps for other missing Reg keys issues ) and all these keys are REGQueryValue:&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-CFMFiayLHYM/Tfxnlj7TAdI/AAAAAAAAA1c/tP4cWLRHhsQ/s1600/13.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="45" width="400" src="http://4.bp.blogspot.com/-CFMFiayLHYM/Tfxnlj7TAdI/AAAAAAAAA1c/tP4cWLRHhsQ/s400/13.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Now ,notice the error copied above from application log:&lt;br /&gt;*******&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-Vs4Qa2C8XG8/TfxuMlsNvoI/AAAAAAAAA1s/msIc8ms_Ytc/s1600/15.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="31" width="307" src="http://2.bp.blogspot.com/-Vs4Qa2C8XG8/TfxuMlsNvoI/AAAAAAAAA1s/msIc8ms_Ytc/s400/15.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Now, double click on each of the 6 keys (start from the bottom most) and select the option &gt;&gt; PROCESS. You will notice the same command line string as showing in the application logs:&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-s3k_78mrtMM/Tfxnl0woC9I/AAAAAAAAA1k/TJ6gwk06JvE/s1600/14.JPG" imageanchor="1" style="margin-left:1em; margin-right:1em"&gt;&lt;img border="0" height="400" width="344" src="http://2.bp.blogspot.com/-s3k_78mrtMM/Tfxnl0woC9I/AAAAAAAAA1k/TJ6gwk06JvE/s400/14.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;So the first key that is missing is &lt;b&gt;HKCR\OLETransactionManagers\DefaultTM&lt;/b&gt; .The reason it’s not showing all the missing keys is because it’s failing on first key itself. If you create the first key and then click on retry button on the setup the Procmon will show you the next missing key.&lt;br /&gt;&lt;br /&gt;But what should be its value .We can check on other servers (preferably same server version).Create the missing keys and click on retry button .The setup will be successful (in our case it was SP3 and not the initial setup .But the resolution is same).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Third part : The Bugs&lt;/b&gt;&lt;br /&gt;1) The issue is , when the SP3 setup fails it should ideally rollback everything to normal .So the NS and client tools should work fine.But On the client's server we saw that the Management Studio stop working and throws an error ( I dont have the screenshot now . Will try and reproduce it ) . The only solution is to uninstall the client tools and reinstall again .During the setup you will again get this error .Click on ignore and the setup will complete .&lt;br /&gt;&lt;br /&gt;2) On my laptop , I saw that it also corrupt other components of SQL Server 2008 like Books on Line ..Again I do not have that proof now but will reproduce it .The solution is to uninstall client tools and reinstall tools of SQL Server 2008.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Happy Learning !!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-686878286598497922?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/686878286598497922/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=686878286598497922&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/686878286598497922'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/686878286598497922'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2011/06/how-to-resolve-setup-errors-when.html' title='How to resolve setup errors when registry keys are missing (Failed to install and configure assemblies C:\Program Files (x86)\Microsoft SQL Server\90\NotificationServices\9.0.242\Bin\microsoft.sqlserver.notificationservices.dll in the COM+ catalog)'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/-t6LbYf_muuc/Tfxm4lT9ihI/AAAAAAAAA0U/9F_0IcWB_7c/s72-c/1.JPG' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-1784383926619261278</id><published>2011-06-18T14:04:00.000+05:30</published><updated>2011-06-18T14:04:25.311+05:30</updated><title type='text'>Understanding how SQL Server behaves in a non-preemptive mode while still running on the OS which is preemptive</title><content type='html'>Today , I was asked by someone how SQL Server behaves in a non-preemptive way while still running on the OS which is preemptive .Even though I explained this theoritically ,I was requested if there is a way we can see it practically . It wasn't difficult but it really proved to what I explained .I alos felt that if we add practicals to theory it will have much deeper impact ...&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NOTE : I am doing all the testing on SQL Server 2008 RTM EVAL as what I am trying to explain can be done in 2008 onwards.On 2005 you will not see what is written here.So I would request to use SQL 2008 and above .&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt; Windows Scheduling (Preemptive) :&lt;/b&gt; &lt;br /&gt;Starting from Windows NT 3.1 (XP ,2000,2003 etc) Windows scheduling was priority driven i.e preemptive scheduling .So every thread will have a priority associated with it .Based on this  priority the threads will get the time slice (Quantum) to run on the CPU  .So , even if thread of lower priority is running and all of a sudden another thread of a higher  &lt;br /&gt;priority  comes up , the low priority thread will be preempted interrupted) and the higher priority thread will be scheduled to run on the CPU.However , the scheduler is smart enough .It will keep the preempted thread on the top of the waiting threads by adjusting its priority (Lets not get too deep in to this at this point). &lt;br /&gt;&lt;br /&gt;Prior to this OS scheduling was non-preemptive i.e. cooperative scheduling .Remember the days when Windows 98 use to hang and we use to reboot the server quite often ,to get rid of it.Cooperative scheduling is good if all the threads leave the CPU after some time and give chance to other threads (including kernal mode threads which are more &lt;br /&gt;Important and get a chance to run whenever required) after a fixed interval of time . But that normally does not happen .some nasty application threads don't yield and hence blocks other threads.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;SQL Server Scheduling (non-preemptive) :&lt;/b&gt; &lt;br /&gt;SQL Server has its own scheduling mechanism and it does not follow OS scheduling (looks strange as it runs on the preemptive OS) .Its called as UMS (User Mode Scheduling) in 2000 and SOS (SQL OS) in 2005 and above .BUT :&lt;br /&gt;&lt;b&gt;1) Why SQL Server does not hang just like windows 98 use to ?&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Answer:&lt;/b&gt; SQL Server does not hang because its threads yield every voluntarily.In case a thread does not yield in 60 seconds (unlike the faulty application where the threads does not yield)SQL Server throws non-yielding scheduler hung error and throws a mini dump with the stack information of all the threads in it .&lt;br /&gt;&lt;br /&gt;&lt;b&gt;2) How SQL Server manages to schedule in the non-preemptive way ?&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Answer: &lt;/b&gt;Windows OS will not schedule any thread which is running in infinite wait loop and simply ignores it. SQL Server (actually UMS) takes advantage of this and cleverly puts all the threads which it does not want to schedule to infinitely sleep by calling WaitforsingleObject function in an infinite loop .When SQL Server wants the thread to run it simply signal the thread and it comes out of the sleep modes .Its the Windows which then schedules the thread .Its important to know that UMS schedules only ONE SQl Server thread per CPU .However , there is an exception to this . There are moments where to complete a task the thread leaves the SQL Server scheduler and goes to preemptive mode scheduling . For example using xp_cmdshell to open notepad or running an extended stored procedure that deals with filesystem (like reading a file) or a linked server query &lt;br /&gt;etc.In that situation , you will see more than one thread on a single CPU in runnable status .That is because one thread is scheduled via UMS\SOS and the other one directly via OS scheduling.&lt;br /&gt;&lt;br /&gt;Let me show you a Demo since my Laptop has only one dual core processor (Its SQL Server 2008 RTM):&lt;br /&gt;&lt;b&gt;Lets first run a simple query and find runnable and sleeping threads &lt;/b&gt; &lt;i&gt;Select Status ,* from sysprocesses where status not in ('background')&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;you will notice that all the SPIDS will show you the status of &lt;b&gt;sleeping&lt;/b&gt; and there is only one SPID that will be showing you the status of &lt;b&gt;runnable&lt;/b&gt; .Its waittype will be &lt;b&gt;PREEMPTIVE_os_WAITFORSINGLEOBJECT&lt;/b&gt; .Notice that only runnable SPID has a KPID associated with it .This KPID is nothing but the worker thread associated with the SPID.You can run it a few times but the output will not change except the KPID which means that one thread is yielding to another after the context switching .The reason why we see runnable state and not running ,because by the time we get the query output the thread again goes to runnable state.You might also see other runnable or suspended SPIDs but its because they are running in preemptive mode .&lt;br /&gt;&lt;br /&gt;Now lets open another Query window and execute the same command there .&lt;br /&gt;&lt;b&gt;Select Status ,* from sysprocesses where status not in ('background')&lt;/b&gt;. This time its SPID 53 (current SPID on my machine) which is showing us the Runnable state while SPID 52 (the previous SPID)is now sleeping .&lt;br /&gt;&lt;br /&gt;Lets do one more experiment.Open a new query window (SPID 51 in my case) and run select @@servicename around 1000 times . Come back to SPID 53 window and notice if the runnable state is showing for SPID 53 or SPID 51.You will notice that we have the SPID 51 doing its task .But why is it showing as sleeping while CPU value is still increasing ? The reason is that when we run the query via SPID 53 , during (and only) that time 51 shows as sleeping because 53 needs to run . So thread related to 51 yields voluntarily. when this query finishes , SPID 51 again picks up , but we cant see that since we have only one processor :) ...&lt;br /&gt;&lt;br /&gt;Anyway , let me show you the small test when the SQL Server thread goes preemptive .We have 2 Query windows.One with sysprocesses query (SPID 53)  and one with calling xp_readerrorlog 100 times (SPID 51).I further modified my sysprocesses query by filtering sleeping SPIDs.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Select Status ,* from sysprocesses where status not in ('background','sleeping')&lt;/b&gt; .Lets run the query through SPID 51 and then by SPID 53.Notice that you have 2 runnable SPIDs now . Thats because SPID 51 is scheduled by OS and not SQL OS \UMS .&lt;br /&gt;&lt;br /&gt;Have a nice day and Happy Learning !!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-1784383926619261278?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/1784383926619261278/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=1784383926619261278&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1784383926619261278'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1784383926619261278'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2011/06/understanding-how-sql-server-behaves-in.html' title='Understanding how SQL Server behaves in a non-preemptive mode while still running on the OS which is preemptive'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-7219538144384226741</id><published>2011-04-27T13:23:00.000+05:30</published><updated>2011-04-27T13:23:12.516+05:30</updated><title type='text'>Finding optimal number of CPUs for a given long running CPU intensive queries (except OLAP queries)</title><content type='html'>Hi Guys ,&lt;br /&gt;&lt;br /&gt;Hope this article will help you in some or the other way one day :) .....&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Introduction:&lt;/b&gt;&lt;br /&gt;This small article is applicable for finding optimal number of CPUs for long running CPU intensive queries/workload that doesn’t frequently wait for other resources  and is not applicable if your queries/workload is often waiting for resources (like I/Os, Locks, Latches etc.) without consuming CPU in a stretch .it can also provide information on uneven CPU load across NUMA nodes and uneven CPU load within same NUMA node (load_factor effect).&lt;br /&gt;It is recommended to analyze Windows Performance Monitor Counters for monitoring CPU pressure. Processor utilization greater then 75% to 80% indicates CPU pressure. Using Windows Performance Monitor should be the 1st step, the procedure suggested in this article should be considered as an additional step.&lt;br /&gt;Further ,it is very important to find ways to optimize the queries/workload by tuning the database schema before attempting to add additional CPUs.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Description:&lt;/b&gt;&lt;br /&gt;When a customer asks you: I am running a resource consuming SQL job and it takes x amount of time, how can I reduce the time so the SQL job completes sooner, can I add more CPUs ? if yes, how many ?&lt;br /&gt;When you see CPU pressure, there are 2 options: you can either upgrade to faster CPUs or add additional CPUs [assuming that the queries are well tuned and normalized]. Upgrading to faster CPU will always help. Adding additional CPUs may not always help the SQL job to run faster unless that SQL job can take advantage of additional CPUs [read Max Degree of parallelism form BOL]. If the customer already has the fastest CPUs available in the market then they have to wait for the next release of faster CPUs. One more choice woiuld be to add additional CPUs and see if it helps, the below procedure will help you identify if this is the case.&lt;br /&gt;This method calculates total user waits for CPU during the SQL workload and suggests additional CPUs if necessary. If CPU usage is at 100%, but no one waited for CPU during the workload, then adding additional CPU will not help; this is the basics of this calculation.&lt;br /&gt;Current recommendations that are available on this topic calculates ‘signal wait time’ to ‘wait time’ ratio to suggest CPU pressure – but this cannot help one easily identify number of additional CPUs necessary.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Procedure:&lt;/b&gt;&lt;br /&gt;When concurrent users apply simultaneous CPU intensive workload, there could be CPU pressure. We can conclude presence of CPU pressure when at any given moment during this time period at least one or more user tasks waited for CPU resource.&lt;br /&gt;In this case one can run the below query to find out how many CPU on an average will help to scale(out) the workload better. It might be more informative to collect the below information in short time intervals (many samples) than just once to understand during which time of the workload application the CPU pressure was the most. Single sample will lead to average additional CPUs necessary for the entire workload duration.&lt;br /&gt;1. Reset Wait Stats&lt;br /&gt;dbcc sqlperf('sys.dm_os_wait_stats', clear)&lt;br /&gt;2. Apply workload (you can find sample workload query at the end of this article, you need to execute the sample workload query simultaneously in many sessions to simulate concurrent user tasks).&lt;br /&gt;3. Run the below query to find Additional CPUs Necessary – it is important to run the query right after the workload completes to get reliable information.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;select round(((convert(float, ws.wait_time_ms) / ws.waiting_tasks_count) / (convert(float, si.os_quantum) / si.cpu_ticks_in_ms) * cpu_count), 2) as Additional_CPUs_Necessary,&lt;br /&gt;round((((convert(float, ws.wait_time_ms) / ws.waiting_tasks_count) / (convert(float, si.os_quantum) / si.cpu_ticks_in_ms) * cpu_count) / hyperthread_ratio), 2) as Additional_Sockets_Necessary&lt;br /&gt;from sys.dm_os_wait_stats ws cross apply sys.dm_os_sys_info si where ws.wait_type = 'SOS_SCHEDULER_YIELD' &lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;b&gt;Example:&lt;/b&gt;&lt;br /&gt;When you have 2 CPUs and you run the sample workload with just 1 or 2 concurrent sessions – you will see no recommendation for addition additional CPUs – unless there is unbalanced user task distribution across CPUs. On the other hand if you run the workload with 4 concurrent sessions – you will notice the query suggests you to add 2 additional CPUs. If you run with 6 concurrent sessions – you will notice the query suggests you to add 4 additional CPUs.&lt;br /&gt;If each workload runs in parallel (MAXDOP not 1), then you will notice additional CPU suggestion, you need to be careful in this case. For example with 2 CPUs when you run the workload (in parallel, MAXDOP 0/2) with 2 concurrent sessions, you will notice the suggestion to add 2 additional CPUs – this just indicates the workload is more scalable with more CPUs – parallel query execution as you can imagine can consume as many CPUs as you have and can consume more!!&lt;br /&gt;The results are not reliable when other applications are running in the system. Also the results might be incorrect on a hyper threading enabled system.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Explanation:&lt;/b&gt;&lt;br /&gt;When there are more user tasks concurrently needing CPU than available CPU, the excess user tasks will wait for CPU (there are exceptions when the workload is not evenly distributed across CPUs). In this case each user task uses its quantum, then goes into a wait state (waiting for CPU with wait_type SOS_SCHEDULER_YIELD. sys.dm_exec_requests doesn’t show this wait type, probably by design to avoid showing user tasks in wait state when they are waiting for CPU. But sys.dm_os_wait_stats will include these waits) until all other runnable user tasks have used their quantum. If one measures how many tasks went into this wait state and for how long while the workload was applied – it is possible to calculate the CPUs necessary to scale the workload better.&lt;br /&gt;runnabkle_task_count from the dm_os_schedulers is also a indication for CPU pressure, but it is just a probe – one cannot reasonably conclude the number of CPUs necessary for a given workload.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Exception:&lt;/b&gt;&lt;br /&gt;There is an exception(for OLTP like workload) where a user tasks doesn’t consume all of its quantum(goes into some other wait state before the quantum expires, waiting for I/Os, Locks, Latches etc.) in a stretch, but continues to run in a loop using CPU without using its full quantum(You know what quantum is ...right :D). The method mentioned here cannot calculate the necessary additional CPUs in this case.. Most common example is short transactions using part of its quantum and starts WRITELOG waits and continues in a loop – inserts using implicit transactions in a loop is a typical example.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Sample Workload:&lt;/b&gt;&lt;br /&gt;Create the below table before running the query to generate CPU intensive workload.&lt;br /&gt;&lt;i&gt;Serial Workload: &lt;/i&gt;&lt;br /&gt;select max(t1.c2 + t2.c2) from tab7 t1 cross join tab7 t2 option (maxdop 1)&lt;br /&gt;&lt;i&gt;Parallel Workload: &lt;/i&gt;&lt;br /&gt;select max(t1.c2 + t2.c2) from tab7 t1 cross join tab7 t2  &lt;br /&gt;&lt;i&gt;Table:&lt;/i&gt;&lt;br /&gt;create table tab7 (c1 int primary key clustered, c2 int, c3 char(2000))&lt;br /&gt;go&lt;br /&gt;begin tran&lt;br /&gt;declare @i int&lt;br /&gt;set @i = 1&lt;br /&gt;while @i &lt;= 5000&lt;br /&gt;begin&lt;br /&gt;insert into tab7 values (@i, @i, 'a')&lt;br /&gt;set @i = @i + 1&lt;br /&gt;end&lt;br /&gt;commit tran&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Happy Learning !!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-7219538144384226741?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/7219538144384226741/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=7219538144384226741&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/7219538144384226741'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/7219538144384226741'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2011/04/finding-optimal-number-of-cpus-for.html' title='Finding optimal number of CPUs for a given long running CPU intensive queries (except OLAP queries)'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-6968788743529328903</id><published>2010-11-09T22:19:00.000+05:30</published><updated>2010-11-09T22:19:50.227+05:30</updated><title type='text'>SQL Server Setup has encountered the following error:File format is not valid</title><content type='html'>Today , we faced an issue where SQL Server 2008 R2 setup was failing at the very beginning .This issue can also be reproduced on 2008 and also in 2005 (in a slightely different way) .Please find the RCA below  :&lt;br /&gt;&lt;br /&gt;Version : SQL Server 2008 R2 &lt;br /&gt;OS : Win Server 2008&lt;br /&gt;&lt;br /&gt;Error : &lt;br /&gt;TITLE: SQL Server Setup failure.&lt;br /&gt;------------------------------&lt;br /&gt;SQL Server Setup has encountered the following error:&lt;br /&gt;File format is not valid..&lt;br /&gt;------------------------------&lt;br /&gt;BUTTONS:&lt;br /&gt;OK&lt;br /&gt;------------------------------&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Resolution :&lt;/b&gt; &lt;br /&gt;Its very clear that there is a file that does not have a correct format and SQL Server cannot read it .So we need to find which file is that  .We need to first open the Setup logs .In SQL 2008 a folder is created with the timstamp and all the logs are created inside it .On my machine it was C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20101109_201205 .&lt;br /&gt;&lt;br /&gt;I first opened Detail_ComponentUpdate.txt &lt;br /&gt;&lt;br /&gt;2010-11-09 20:13:14 Slp: Running Action: GatherUserSettings&lt;br /&gt;2010-11-09 20:13:21 Slp: -- PidPublicConfigObject : ValidateSettings is normalizing input pid=[PID value hidden]&lt;br /&gt;2010-11-09 20:13:21 Slp: -- PidPrivateConfigObject : NormalizePid is normalizing input pid=[PID value hidden]&lt;br /&gt;2010-11-09 20:13:21 Slp: -- PidPrivateConfigObject : NormalizePid found a pid containing dashes, assuming pid is normalized, output pid=[PID value hidden]&lt;br /&gt;2010-11-09 20:13:21 Slp: -- PidPublicConfigObject : ValidateSettings proceeding with normalized pid=[PID value hidden]&lt;br /&gt;2010-11-09 20:13:21 Slp: -- PidPrivateConfigObject : Initialize is initializing using input pid=[PID value hidden]&lt;br /&gt;2010-11-09 20:13:21 Slp: -- PidPrivateConfigObject : NormalizePid is normalizing input pid=[PID value hidden]&lt;br /&gt;2010-11-09 20:13:21 Slp: -- PidPrivateConfigObject : NormalizePid found a pid containing dashes, assuming pid is normalized, output pid=[PID value hidden]&lt;br /&gt;2010-11-09 20:13:21 Slp: -- PidPrivateConfigObject : Initialize proceeding with normalized pid=[PID value hidden]&lt;br /&gt;2010-11-09 20:13:21 Slp: -- PidPrivateConfigObject : Initialize called ValidatePid, output is pid=[PID value hidden] validateSuccess=True output editionId=EVAL(0x2467BCA1)&lt;br /&gt;2010-11-09 20:13:21 Slp: -- PidPublicConfigObject : ValidateSettings initialized private object, result is initializeResult=Success&lt;br /&gt;&lt;b&gt;&lt;br /&gt;2010-11-09 20:13:22 Slp: Detected localization resources folder: 1033&lt;br /&gt;2010-11-09 20:13:22 Slp: License file: C:\Documents and Settings\Abhay\Desktop\2008 R2 X64\2008_R2_x86\x86\1033\License_EVAL.rtf&lt;br /&gt;2010-11-09 20:13:22 Slp: Error: Action "GatherUserSettings" threw an exception during execution.&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;2010-11-09 20:13:22 Slp: Microsoft.SqlServer.Setup.Chainer.Workflow.ActionExecutionException: Thread was being aborted. ---&gt; System.Threading.ThreadAbortException: Thread was being aborted.&lt;br /&gt;2010-11-09 20:13:22 Slp:    at System.Threading.WaitHandle.WaitOneNative(SafeWaitHandle waitHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)&lt;br /&gt;2010-11-09 20:13:22 Slp:    at System.Threading.WaitHandle.WaitOne(Int64 timeout, Boolean exitContext)&lt;br /&gt;2010-11-09 20:13:22 Slp:    at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)&lt;br /&gt;2010-11-09 20:13:22 Slp:    at System.Threading.WaitHandle.WaitOne()&lt;br /&gt;2010-11-09 20:13:22 Slp:    at Microsoft.SqlServer.Configuration.UIExtension.Request.Wait()&lt;br /&gt;2010-11-09 20:13:22 Slp:    at Microsoft.SqlServer.Configuration.UIExtension.UserInterfaceProxy.SubmitAndWait(Request request)&lt;br /&gt;2010-11-09 20:13:22 Slp:    at Microsoft.SqlServer.Configuration.UIExtension.UserInterfaceProxy.NavigateToWaypoint(String moniker)&lt;br /&gt;2010-11-09 20:13:22 Slp:    at Microsoft.SqlServer.Configuration.UIExtension.UserInterfaceService.Waypoint(String moniker)&lt;br /&gt;2010-11-09 20:13:22 Slp:    at Microsoft.SqlServer.Configuration.UIExtension.WaypointAction.ExecuteAction(String actionId)&lt;br /&gt;2010-11-09 20:13:22 Slp:    at Microsoft.SqlServer.Chainer.Infrastructure.Action.Execute(String actionId, TextWriter errorStream)&lt;br /&gt;2010-11-09 20:13:22 Slp:    at Microsoft.SqlServer.Setup.Chainer.Workflow.ActionInvocation.InvokeAction(WorkflowObject metabase, TextWriter statusStream)&lt;br /&gt;2010-11-09 20:13:22 Slp:    at Microsoft.SqlServer.Setup.Chainer.Workflow.PendingActions.InvokeActions(WorkflowObject metaDb, TextWriter loggingStream)&lt;br /&gt;2010-11-09 20:13:22 Slp:    --- End of inner exception stack trace ---&lt;br /&gt;2010-11-09 20:13:22 Slp:    at Microsoft.SqlServer.Setup.Chainer.Workflow.PendingActions.InvokeActions(WorkflowObject metaDb, TextWriter loggingStream)&lt;br /&gt;2010-11-09 20:13:25 Slp: Received request to add the following file to Watson reporting: C:\Documents and Settings\Abhay\Local Settings\Temp\tmp11E.tmp&lt;br /&gt;2010-11-09 20:13:25 Slp: The following is an exception stack listing the exceptions in outermost to innermost order&lt;br /&gt;2010-11-09 20:13:25 Slp: Inner exceptions are being indented&lt;br /&gt;2010-11-09 20:13:25 Slp: &lt;br /&gt;2010-11-09 20:13:25 Slp: Exception type: System.ArgumentException&lt;br /&gt;2010-11-09 20:13:25 Slp:     Message: &lt;br /&gt;2010-11-09 20:13:25 Slp:         File format is not valid.&lt;br /&gt;2010-11-09 20:13:25 Slp:     Stack: &lt;br /&gt;2010-11-09 20:13:25 Slp:         at System.Windows.Forms.RichTextBox.StreamIn(Stream data, Int32 flags)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at System.Windows.Forms.RichTextBox.LoadFile(Stream data, RichTextBoxStreamType fileType)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at System.Windows.Forms.RichTextBox.LoadFile(String path, RichTextBoxStreamType fileType)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at Microsoft.SqlServer.Configuration.InstallWizard.EULAPidView.UpdateLicenseText(String filepath)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at Microsoft.SqlServer.Configuration.InstallWizard.EULAPidController.LoadData()&lt;br /&gt;2010-11-09 20:13:25 Slp:         at Microsoft.SqlServer.Configuration.InstallWizardFramework.InstallWizardPageHost.PageEntered(PageChangeReason reason)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at Microsoft.SqlServer.Configuration.WizardFramework.UIHost.set_SelectedPageIndex(Int32 value)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at Microsoft.SqlServer.Configuration.WizardFramework.UIHost.GoNext()&lt;br /&gt;2010-11-09 20:13:25 Slp:         at Microsoft.SqlServer.Configuration.WizardFramework.NavigationButtons.nextButton_Click(Object sender, EventArgs e)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at System.Windows.Forms.Control.OnClick(EventArgs e)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at System.Windows.Forms.Button.OnClick(EventArgs e)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at System.Windows.Forms.Control.WmMouseUp(Message&amp; m, MouseButtons button, Int32 clicks)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at System.Windows.Forms.Control.WndProc(Message&amp; m)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at System.Windows.Forms.ButtonBase.WndProc(Message&amp; m)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at System.Windows.Forms.Button.WndProc(Message&amp; m)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)&lt;br /&gt;2010-11-09 20:13:25 Slp:         at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)&lt;br /&gt;2010-11-09 20:28:33 Slp: Sco: Attempting to write hklm registry key SOFTWARE\Microsoft\Microsoft SQL Server to file C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20101109_201205\Registry_SOFTWARE_Microsoft_Microsoft SQL Server.reg_&lt;br /&gt;2010-11-09 20:28:33 Slp: Sco: Attempting to write hklm registry key SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall to file C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20101109_201205\Registry_SOFTWARE_Microsoft_Windows_CurrentVersion_Uninstall.reg_&lt;br /&gt;2010-11-09 20:28:33 Slp: Sco: Attempting to write hklm registry key SOFTWARE\Microsoft\MSSQLServer to file C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\20101109_201205\Registry_SOFTWARE_Microsoft_MSSQLServer.reg_&lt;br /&gt;&lt;b&gt;2010-11-09 20:28:36 Slp: File format is not valid.&lt;/b&gt;&lt;br /&gt;2010-11-09 20:28:36 Slp: Watson bucket for exception based failure has been created&lt;br /&gt;2010-11-09 20:28:36 Slp: Sco: Attempting to create base registry key HKEY_LOCAL_MACHINE, machine &lt;br /&gt;2010-11-09 20:28:36 Slp: Sco: Attempting to open registry subkey Software\Microsoft\PCHealth\ErrorReporting\DW\Installed&lt;br /&gt;2010-11-09 20:28:36 Slp: Sco: Attempting to get registry value DW0200&lt;br /&gt;2010-11-09 20:29:01 Slp: Submitted 1 of 1 failures to the Watson data repository&lt;br /&gt;&lt;br /&gt;Assuming that there is a file with incorrect format I took a chance to open this file as mentioned in the error above .C:\Documents and Settings\Abhay\Desktop\2008 R2 X64\2008_R2_x86\x86\1033\License_EVAL.rtf . Since this is an RTF file we can open it in WORDPAD ....&lt;br /&gt;&lt;br /&gt;When opened , I found it unreadable ...Initially I thought it is suppose to be like that as there might be something encrypted .&lt;br /&gt;However , there were other license files in the same folder which were absolutely readable ..&lt;br /&gt;&lt;br /&gt;This made me curious and I checked the same file on my machine as I also had the same EVAL setup ...I was able to read it word by word .So it was clear that the file was corrupt ....We tried and swapped the file between my TP and the server ...The setup moved forward :)  .&lt;br /&gt;&lt;br /&gt;Hope this helps .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-6968788743529328903?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/6968788743529328903/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=6968788743529328903&amp;isPopup=true' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/6968788743529328903'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/6968788743529328903'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/11/sql-server-setup-has-encountered.html' title='SQL Server Setup has encountered the following error:File format is not valid'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-4677781908352767388</id><published>2010-11-09T22:12:00.000+05:30</published><updated>2010-11-09T22:12:33.903+05:30</updated><title type='text'>Error 1706. An installation package for the product Microsoft SQL Server 2005 cannot be found. Try the installation again using a valid copy of the installation package 'SqlRun_SQL.msi'.</title><content type='html'>adding a new post after a good gap ...&lt;br /&gt;Recently we faced an issue where we lost physical files of Master database (master.mdf and mastlog.ldf).We had the backup files but we could not use them unless SQL Server is up and running .So we had no choice but to rebuild master .&lt;br /&gt;&lt;br /&gt;&lt;i&gt;We tried the step below via DOS prompt :&lt;/i&gt;&lt;br /&gt;&lt;b&gt;C:\Documents and Settings\Abhay\Desktop\softwares\SQLEVAL_2005\Servers&gt;start /wait setup.exe /qn INSTANCENAME=CORRUPT REINSTALL=SQL_Engine REBUILDDATABASE=1 SAPWD=XXXXX&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;This had always worked for me and is also mentioned in BOL .However , this time this did not work .The errors I got in the log file were (&lt;b&gt;to find the error we should search for Return Value 3&lt;/b&gt;):&lt;br /&gt;&lt;br /&gt;Error 1706. An installation package for the product Microsoft SQL Server 2005 cannot be found. Try the installation again using a valid copy of the installation package 'SqlRun_SQL.msi'.&lt;br /&gt;MSI (s) (2C:08) [14:07:26:265]: User policy value 'DisableRollback' is 0&lt;br /&gt;MSI (s) (2C:08) [14:07:26:265]: Machine policy value 'DisableRollback' is 0&lt;br /&gt;&lt;b&gt;Action ended 14:07:26: InstallFinalize. Return value 3.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The setup files were valid and had been used many time in the past ..I ran SQLRun_SQL.msi manually and it was running fine .I also used 2 different setups and go the same error .&lt;br /&gt;Also &lt;br /&gt;&lt;br /&gt;MSI (s) (2C:08) [14:07:26:281]: File: C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\modellog.ldf; To be installed; Won't patch; No existing file&lt;br /&gt;MSI (s) (2C:08) [14:07:26:281]: Executing op: FileCopy(SourceName=C:\Config.Msi\3bf6ceb.rbf,,DestName=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\model.mdf,Attributes=32800,FileSize=1245184,PerTick=0,,VerifyMedia=0,ElevateFlags=3,,,,,,,InstallMode=4194308,,,,,,,)&lt;br /&gt;MSI (s) (2C:08) [14:07:26:281]: File: C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\model.mdf; To be installed; Won't patch; &lt;b&gt;No existing file&lt;br /&gt;&lt;/b&gt;MSI (s) (2C:08) [14:07:26:296]: Executing op: FileCopy(SourceName=C:\Config.Msi\3bf6cea.rbf,,DestName=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\msdblog.ldf,Attributes=32800,FileSize=786432,PerTick=0,,VerifyMedia=0,ElevateFlags=3,,,,,,,InstallMode=4194308,,,,,,,)&lt;br /&gt;MSI (s) (2C:08) [14:07:26:296]: File: C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\msdblog.ldf; To be installed; Won't patch; &lt;b&gt;No existing file&lt;/b&gt; &lt;br /&gt;MSI (s) (2C:08) [14:07:26:296]: Executing op: FileCopy(SourceName=C:\Config.Msi\3bf6ce9.rbf,,DestName=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\msdbdata.mdf,Attributes=32800,FileSize=12255232,PerTick=0,,VerifyMedia=0,ElevateFlags=3,,,,,,,InstallMode=4194308,,,,,,,)&lt;br /&gt;MSI (s) (2C:08) [14:07:26:296]: File: C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\msdbdata.mdf; To be installed; Won't patch; &lt;b&gt;No existing file&lt;/b&gt;&lt;br /&gt;MSI (s) (2C:08) [14:07:26:296]: Executing op: FileCopy(SourceName=C:\Config.Msi\3bf6ce8.rbf,,DestName=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\mastlog.ldf,Attributes=32800,FileSize=853016576,PerTick=0,,VerifyMedia=0,ElevateFlags=3,,,,,,,InstallMode=4194308,,,,,,,)&lt;br /&gt;MSI (s) (2C:08) [14:07:26:296]: File: C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\mastlog.ldf; To be installed; Won't patch; &lt;b&gt;No existing file&lt;/b&gt;&lt;br /&gt;MSI (s) (2C:08) [14:07:26:312]: Executing op: FileCopy(SourceName=C:\Config.Msi\3bf6ce7.rbf,,DestName=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\master.mdf,Attributes=32800,FileSize=92602368,PerTick=0,,VerifyMedia=0,ElevateFlags=3,,,,,,,InstallMode=4194308,,,,,,,)&lt;br /&gt;MSI (s) (2C:08) [14:07:26:312]: File: C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\master.mdf; To be installed; Won't patch; &lt;b&gt;No existing file&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;This was strange as these files were existing ....&lt;br /&gt;&lt;br /&gt;&lt;b&gt;I ran the same command using \qb option and got the same error but in a form of a pop-up box.&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;I then checked and found that there is an option called as &lt;b&gt;REINSTALLMODE&lt;/b&gt; .;&lt;b&gt;REINSTALLMODE&lt;/b&gt; is used to repair installed components. The supported values are:&lt;br /&gt;O – Reinstall if file is missing, or an older version is present.&lt;br /&gt;M – Rewrite machine specific reg keys under HKLM&lt;br /&gt;U – Rewrite user specific reg keys under HKCU&lt;br /&gt;S – Reinstall all shortcuts&lt;br /&gt;&lt;br /&gt;The Option O looked appropriate but I used all i.e. &lt;br /&gt;&lt;b&gt;C:\Documents and Settings\Abhay\Desktop\softwares\SQLEVAL_2005\Servers&gt;start /wait setup.exe /qn INSTANCENAME=CORRUPT REINSTALL=SQL_Engine REINSTALLMODE=OMUS REBUILDDATABASE=1 SAPWD=XXXXX&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;This resolved the issue on my laptop but not on client server .&lt;br /&gt;Finally I found that there is one more option which is never documented ...and this option is &lt;b&gt;V&lt;/b&gt;&lt;br /&gt;The issue was that the setup was copied for a different server and the original media location of where the RTM bits where installed in some cache file.That was the reason we were getting the error about the installation package not being found.To resolve this we had to use the option V to re-cache the media from the new location.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;C:\Documents and Settings\Abhay\Desktop\softwares\SQLEVAL_2005\Servers&gt;start /wait setup.exe /qn INSTANCENAME=CORRUPT REINSTALL=SQL_Engine REINSTALLMODE=V REBUILDDATABASE=1 SAPWD=XXXXX&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;This ran like a knife through butter ..&lt;br /&gt; &lt;br /&gt;Hope it will help you in future ...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-4677781908352767388?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/4677781908352767388/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=4677781908352767388&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4677781908352767388'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4677781908352767388'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/11/error-1706-installation-package-for.html' title='Error 1706. An installation package for the product Microsoft SQL Server 2005 cannot be found. Try the installation again using a valid copy of the installation package &apos;SqlRun_SQL.msi&apos;.'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-5342960748393112689</id><published>2010-09-29T17:35:00.000+05:30</published><updated>2010-09-29T17:35:01.887+05:30</updated><title type='text'>Error: 26049, Severity: 16, State: 1 :Server local connection provider failed to listen on [ \\.\pipe\SQLLocal\XXXXX ]. Error: 0x5</title><content type='html'>There might be many reasons and many solutions for this kind of error.But let me explain my situation :) ...For testing I installed a new default instance on one of the test servers.The setup was successful .However , later one of the other named instance did not come up after the restart.&lt;br /&gt;&lt;br /&gt;The errors were :&lt;br /&gt;&lt;br /&gt;2010-09-30 03:17:31.65 Server      Error: 26049, Severity: 16, State: 1.&lt;br /&gt;2010-09-30 03:17:31.65 Server      Server local connection provider failed to listen on [ \\.\pipe\SQLLocal\XXXXX ]. Error: 0x5&lt;br /&gt;2010-09-30 03:17:31.65 Server      Error: 17182, Severity: 16, State: 1.&lt;br /&gt;2010-09-30 03:17:31.65 Server      TDSSNIClient initialization failed with error 0x5, status code 0x40.&lt;br /&gt;2010-09-30 03:17:31.65 Server      Error: 17182, Severity: 16, State: 1.&lt;br /&gt;2010-09-30 03:17:31.65 Server      TDSSNIClient initialization failed with error 0x5, status code 0x1.&lt;br /&gt;2010-09-30 03:17:31.65 Server      Error: 17826, Severity: 18, State: 3.&lt;br /&gt;2010-09-30 03:17:31.65 Server      Could not start the network library because of an internal error in the network library. To determine the cause, review the errors immediately preceding this one in the error log.&lt;br /&gt;2010-09-30 03:17:31.65 Server      Error: 17120, Severity: 16, State: 1.&lt;br /&gt;2010-09-30 03:17:31.65 Server      SQL Server could not spawn FRunCM thread. Check the SQL Server error log and the Windows event logs for information about possible related problems.&lt;br /&gt;&lt;br /&gt;The issue is quite simple unlike it looks like .I tried everything like changing the named pipe , etc. etc.&lt;br /&gt;Assuming, that 0x5 is the OS error which means Access Denied ,I gave the permission to the domain ID on the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer.&lt;br /&gt;This resolved the issue .&lt;br /&gt;&lt;br /&gt;status code 0x40 means that there is an issue with Shared memory listener&lt;br /&gt;status code 0x50 means that there is an issue with Named pipe listener&lt;br /&gt;status code 0x0A means that there is an issue with TCP/IP listener&lt;br /&gt;&lt;br /&gt;Please go through this MSDN blog (which has one more link in it).&lt;br /&gt;http://blogs.msdn.com/b/sql_protocols/archive/2006/03/09/546655.aspx?wa=wsignin1.0&lt;br /&gt;&lt;br /&gt;Happy Learning !!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-5342960748393112689?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/5342960748393112689/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=5342960748393112689&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5342960748393112689'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5342960748393112689'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/09/error-26049-severity-16-state-1-server.html' title='Error: 26049, Severity: 16, State: 1 :Server local connection provider failed to listen on [ \\.\pipe\SQLLocal\XXXXX ]. Error: 0x5'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-3695964825820763002</id><published>2010-09-28T16:28:00.000+05:30</published><updated>2010-09-28T16:28:39.859+05:30</updated><title type='text'>A simple VB script to retain Errorlogs worth 90 days (or as you like)</title><content type='html'>So far ,I heard retaining X number of errlogs which is widely used (So I am not writing that script here)...But one of our clients asked us to retain errlogs worth only 90 days .The client was not ready to recycle the errorlogs and wanted us to keep them to the default ...&lt;br /&gt;&lt;br /&gt;Finally , we could come out with a simple VB script that can do it .The script code is mentioned below .&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Code :&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;sFolder = "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG"&lt;br /&gt;iMaxAge = 90&lt;br /&gt;Set oFSO = CreateObject("Scripting.FileSystemObject")&lt;br /&gt;If oFSO.FolderExists(sFolder) Then&lt;br /&gt;for each oFile in oFSO.GetFolder(sFolder).Files&lt;br /&gt;If DateDiff("d", oFile.DateLastModified, Now) &gt; iMaxAge and (oFile.name= "ERRORLOG.1" or oFile.name= "ERRORLOG.2" or oFile.name= "ERRORLOG.3" or oFile.name= "ERRORLOG.4" or oFile.name= "ERRORLOG.5" or oFile.name= "ERRORLOG.6") Then&lt;br /&gt;wscript.echo "Deleting" &amp;oFile.Name&lt;br /&gt;oFile.Delete&lt;br /&gt;End If&lt;br /&gt;next&lt;br /&gt;End If&lt;br /&gt;&lt;br /&gt;You will need to create a scheduled task/Or SQL Server job using xp_cmdshell, to run at a specific time .Once its kicked off , if any of the files mentioned in the code (Note : errorlog will not be tried upon) have a timestamp greater than 90 days from the day you are executing the file , It will delete those files ...for example if I have 7 files below :&lt;br /&gt;&lt;br /&gt;File    Timestamp&lt;br /&gt;Errorlog    12/9/2009&lt;br /&gt;Errorlog.1    12/8/2009&lt;br /&gt;Errorlog.2   12/7/2009&lt;br /&gt;Errorlog.3   12/6/2009&lt;br /&gt;Errorlog.4   12/5/2009&lt;br /&gt;Errorlog.5   12/4/2009&lt;br /&gt;Errorlog.6   12/3/2009&lt;br /&gt;&lt;br /&gt;The files deleted will be : Errorlog.3,Errorlog.4,Errorlog.5 and Errorlog.6&lt;br /&gt;&lt;br /&gt;You need to change the Path of sFolder variable ..&lt;br /&gt;Happy learning ...&lt;br /&gt;&lt;br /&gt;Abhay&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-3695964825820763002?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/3695964825820763002/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=3695964825820763002&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/3695964825820763002'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/3695964825820763002'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/09/simple-vb-script-to-retain-errorlogs.html' title='A simple VB script to retain Errorlogs worth 90 days (or as you like)'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-6164818517006974307</id><published>2010-09-28T16:23:00.000+05:30</published><updated>2010-09-28T16:23:59.386+05:30</updated><title type='text'>checkODBCConnectError: sqlstate = 28000; native error = 4818; message = [Microsoft][SQL Native Client][SQL Server]Login failed for user 'XXXXX\clusterservice</title><content type='html'>a little Background :&lt;br /&gt;As per our security guidelines Builtin\Administrator login should be removed from all the SQL Server instances.It was implemented on all the SQL Server instances including those which are on MCSC (Windows Cluster).&lt;br /&gt;After that, the nodes were rebooted due to patching requirements .The nodes came up , but SQL Server did not :D ...&lt;br /&gt;&lt;br /&gt;Error in cluster logs (you will not find it in SQL Server logs) :&lt;br /&gt;&lt;br /&gt;ERR  SQL Server &lt;SQL Server&gt;: [sqsrvres] checkODBCConnectError: sqlstate = 28000; native error = 4818; message = [Microsoft][SQL Native Client][SQL Server]Login failed for user 'XXXXX\clusterservice'.&lt;br /&gt;ERR  SQL Server &lt;SQL Server&gt;: [sqsrvres] ODBC sqldriverconnect failed &lt;br /&gt;&lt;br /&gt;The error was clear .The cluster service was not able to login to SQL Server through user XXXXX\clusterservice but via a LOGIN ...That login is BUILTIN\Administrators.&lt;br /&gt;But why it needs to login to SQL Server ?? Because it needs to run the isAlive check to make sure that the SQL Server is up and running .It also runs the looksalive (its a function)check but that does not need to query SQL Server .Is Alive check runs select @@servername and waits for the return message through ODBC client (in our case its SQL Server Native client).Thus the Isalive check was not able to create a trusted connection and we lost the access to Virtual server.&lt;br /&gt;&lt;br /&gt;So, in a SQL Server 2005\2008 failover cluster installation, the cluster service account relies on membership in the BUILTIN\Administrators group to log on to SQL Server 2005\2008 to run the IsAlive check.If you remove the BUILTIN\Administrators group from a failover cluster, you must explicitly grant the MSCS service account permissions to log on to the SQL Server 2005 failover cluster.&lt;br /&gt;&lt;br /&gt;The SQL Server 2005 resource starts an instance of the Sqlcmd.exe utility under the security context of the MSCS service account. Then, the SQL Server 2005 resource runs an SQL script over a dedicated administrator connection (DAC) that samples various dynamic management views (DMV). Because a DAC connection is used to collect some diagnostic data, the clustering service account must be provisioned in the SYSADMIN fixed server role. If later someone says that clustering service account cannot be provisioned in the SYSADMIN fixed server role, then we can create a login for cluster service account that is not given the SYSADMIN fixed server role .I have not tested it yet .So cannot confirm that this will work on not ...&lt;br /&gt;&lt;br /&gt;Commands :&lt;br /&gt;CREATE LOGIN [&lt;Domain Name&gt;\&lt;MSCS Service Account&gt;] FROM WINDOWS WITH DEFAULT_DATABASE=[master]&lt;br /&gt;EXEC master.sp_addsrvrolemember @loginame = N'&lt;Domain Name&gt;\&lt;MSCS Service Account&gt; ', @rolename = N'sysadmin'&lt;br /&gt;&lt;br /&gt;happly learning .....&lt;br /&gt;Regards&lt;br /&gt;Abhay&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-6164818517006974307?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/6164818517006974307/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=6164818517006974307&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/6164818517006974307'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/6164818517006974307'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/09/checkodbcconnecterror-sqlstate-28000.html' title='checkODBCConnectError: sqlstate = 28000; native error = 4818; message = [Microsoft][SQL Native Client][SQL Server]Login failed for user &apos;XXXXX\clusterservice'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-3803009041031762361</id><published>2010-09-20T20:37:00.000+05:30</published><updated>2010-09-20T20:37:28.138+05:30</updated><title type='text'>Msg 22004, Level 16, State 1, Line 0 :Failed to open loopback connection. Please see event log for more information.Failed to open loopback connection. Please see event log for more information.</title><content type='html'>I am back with one more solution :).The problem was simple but the error made me thinking ..I was trying to do xp_readerrorlog on a small file .But my SPID hanged ..after some time I got this error :&lt;br /&gt;&lt;br /&gt;&lt;b&gt;SQL Server error in QA :&lt;/b&gt;&lt;br /&gt;Msg 22004, Level 16, State 1, Line 0&lt;br /&gt;Failed to open loopback connection. Please see event log for more information.&lt;br /&gt;Msg 22004, Level 16, State 1, Line 0&lt;br /&gt;error log location not found&lt;br /&gt;&lt;br /&gt;I read somewhere that this error comes when SQL Server Agent failes to come up.Yes my agent was down.But I faied to understand what is the relation between running xp_readerrlog and SQL Agent not running .Still, I tried to run the agent and got the error ...So something is related to SQL Agent here and that something is that If SQL Agent is not running , I can run xp_readerrlog successfully (I will prove it wrong later).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;I checked the application logs immediately and got these errors :&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;Event Type: Error&lt;br /&gt;Event Source: MSSQLSERVER&lt;br /&gt;Event Category: (2)&lt;br /&gt;Event ID: 17052&lt;br /&gt;Date:  09/20/2010&lt;br /&gt;Time:  18:24:22&lt;br /&gt;User:  N/A&lt;br /&gt;Computer: abchaudh&lt;br /&gt;Description:&lt;br /&gt;Severity: 16 Error:10061, OS: 10061 [Microsoft][SQL Native Client]TCP Provider: No connection could be made because the target machine actively refused it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.&lt;br /&gt;Data:&lt;br /&gt;0000: 4d 27 00 00 0a 00 00 00   M'......&lt;br /&gt;0008: 12 00 00 00 61 00 62 00   ....a.b.&lt;br /&gt;0010: 63 00 68 00 61 00 75 00   c.h.a.u.&lt;br /&gt;0018: 64 00 68 00 00 00 0e 00   d.h.....&lt;br /&gt;0020: 00 00 6d 00 61 00 73 00   ..m.a.s.&lt;br /&gt;0028: 74 00 65 00 72 00 00 00   t.e.r...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Event Type: Error&lt;br /&gt;Event Source: SQLAgent$CORRUPT&lt;br /&gt;Event Category: Service Control &lt;br /&gt;Event ID: 103&lt;br /&gt;Date:  09/20/2010&lt;br /&gt;Time:  18:24:45&lt;br /&gt;User:  N/A&lt;br /&gt;Computer: abchaudh&lt;br /&gt;Description:&lt;br /&gt;SQLServerAgent could not be started (reason: Unable to connect to server 'abchaudh\CORRUPT'; SQLServerAgent cannot start).&lt;br /&gt;&lt;br /&gt;For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.&lt;br /&gt;&lt;br /&gt;Event Type: Information&lt;br /&gt;Event Source: SQLAgent$CORRUPT&lt;br /&gt;Event Category: Service Control &lt;br /&gt;Event ID: 102&lt;br /&gt;Date:  09/20/2010&lt;br /&gt;Time:  18:24:52&lt;br /&gt;User:  N/A&lt;br /&gt;Computer: abchaudh&lt;br /&gt;Description:&lt;br /&gt;SQLServerAgent service successfully stopped.&lt;br /&gt;&lt;br /&gt;For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.&lt;br /&gt;&lt;br /&gt;I also checked the SQL Agent logs :&lt;br /&gt;&lt;br /&gt;&lt;b&gt;SQL Agent logs :&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;2010-09-20 18:25:36 - ! [298] SQLServer Error: 10061, TCP Provider: No connection could be made because the target machine actively refused it. [SQLSTATE 08001] &lt;br /&gt;2010-09-20 18:25:36 - ! [165] ODBC Error: 0, Login timeout expired [SQLSTATE HYT00] &lt;br /&gt;2010-09-20 18:25:36 - ! [298] SQLServer Error: 10061, An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. [SQLSTATE 08001] &lt;br /&gt;2010-09-20 18:25:36 - ! [000] Unable to connect to server 'abchaudh\CORRUPT'; SQLServerAgent cannot start&lt;br /&gt;2010-09-20 18:25:42 - ! [298] SQLServer Error: 10061, TCP Provider: No connection could be made because the target machine actively refused it. [SQLSTATE 08001] &lt;br /&gt;2010-09-20 18:25:42 - ! [165] ODBC Error: 0, Login timeout expired [SQLSTATE HYT00] &lt;br /&gt;2010-09-20 18:25:42 - ! [298] SQLServer Error: 10061, An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. [SQLSTATE 08001] &lt;br /&gt;2010-09-20 18:25:42 - ! [382] Logon to server 'abchaudh\CORRUPT' failed (DisableAgentXPs)&lt;br /&gt;2010-09-20 18:25:43 - ? [098] SQLServerAgent terminated (normally)&lt;br /&gt;&lt;br /&gt;So, now I have 2 issues : SQL Agent is not running and xp_readerrorlog is timing out.&lt;br /&gt;&lt;br /&gt;.If you see one of my older posts on "target machine actively refuses it" , you will have some information .&lt;br /&gt;&lt;br /&gt;So I opened CLICONFG and found 3 incorrect aliases which were not using the right port ..&lt;br /&gt;&lt;br /&gt;I removed them and SQL Agent came on line ...xp_read errorlog also started working ...&lt;br /&gt;&lt;br /&gt;I stopped SQL Agent and stil everything was working ...&lt;br /&gt;So the issue was that xp_readerrlog tries to connect to SQL Server but stucks due to the Alias pointing to incorrect port.&lt;br /&gt;&lt;br /&gt;But this does not affect SQL Server service .To check why its not affecting SQL Server service , I disabled the sahred memory protocol and BANG....SQL Server connection failed ...&lt;br /&gt;&lt;br /&gt;Happy learning ....&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-3803009041031762361?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/3803009041031762361/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=3803009041031762361&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/3803009041031762361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/3803009041031762361'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/09/msg-22004-level-16-state-1-line-0.html' title='Msg 22004, Level 16, State 1, Line 0 :Failed to open loopback connection. Please see event log for more information.Failed to open loopback connection. Please see event log for more information.'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-5798423552832797696</id><published>2010-08-25T14:48:00.000+05:30</published><updated>2010-08-25T14:55:37.368+05:30</updated><title type='text'>Could not load the DLL xpstar90.dll, or one of the DLLs it references. Reason: 126(The specified module could not be found.)</title><content type='html'>Hi Team ,&lt;br /&gt;This issue was faced by someone outside IBM but my main intention is to explain the benefit of another nice tool : Dependency Walker (http://www.dependencywalker.com/)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Issue :&lt;/strong&gt;&lt;br /&gt;SQL Server Agent failed to come up after the service account password was reset at AD level .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Error(s) :&lt;/strong&gt;&lt;br /&gt;In the event log you will see these errors in sequence :&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;Could not load the DLL xpstar90.dll, or one of the DLLs it references. Reason: 126(The specified module could not be found.).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;Failed to retrieve SQLPath for syssubsystems population.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;SQLServerAgent could not be started (reason: Failed to load any subsystems. Check errorlog for details.).&lt;br /&gt;&lt;br /&gt;The first error is the main error and rest are the errors following the first error and we need not to think about them .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Troubleshooting and Resolution :&lt;/strong&gt;&lt;br /&gt;The error clearly says that either there is a problem with xpstar90.dll or the other dlls that this dll references .&lt;br /&gt;This file is located in I first tried to re-register xpstar90.dll by using regsvr32 xrstar90.dll and got this message :&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;xpstar90.dll was loaded , But the dllRegisterServer entry point was not found.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;I have heard that sometimes there is a different way of registering some DLLs , so by this error I did not come to the conclusion that this file is corrupt.&lt;br /&gt;I was also thinking that there might be some other DDL that this DLL refers to , which got corrupted.&lt;br /&gt;&lt;br /&gt;I decided to see the tree structure of xpstar90.dll in Dependency Walker . I opened the C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\xpstar90.dll in it and go this output.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_SqLnRbOtgHE/THThJCOjkWI/AAAAAAAAAxg/rtYp6OkhSV8/s1600/untitled.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 225px;" src="http://2.bp.blogspot.com/_SqLnRbOtgHE/THThJCOjkWI/AAAAAAAAAxg/rtYp6OkhSV8/s320/untitled.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5509275789513953634" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;So, in this case XPSTAR90.DLL itself was corrupt .I found its version 2005.90.4035.0 and replaced it with another one that I had in another instance .&lt;br /&gt;SQL Agent came online .&lt;br /&gt;In case if it dos not , then we need to uninstall Native client from ADD Remove Programs and reinstall it .&lt;br /&gt;&lt;br /&gt;Happy learning&lt;br /&gt;Abhay&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-5798423552832797696?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/5798423552832797696/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=5798423552832797696&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5798423552832797696'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5798423552832797696'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/08/could-not-load-dll-xpstar90dll-or-one.html' title='Could not load the DLL xpstar90.dll, or one of the DLLs it references. Reason: 126(The specified module could not be found.)'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_SqLnRbOtgHE/THThJCOjkWI/AAAAAAAAAxg/rtYp6OkhSV8/s72-c/untitled.bmp' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-199202952498664506</id><published>2010-08-02T16:40:00.001+05:30</published><updated>2010-08-02T16:56:35.479+05:30</updated><title type='text'>Error 1117 :The request could not be performed because of an I/O device error.</title><content type='html'>Our backups were failing under these conditions :&lt;br /&gt;&lt;br /&gt;Scenario 1:  The System databases plus few user databases are on local disk &amp; few user databases are on LUNs.&lt;br /&gt;&lt;br /&gt;Scenario 2: The System &amp; user databases are completely on LUNs&lt;br /&gt;&lt;br /&gt;The backups were running for some good amount of time but then use to fail with Error 1117.I know that taking backups on network is not suported but I was breaking my head on this ERROR (1117)to know the reason behind this error .After going through a few tests on my machine using external HDDs ,my understanding of this error is :&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-&gt; Error 1117 is ERROR_IO_DEVICE .Thats fine .But I was curious about knowing the situations under which this error might occur and what is the exact meaning on this Error .Does Error_IO_Device means that the Hardware is corrupt ? Found that this error occurs under the below situations and then found the reasons behind those situations as well :&lt;br /&gt;&lt;br /&gt;STATUS_FT_MISSING_MEMBER                &lt;br /&gt;ERROR_IO_DEVICE&lt;br /&gt;&lt;br /&gt;An attempt was made to explicitly access the secondary copy of information via a device control to the fault tolerance driver and the secondary copy is not present in the system.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;STATUS_FT_ORPHANING                     &lt;br /&gt;ERROR_IO_DEVICE&lt;br /&gt;{FT Orphaning} A disk that is part of a fault-tolerant volume can no longer be accessed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;STATUS_DATA_OVERRUN                     &lt;br /&gt;ERROR_IO_DEVICE&lt;br /&gt;{Data Overrun} A data overrun error occurred.&lt;br /&gt;&lt;br /&gt;STATUS_DATA_LATE_ERROR                  &lt;br /&gt;ERROR_IO_DEVICE&lt;br /&gt;{Data Late} A data late error occurred.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;STATUS_IO_DEVICE_ERROR                  &lt;br /&gt;ERROR_IO_DEVICE&lt;br /&gt;The I/O device reported an I/O error&lt;br /&gt;&lt;br /&gt;STATUS_DEVICE_PROTOCOL_ERROR            &lt;br /&gt;ERROR_IO_DEVICE&lt;br /&gt;A protocol error was detected between the driver and the device.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;STATUS_DRIVER_INTERNAL_ERROR            &lt;br /&gt;ERROR_IO_DEVICE&lt;br /&gt;An error was detected between two drivers or within an I/O driver.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So this error mapping says that this error will be thrown out if anyof these conditions are met .In my situation we were falling in into STATUS_DATA_LATE_ERROR since we were also getting thses entries in the SQL serve errorlogs : "x I/O requests are pending for more then 15 secs ............filename.mdf"&lt;br /&gt;&lt;br /&gt;If you are running backup jobs you might also get this error -1073548784 .&lt;br /&gt;This is a common error and may come when the query you are running remotely is incorrect , or the table you are trying to drop does not exist .Try to export a table that already exists in another DB and you will recreate this OLEDB error.So we need not to worry about finding the message identifier for this number .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Action plan :&lt;br /&gt;-----------------&lt;br /&gt;--try to take backup of another database located remotely and of near about same size . I mean around 20GB.&lt;br /&gt;&lt;br /&gt;--Run Chkdsk on this drive or ask someone to do that and see if the consistency errors come up .&lt;br /&gt;&lt;br /&gt;--Create a similar database on another external drive like this one and take the backup .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Conclusion :&lt;br /&gt;---------------&lt;br /&gt;I am very much certain that the issue is with the drive and(OR)Network.The 15 sec IO delay messages in Errorlogs also suggests the same .But as you can see this error also comes when dataa gets late in reaching the destination (STATUS_DATA_LATE_ERROR) I am suspecting that the network might also be a bit slow and contributing to the backup failure .&lt;br /&gt;&lt;br /&gt;Now the ball is in your court how you explain this to the client :) .&lt;br /&gt;&lt;br /&gt;Hapy Learning&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-199202952498664506?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/199202952498664506/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=199202952498664506&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/199202952498664506'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/199202952498664506'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/08/error-1117-request-could-not-be.html' title='Error 1117 :The request could not be performed because of an I/O device error.'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-5933577957257022426</id><published>2010-07-27T15:56:00.000+05:30</published><updated>2010-07-29T14:16:57.511+05:30</updated><title type='text'>Msg 8914, Level 16, State 1, Line 1  -&gt; Incorrect PFS free space information for page</title><content type='html'>Msg 8914, Level 16, State 1, Line 1&lt;br /&gt;Incorrect PFS free space information for page (1:61991) in object ID 1993058136, index ID 1, partition ID 72057594955366400, alloc unit ID 71906736119218176 (type LOB data). Expected value   0_PCT_FULL, actual value 100_PCT_FULL.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This was the error we were getting in the Docs table of one of the Sharepoint database .The Compatibility level was 80 and Build was 1399 (2005 RTM).&lt;br /&gt;&lt;br /&gt;I tried a lot of things on it like :&lt;br /&gt;        -&gt; I Rebuilt the clustered index with and without LOB_COMPACTION option .&lt;br /&gt; -&gt; DBCC page shows is fill factor 100&lt;br /&gt; -&gt; Changed the fill factor to 100 explicitly&lt;br /&gt; -&gt; Ran dbcc updateusage&lt;br /&gt; -&gt; changed the compatibility level to 90&lt;br /&gt; -&gt; changed the fill factor to to 99 ,50 etc &lt;br /&gt;Nothing helped .The profiler did not show much (my intention was to know what checkdb is doing internally).&lt;br /&gt;&lt;br /&gt;Finally I took the backup of the database and restored it as a test database .It did not give any errors .This means that actually its not a corruption .&lt;br /&gt;&lt;br /&gt;On the restored database Ran DBCC checkdb with repair_allow_data_loss .&lt;br /&gt;It fixed the issue without harming the data .Finally Ran the same on the Sharepoint database and it resolved the issue .&lt;br /&gt;&lt;br /&gt;Hope this gives you the confidence to run the repair_allow_data_loss for this issue .&lt;br /&gt;But remember , almost every time if you run it with repair_allow_data_loss you will end up loosing the data .So be careful .&lt;br /&gt;&lt;br /&gt;This situation was AN EXCEPTION and you can safely use this option of checkdb.&lt;br /&gt;&lt;br /&gt;Root cause :&lt;br /&gt;Microsoft says that &lt;br /&gt;the engine (just like OS does which giving pages to processes ) pre-allocates a set of data pages (say X) to the SPID which needs it and marks them as 100% full in PFS assuming that those pages will eventually get filled very soon.It does this to avoid frequently updating PFS page and improving performance.But later when the SPID completes its work in less pages (say X-Y) , these remaining pages are released .However, the remaining pages should be marked again as empty (0_PCT_FULL) which it does not do and hence DBCC CheckDB reports those errors (SQL 2000 silently use to fix it ).Repair_allow_data_loss will fix it with no data loss actually.&lt;br /&gt;&lt;br /&gt;Regards&lt;br /&gt;Abhay&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-5933577957257022426?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/5933577957257022426/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=5933577957257022426&amp;isPopup=true' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5933577957257022426'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5933577957257022426'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/07/msg-8914-level-16-state-1-line-1.html' title='Msg 8914, Level 16, State 1, Line 1  -&gt; Incorrect PFS free space information for page'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-1174956805427142119</id><published>2010-07-26T17:28:00.000+05:30</published><updated>2010-07-26T17:30:08.260+05:30</updated><title type='text'>Finding the last date when the LOG/FULL/DIFF/FILEGROUP backup was taken for all the databases</title><content type='html'>Hi Guys , &lt;br /&gt;While creating a few scripts , a requirement came where I had to find the last backups (all types) taken for all the databases (except tempdb) .&lt;br /&gt;Please find the script below .Hope it helps you in your daily activities .If you want to automate it for all the instances in your environment , please let me know and I can send you some more files. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*&lt;br /&gt;Script  : Last_bckp.sql&lt;br /&gt;Author  : Abhay Chaudhary, &lt;br /&gt;Date  : 26th JUL, 2010&lt;br /&gt;Purpose  : Collecting SQL Server 2000/2005/2008 last backup taken information.&lt;br /&gt;Requirements    : Do a CTRL+F and change the &lt;DBNAME&gt; to the DB where you want to   &lt;br /&gt;                  create the object.&lt;br /&gt;Suggestions     : hi_abhay78@yahoo.co.in&lt;br /&gt;Version  : 1.0&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;USE &lt;DBNAME&gt;&lt;br /&gt;set nocount on&lt;br /&gt;if not exists (select * from &lt;dbname&gt;..sysobjects where name ='bckp_types' and type ='S')&lt;br /&gt;begin &lt;br /&gt;create table &lt;dbname&gt;..bckp_types (num int identity(1,1),type varchar(1),bkp_name varchar(20))&lt;br /&gt;insert into &lt;dbname&gt;..bckp_types (type,bkp_name) values ('D','Full backup')&lt;br /&gt;insert into &lt;dbname&gt;..bckp_types (type,bkp_name) values ('L','Log Backup')&lt;br /&gt;insert into &lt;dbname&gt;..bckp_types (type,bkp_name) values ('F','Filegroup backup')&lt;br /&gt;insert into &lt;dbname&gt;..bckp_types (type,bkp_name) values ('I','Differential backup')&lt;br /&gt;end &lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;Declare @loop int&lt;br /&gt;select @loop= max(num) from bckp_types&lt;br /&gt;While (@loop !=0)&lt;br /&gt;begin &lt;br /&gt;Select 'last ' + bkp_name +' taken details.' from bckp_types where num=@loop&lt;br /&gt;declare @bk_type varchar(1)&lt;br /&gt;select @bk_type = type from bckp_types where num=@loop&lt;br /&gt;&lt;br /&gt;SELECT s.name                     'database Name',&lt;br /&gt;       b.backup_finish_date         'last backup date',&lt;br /&gt;       bmf.physical_device_name     'location of backup'&lt;br /&gt;  FROM master..sysdatabases s LEFT OUTER JOIN msdb..backupset b ON s.name = b.database_name&lt;br /&gt;  INNER JOIN msdb..backupmediafamily bmf ON b.media_set_id = bmf.media_set_id&lt;br /&gt;  WHERE s.name &lt;&gt; 'tempdb'&lt;br /&gt;  AND b.backup_finish_date = (SELECT MAX(backup_finish_date)&lt;br /&gt;                              FROM msdb..backupset&lt;br /&gt;                              WHERE database_name = b.database_name&lt;br /&gt;                              AND type = @bk_type) &lt;br /&gt;  ORDER BY s.name&lt;br /&gt;&lt;br /&gt;set @loop=@loop-1&lt;br /&gt;end&lt;br /&gt;go&lt;br /&gt;Drop table &lt;dbname&gt;..bckp_types&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Happy Learning ...&lt;br /&gt;Abhay&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-1174956805427142119?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/1174956805427142119/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=1174956805427142119&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1174956805427142119'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1174956805427142119'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/07/finding-last-date-when.html' title='Finding the last date when the LOG/FULL/DIFF/FILEGROUP backup was taken for all the databases'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-5892865780106706219</id><published>2010-07-16T16:39:00.000+05:30</published><updated>2010-07-16T16:51:11.390+05:30</updated><title type='text'>SQLServer Error: 848, SQL Network Interfaces: The system detected a possible attempt to compromise security.</title><content type='html'>We faced a strange but simple issue yesterday and as usual I would like to share it with you .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Situation :&lt;br /&gt;-------------&lt;br /&gt;SQL server 2005 SP2&lt;br /&gt;Windows Server 2003 SP2&lt;br /&gt;Cluster : Yes 2 node A-P cluster&lt;br /&gt;&lt;br /&gt;Service account of SQL Server Agent service and SQL Server service were same .SQL Server is Clustered .&lt;br /&gt;&lt;br /&gt;While SQL Sevrer as well as agent were running fine the account under both the services are running ,got locked(we came to know this later as a rootcause of this issue).Still ,everything was fine and there was no issue since the account got locked after SQL Server and agent were started.&lt;br /&gt;&lt;br /&gt;Then we found that all the jobs that were scheduled stopped working .In the job history we found that there is no JOB HISTORY created since the jobs stopped working .But there was not a single failure of the jobs .&lt;br /&gt;&lt;br /&gt;Which means that the jobs were not scheduled by the Job schedular &gt;&gt; to the Threads &gt;&gt; to the SPIDs .So , we manually executed the jobs and all of them completed successfully .But again , there was no history being created and those jobs were not doing anything .For example , the backup job was running successfully when we ran it explicitly but no backups were taken .&lt;br /&gt;&lt;br /&gt;To drill down further , we ran the commands under the jobs in QA and those were running fine .We created new jobs and there was no change at all in the situation .&lt;br /&gt;&lt;br /&gt;Then we checked the SQL Agent logs and found this :&lt;br /&gt;&lt;br /&gt;[298] SQLServer Error: 848, SQL Network Interfaces: The system detected a possible attempt to compromise security. Please ensure that you can contact the server that authenticated you. [SQLSTATE HY000] &lt;br /&gt;[298] SQLServer Error: 848, Cannot generate SSPI context [SQLSTATE HY000] &lt;br /&gt;[382] Logon to server '(local)' failed (ConnAttemptCachableOp)&lt;br /&gt;&lt;br /&gt;This was strange to us as why the connectivity error is not being displayed when we were explicitely executing the job, which completes successfully and doing nothing.&lt;br /&gt;But since it was the connectivity error by agent , we decided to run the jobs by logging on to the server using the account under which SQL Server and agent are running.&lt;br /&gt;&lt;br /&gt;We then found out the the account was locked under which SQL Server and agent were still running.&lt;br /&gt;&lt;br /&gt;Once the account got unlocked at the AD ,the jobs ACTUALLY started working . &lt;br /&gt;&lt;br /&gt;To me it looks like a bug in design and i have logged it on the CONNECT :&lt;br /&gt;https://connect.microsoft.com/SQLServer/feedback/details/575388/strange-behaviour-in-sql-agent-job-on-cluster-where-the-job-runs-but-does-not-do-anything&lt;br /&gt;&lt;br /&gt;hope it helos you to resolve your issue .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-5892865780106706219?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/5892865780106706219/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=5892865780106706219&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5892865780106706219'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5892865780106706219'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/07/sqlserver-error-848-sql-network.html' title='SQLServer Error: 848, SQL Network Interfaces: The system detected a possible attempt to compromise security.'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-3214123532495103958</id><published>2010-06-19T20:32:00.000+05:30</published><updated>2010-06-19T20:45:36.401+05:30</updated><title type='text'>Data auditing in SQL Server</title><content type='html'>There are 2 ways we can audit the SQL Server events to the tracefile (people call it audit log file).&lt;br /&gt;&lt;br /&gt;- setting sp_configure parameter 'c2 audit mode' to 1.This will automatically capture all the audit events for all the databases and all the columns . You cannot modify it .Even if you try to , it will   &lt;br /&gt;  not take the changes made manually .&lt;br /&gt;&lt;br /&gt;- Creating our own trace for selected events and columns .Please check BOL for it .&lt;br /&gt;&lt;br /&gt;In case you want to go through the second option and that is to create our own trace please see the demo below:&lt;br /&gt;&lt;br /&gt;Step 1 &lt;br /&gt;In this step we are creating test_yasir trace in C: drive.Then we are setting the Events and columns adn settin gthem to ON .I have choosen a few events and columns .&lt;br /&gt;&lt;br /&gt;declare @TraceIdOut int&lt;br /&gt;exec sp_trace_create @TraceIdOut OUTPUT,6, N'c:\test_Yasir'&lt;br /&gt;PRINT @TraceIdOut&lt;br /&gt;&lt;br /&gt;declare @On bit&lt;br /&gt;SET @On = 1&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 14, 6, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 14, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 14, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 14, 9, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 14, 10, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 15, 6, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 15, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 15, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 15, 9, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 15, 10, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 20, 6, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 20, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 20, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 20, 9, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 20, 10, @On&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 1, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 3, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 6, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 10, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 11, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 14, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 22, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 26, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 35, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 8, @On&lt;br /&gt;&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 1, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 3, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 6, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 10, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 11, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 14, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 22, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 26, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 35, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 8, @On&lt;br /&gt;&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 1, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 3, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 6, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 10, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 11, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 14, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 22, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 26, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 35, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 8, @On&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 1, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 3, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 6, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 10, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 11, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 14, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 22, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 26, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 35, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 8, @On&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Step 2 :&lt;br /&gt;&lt;br /&gt;In this step we wil apply the filter since you said you need to audit only a user database.We will achieve it using sp_trace_setfilter&lt;br /&gt;&lt;br /&gt;sp_trace_setfilter 3,3,0,0,1&lt;br /&gt;&lt;br /&gt;In this example I have set the filter on databaseid (to 1 which is master) in traceid 3 &lt;br /&gt;&lt;br /&gt;Step 3:&lt;br /&gt;In this step we will first confirm if our trace is showing up in the metadata.Do a select * from sys.traces and check the trace you created as well its trace id .&lt;br /&gt;Then start the trace (which is 1) using sp_trace_setstatus&lt;br /&gt;&lt;br /&gt;example :&lt;br /&gt;sp_trace_setstatus 3,1&lt;br /&gt;&lt;br /&gt;Here traceid is 3 and staus is 1 &lt;br /&gt;Further , if you want to add or remove any event use sp_trace_setevent after stopping the trace using sp_trace_setstatus&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;But in this method there is a problem .The problem is that , if you restart the instance the trace metadata will be washed from the sys.traces DMV.&lt;br /&gt;So you will have to manually run it again .Further the physical trace file (log file) still exist.So you will get the error while creaing the trace .To over come this :&lt;br /&gt;&lt;br /&gt;1) I have added the datetime in the file name .So it will create a unique file each minute.&lt;br /&gt;2) I have encapsulated the query into an SP and pinned it to SQL Server startup.&lt;br /&gt;&lt;br /&gt;So now &lt;br /&gt;&lt;br /&gt;step 1 would be &lt;br /&gt;&lt;br /&gt;create proc audit_trace as&lt;br /&gt;declare @TraceIdOut int&lt;br /&gt;Declare @D1 nvarchar(30)&lt;br /&gt;Declare @D2 nvarchar(30)&lt;br /&gt;Declare @D3 nvarchar(30)&lt;br /&gt;Declare @D4 nvarchar(30)&lt;br /&gt;Declare @D5 nvarchar(30)&lt;br /&gt;Declare @trace_name nvarchar(256)&lt;br /&gt;&lt;br /&gt;SELECT @D1=DATENAME(Day, GETDATE())&lt;br /&gt;SELECT @D2=DATENAME(month, GETDATE())&lt;br /&gt;SELECT @D3=DATENAME(year, GETDATE())&lt;br /&gt;SELECT @D4=DATENAME(hour, GETDATE())&lt;br /&gt;SELECT @D5=DATENAME(minute, GETDATE())&lt;br /&gt;&lt;br /&gt;set @trace_name='c:\trace_'+@d1+'_'+@d2+'_'+@d3+'_'+@d4+'_'+@d5+'_'&lt;br /&gt;print @trace_name&lt;br /&gt;&lt;br /&gt;--set @trace_name = 'c:\trace_'+@trace_date+'.trc'&lt;br /&gt;--print @trace_name&lt;br /&gt;exec sp_trace_create @TraceIdOut OUTPUT,6, @trace_name&lt;br /&gt;PRINT @TraceIdOut&lt;br /&gt;&lt;br /&gt;declare @On bit&lt;br /&gt;SET @On = 1&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 14, 6, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 14, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 14, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 14, 9, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 14, 10, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 15, 6, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 15, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 15, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 15, 9, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 15, 10, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 20, 6, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 20, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 20, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 20, 9, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 20, 10, @On&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 1, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 3, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 6, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 10, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 11, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 14, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 22, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 26, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 35, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 104, 8, @On&lt;br /&gt;&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 1, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 3, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 6, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 10, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 11, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 14, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 22, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 26, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 35, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 107, 8, @On&lt;br /&gt;&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 1, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 3, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 6, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 10, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 11, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 14, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 22, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 26, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 35, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 106, 8, @On&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 1, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 3, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 6, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 10, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 11, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 14, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 22, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 26, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 35, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 8, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 7, @On&lt;br /&gt;exec sp_trace_setevent @TraceIdOut, 105, 8, @On&lt;br /&gt;&lt;br /&gt;/*adding the SP to execute at SQl Server startup */&lt;br /&gt;exec sp_procoption N'audit_trace', 'startup', 'on'&lt;br /&gt;&lt;br /&gt;Step 2 and 3 will be same as mentioned above in the begening .&lt;br /&gt;&lt;br /&gt;Disadvantage &lt;br /&gt;-------------&lt;br /&gt;Simple ..Its resource consuming .Do not add a lot of columns in the trace .Do specifically what you want to audit.&lt;br /&gt;It entirely depends what all columns you are auditing.&lt;br /&gt;You need to keep the instance under testing phase and monitor the resource consumption due to tracing .&lt;br /&gt;Clear the client that we need to make sure that we have fast disks ,more/faster CPUs, IO processing capabbilities and enough RAM in case they need to do extensive auditing (if there are performance issues).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-3214123532495103958?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/3214123532495103958/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=3214123532495103958&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/3214123532495103958'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/3214123532495103958'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/06/data-auditing-in-sql-server.html' title='Data auditing in SQL Server'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-1460878941978148257</id><published>2010-06-19T20:21:00.000+05:30</published><updated>2010-06-19T20:24:11.274+05:30</updated><title type='text'>Using WMI and SQL Agent to fire low memory threshold alert ...</title><content type='html'>This will work perfectly ....The only thing I wanted to add to the table was when it alerts you it should also fill the column with available MBytes so that you know how much memory was available .......But after trying it for 2 days , I realized that the class through which I am checking another class (Perfmon &gt;&gt; memory &gt;&gt; Available Mbytes) does not have a column for this.I am using "_instance modification" class .May be its due to this that the alert is fired but the job fails when it inserts the availableMbytes ...because this column is not in _instancemodificationevent class...the error number also suggests that .&lt;br /&gt;&lt;br /&gt;By the way this one will only alert if your RAM is &gt; 256 every 10 seconds ....this is because I wanted to test it ....you need to modify it to &lt; 256 and every 300 seconds ...so that you get alert every 5 mins or whatever you decide ....&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*******************************************************************************************&lt;br /&gt;*  This script will create an Alert to Monitor Physical RAM reaching a low threshold.&lt;br /&gt;*  The alert will run a job and the job will enter data in a table.&lt;br /&gt;*******************************************************************************************/&lt;br /&gt;&lt;br /&gt;/* Step 1: creating the table to capture the Event information */&lt;br /&gt;&lt;br /&gt;USE Master&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[memory]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)&lt;br /&gt;DROP TABLE [dbo].[memory]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;CREATE TABLE [dbo].[memory] (&lt;br /&gt;[PostTime] [datetime] NOT NULL default (getdate()) ,&lt;br /&gt;[computerName] sql_variant Not Null ,&lt;br /&gt;[RecordID] [int] IDENTITY (1,1) NOT FOR REPLICATION NOT NULL,&lt;br /&gt;[Flag] [int] NOT NULL CONSTRAINT [DF_MEMORY_Flag]  DEFAULT ((0)),&lt;br /&gt;) ON [PRIMARY]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;CREATE INDEX [Memory_IDX01] ON [dbo].[memory]([recordid]) WITH FILLFACTOR = 100 ON [PRIMARY]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;/*Step 2 : Creating the Job that will enter values into the table we created above*/&lt;br /&gt;/*Service account and sql operator option are optional*/&lt;br /&gt;&lt;br /&gt;USE [msdb]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = N'Capture memory Event')&lt;br /&gt;EXEC msdb.dbo.sp_delete_job @job_name = N'Capture Memory Event', @delete_unused_schedule=1&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;--DECLARE @ServiceAccount varchar(128)&lt;br /&gt;--SET @ServiceAccount = N'&lt;job_owner_account&gt;'&lt;br /&gt;--DECLARE @SQLOperator varchar(128)&lt;br /&gt;--SET @SQLOperator = N'&lt;sql_agent_operator&gt;'&lt;br /&gt;&lt;br /&gt;BEGIN TRANSACTION&lt;br /&gt;DECLARE @ReturnCode INT&lt;br /&gt;SELECT @ReturnCode = 0&lt;br /&gt;&lt;br /&gt;IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)&lt;br /&gt;BEGIN&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;DECLARE @jobId BINARY(16)&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Capture Memory Event', &lt;br /&gt;@enabled=1, &lt;br /&gt;@notify_level_eventlog=2, &lt;br /&gt;@notify_level_email=3, &lt;br /&gt;@notify_level_netsend=0, &lt;br /&gt;@notify_level_page=0, &lt;br /&gt;@delete_level=0, &lt;br /&gt;@description=N'Job for responding to memory events', &lt;br /&gt;@category_name=N'[Uncategorized (Local)]', &lt;br /&gt;--@owner_login_name=@ServiceAccount, &lt;br /&gt;--@notify_email_operator_name=@SQLOperator, &lt;br /&gt;@job_id = @jobId OUTPUT&lt;br /&gt;&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;&lt;br /&gt;/*Step 3: Insert graph into LogEvents*/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Insert data into LogEvents', &lt;br /&gt;@step_id=1, &lt;br /&gt;@cmdexec_success_code=0, &lt;br /&gt;@on_success_action=1, &lt;br /&gt;@on_success_step_id=0, &lt;br /&gt;@on_fail_action=2, &lt;br /&gt;@on_fail_step_id=0, &lt;br /&gt;@retry_attempts=0, &lt;br /&gt;@retry_interval=0, &lt;br /&gt;@os_run_priority=0, @subsystem=N'TSQL', &lt;br /&gt;@command=N'&lt;br /&gt;declare @@server sql_variant&lt;br /&gt;select @@server =serverproperty (''machinename'')&lt;br /&gt;&lt;br /&gt;INSERT INTO memory (&lt;br /&gt;PostTime, &lt;br /&gt;Computername&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;VALUES (&lt;br /&gt;GETDATE(), &lt;br /&gt;@@server)&lt;br /&gt;', &lt;br /&gt;@database_name=N'master', &lt;br /&gt;@flags=0&lt;br /&gt;&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;COMMIT TRANSACTION&lt;br /&gt;&lt;br /&gt;GOTO EndSave&lt;br /&gt;&lt;br /&gt;QuitWithRollback:&lt;br /&gt;IF (@@TRANCOUNT &gt; 0) ROLLBACK TRANSACTION&lt;br /&gt;EndSave:&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;/*Creating the alert and associating it with the Job to be fired */&lt;br /&gt;&lt;br /&gt;USE [msdb]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = N'Respond to Memory_event')&lt;br /&gt;EXEC msdb.dbo.sp_delete_alert @name=N'Respond to memory_event'&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;DECLARE @server_namespace varchar(255)&lt;br /&gt;SET @server_namespace = N'\\.\root\Cimv2\'&lt;br /&gt;&lt;br /&gt;EXEC msdb.dbo.sp_add_alert @name=N'Respond to memory_event', &lt;br /&gt;  @message_id=0, &lt;br /&gt;  @severity=0, &lt;br /&gt;  @enabled=1, &lt;br /&gt;  @delay_between_responses=0, &lt;br /&gt;  @include_event_description_in=0, &lt;br /&gt;  @category_name=N'[Uncategorized]', &lt;br /&gt;  @wmi_namespace=N'\\.\root\Cimv2', &lt;br /&gt;  @wmi_query=N'SELECT * FROM __InstanceModificationEvent WITHIN 10 WHERE TargetInstance ISA ''Win32_PerfFormattedData_PerfOS_Memory'' AND TargetInstance.AvailableBytes &gt; 256', &lt;br /&gt;  @job_name='Capture memory Event' ;&lt;br /&gt;&lt;br /&gt;--EXEC msdb.dbo.sp_add_notification @alert_name=N'Respond to memory_event', @operator_name=N'Test', @notification_method = 1&lt;br /&gt;--GO&lt;br /&gt;&lt;br /&gt;--/* Step 5: Create a stored proc for sending the [Create_user] information as .CSV file */&lt;br /&gt; &lt;br /&gt;--Create proc [dbo].[Deadlock_rpt] &lt;br /&gt;--as&lt;br /&gt;--DECLARE @SQL varchar(Respond to memory_event2000)&lt;br /&gt;--DECLARE @date varchar (2000)&lt;br /&gt;--DECLARE @File varchar(1000)&lt;br /&gt;--select @date= convert(date,GETDATE())&lt;br /&gt;--SET @SQL = 'select * from [Create_user] where flag = 0'&lt;br /&gt;--SET @File = '[Create_user] report'+@date+'.csv'&lt;br /&gt; &lt;br /&gt;--EXECUTE msdb.dbo.sp_send_dbmail&lt;br /&gt;--@profile_name = 'test',&lt;br /&gt;--@recipients = 'your email.com',&lt;br /&gt;--@subject = 'low memory threshold reached...',&lt;br /&gt;--@body = '***URGENT***Attached please find the low memory threshold report',&lt;br /&gt;--@query =@SQL ,&lt;br /&gt;--@attach_query_result_as_file = 1,&lt;br /&gt;--@query_attachment_filename = @file,&lt;br /&gt;--@query_result_header = 1,&lt;br /&gt;--@query_result_separator = ' ',&lt;br /&gt;--@query_result_no_padding = 1,&lt;br /&gt;--@query_result_width = 32767 &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--/* Step 6: Changing the flag to 1 so that next time this information is not sent*/ &lt;br /&gt;--update dbo.[Create_user] set flag = 1 where flag = 0&lt;br /&gt;--go&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-1460878941978148257?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/1460878941978148257/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=1460878941978148257&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1460878941978148257'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1460878941978148257'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/06/using-wmi-and-sql-agent-to-fire-low.html' title='Using WMI and SQL Agent to fire low memory threshold alert ...'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-415671032079490415</id><published>2010-06-19T20:18:00.001+05:30</published><updated>2010-06-19T20:18:32.236+05:30</updated><title type='text'>Printing DBCC inputbuffer for any SPID &gt; 50</title><content type='html'>It helps in many cases .For example if SPIDS are involved in blocking .and we are doing inputbuffer one by one.&lt;br /&gt;For blocking you can just add : and blocked !=0 in the sysprocesses query&lt;br /&gt;Similarly you can modify it for waittype,waittime, CPU etc (as per your need)&lt;br /&gt;&lt;br /&gt;--Input buffers&lt;br /&gt;PRINT 'Input buffer SPIDs'&lt;br /&gt;&lt;br /&gt;declare @spid smallint&lt;br /&gt;declare @i_buff_string char(30) &lt;br /&gt;set nocount on   &lt;br /&gt;declare bufCursor CURSOR FOR SELECT spid from master.dbo.sysprocesses where spid &gt; 50&lt;br /&gt;FOR READ ONLY&lt;br /&gt;open bufCursor&lt;br /&gt;fetch next from bufCursor into @spid &lt;br /&gt;while (@@fetch_status &lt;&gt; -1) &lt;br /&gt;begin &lt;br /&gt;    SET @i_buff_string = ('DBCC INPUTBUFFER (' + convert(char(6),@spid) +')') &lt;br /&gt;    PRINT '-&gt; '+@i_buff_string &lt;br /&gt;    exec (@i_buff_string) &lt;br /&gt;  PRINT ''&lt;br /&gt;    fetch next from bufCursor into @spid &lt;br /&gt;end &lt;br /&gt;close bufCursor&lt;br /&gt;deallocate bufCursor&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-415671032079490415?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/415671032079490415/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=415671032079490415&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/415671032079490415'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/415671032079490415'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/06/printing-dbcc-inputbuffer-for-any-spid.html' title='Printing DBCC inputbuffer for any SPID &gt; 50'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-7424913554886072408</id><published>2010-06-19T19:56:00.000+05:30</published><updated>2010-06-19T20:17:01.681+05:30</updated><title type='text'>Why do we need the Non-clustered Index</title><content type='html'>I was asked this question by an SME , So I thought let me pass on if it makes sense .&lt;br /&gt;&lt;br /&gt;Lets create a table test which has a few columns from Person.address table (Adventureworks database)&lt;br /&gt;select addressid,addressline1,addressline2,postalcode,stateprovinceid into test from Person.Address&lt;br /&gt;&lt;br /&gt;On this table I created clustered index on AddressID and stateprovinceID&lt;br /&gt;CREATE UNIQUE CLUSTERED INDEX [combined index] ON [dbo].[testo] &lt;br /&gt;(&lt;br /&gt; [addressid] ASC,&lt;br /&gt; [stateprovinceid] ASC&lt;br /&gt;)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]&lt;br /&gt;&lt;br /&gt;Another non-clustered index was created with include option&lt;br /&gt;CREATE NONCLUSTERED INDEX [provinceID] ON [dbo].[testo] &lt;br /&gt;(&lt;br /&gt; [postalcode] ASC&lt;br /&gt;)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;*** BUT I WILL DISABLE THE INDEX ********&lt;br /&gt;&lt;br /&gt;Now I ran a few queries:&lt;br /&gt;-----------------------------------&lt;br /&gt;select * from test where postalcode &gt;'98501'&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_SqLnRbOtgHE/TBzU-kJ_NGI/AAAAAAAAAwU/AhSCCki0ezw/s1600/1.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 114px;" src="http://4.bp.blogspot.com/_SqLnRbOtgHE/TBzU-kJ_NGI/AAAAAAAAAwU/AhSCCki0ezw/s400/1.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5484492617552966754" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;select * from test where postalcode &gt;'98501' order by stateprovinceid&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_SqLnRbOtgHE/TBzVcHkNYaI/AAAAAAAAAwk/wsCsNA8DRE0/s1600/2.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 86px;" src="http://4.bp.blogspot.com/_SqLnRbOtgHE/TBzVcHkNYaI/AAAAAAAAAwk/wsCsNA8DRE0/s400/2.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5484493125274395042" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;select postalcode from testo where postalcode &gt;'98501' order by stateprovinceid&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_SqLnRbOtgHE/TBzVqeGQNNI/AAAAAAAAAws/rBA5OAbM7uM/s1600/3.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 104px;" src="http://4.bp.blogspot.com/_SqLnRbOtgHE/TBzVqeGQNNI/AAAAAAAAAws/rBA5OAbM7uM/s400/3.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5484493371840935122" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;select addressline1,addressline2 from testo where postalcode &gt;'98501' order by stateprovinceid&lt;br /&gt;&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_SqLnRbOtgHE/TBzVzZ6tGCI/AAAAAAAAAw0/EnJSWujHFqY/s1600/4.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 59px;" src="http://1.bp.blogspot.com/_SqLnRbOtgHE/TBzVzZ6tGCI/AAAAAAAAAw0/EnJSWujHFqY/s400/4.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5484493525337577506" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Notice that In all the cases above we have the clustered index Scan and not a simple SCAN .&lt;br /&gt;So the clustered index is being used .And since Its visible that a clustered index is being used there is no need of any other index .Why ............because the data itself lies in the clustered index and we can not improve the plan anymore.&lt;br /&gt;&lt;br /&gt;Lets see why a scan would be used &lt;br /&gt;Your Data is sorted on the bases of 2 columns in the clustered index .So any query will use that Index because the data lies there .So in worst to worst case you will have a Clustered Index Scan (Better than a Index scan [heap scan]).&lt;br /&gt;&lt;br /&gt; But why Scan and not Seek &lt;br /&gt; Because the columns you are using in the where clause or the columns you are looking for as an output have no index or you can say they are not indexed (indirectly , working like a &lt;br /&gt;                heap).So , You will do a scan for those Rows .But since its ordered already , So it will be a clustered Scan.&lt;br /&gt;&lt;br /&gt;Now you enable the non-clustered index and run few queries&lt;br /&gt;&lt;br /&gt;select postalcode from testo where postalcode &gt;'98501'&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_SqLnRbOtgHE/TBzV_ZVLjnI/AAAAAAAAAw8/jAHKM83_qMs/s1600/5.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 112px;" src="http://3.bp.blogspot.com/_SqLnRbOtgHE/TBzV_ZVLjnI/AAAAAAAAAw8/jAHKM83_qMs/s400/5.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5484493731338620530" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;It did an index seek .remember it is not a Clustered index seek like below&lt;br /&gt;&lt;br /&gt;select addressid from testo where addressid &lt; 100&lt;br /&gt;&lt;a href="http://1.bp.blogspot.com/_SqLnRbOtgHE/TBzWLolgBcI/AAAAAAAAAxE/sUVKNP7FhmU/s1600/6.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 121px;" src="http://1.bp.blogspot.com/_SqLnRbOtgHE/TBzWLolgBcI/AAAAAAAAAxE/sUVKNP7FhmU/s400/6.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5484493941592032706" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The reason is that In the earlier case a non-cluseterd index was used to find out the postalcode very quickly but since the data was in the clustered index it needed to point to that Leaf and hence some more efforts .But these efforts were far less than Clustered index scan .&lt;br /&gt;&lt;br /&gt;That is the reason we need to Non-clustered index .TO reduce the ROW Lookups or Bookmark lookups.which are the pointers to the clustered index.&lt;br /&gt;&lt;br /&gt;Happy learning!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-7424913554886072408?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/7424913554886072408/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=7424913554886072408&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/7424913554886072408'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/7424913554886072408'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/06/i-was-asked-this-question-by-sme-so-i.html' title='Why do we need the Non-clustered Index'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_SqLnRbOtgHE/TBzU-kJ_NGI/AAAAAAAAAwU/AhSCCki0ezw/s72-c/1.bmp' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-1518599237460504849</id><published>2010-06-19T19:34:00.000+05:30</published><updated>2010-06-19T19:54:38.190+05:30</updated><title type='text'>xp_sendmail: failed with mail error 0x80040111</title><content type='html'>Hi guys,&lt;br /&gt;Its been long since i posted any new stuff ...so far I've posted nothing related SQL 2000 but i thought this one is needed .&lt;br /&gt;&lt;br /&gt;We recently faced a SQL Mail issue on WIN 2k Server .Anyone who has worked on SQL Mail issue in the past would be knowing how irritating this issue can be sometimes.But its actually our dis-interest that makes this issue difficult.Somehow we don't like such issues :) ...Since we resolved this issue and went through different permutations and combinations I would like to discuss this with you all so that in future we can save some time and resources on the same issue.This includes &lt;br /&gt;&lt;br /&gt;-&gt; Some very basic understanding on SQL mail .&lt;br /&gt;-&gt; What you should do/do not do when SQL Mail issue comes up.&lt;br /&gt;&lt;br /&gt;Brief understanding on SQL Mail &lt;br /&gt;--------------------------------&lt;br /&gt;There are two ways you can send mails in SQL Server 2000 (Not talking about 2005 or 2008).&lt;br /&gt;&lt;br /&gt;-&gt; SQL Agent Mail&lt;br /&gt;-&gt; SQL Mail .&lt;br /&gt;&lt;br /&gt;Yes , you heard it right .SQL Agent uses its own Extended M(ail)API session where as SQL Mail uses its own .However,Both SQL Mail and SQL Agent Mail connect with Microsoft Exchange Server, Microsoft Windows NT® Mail, or a Post Office Protocol 3 (POP3) server using Mail Profile. It is possible to use different profiles for SQL Mail and SQL Agent Mail at the same time.&lt;br /&gt;Extended MAPI is nothing but a better version over Simple MAPI .Anyway, we don't have to go in this direction .&lt;br /&gt;&lt;br /&gt;The SPs that we use in SQL Mail are :&lt;br /&gt;&lt;br /&gt;xp_startmail &lt;-- used to start the mail session&lt;br /&gt;xp_sendmail &lt;-- To send mail .This invokes sp_processmail.&lt;br /&gt;xp_findnextmsg &lt;--sp_processmail uses this SP&lt;br /&gt;xp_readmail &lt;-- used by sp_processmail&lt;br /&gt;xp_deletemail&lt;--deletes the message.&lt;br /&gt;sp_processmail &lt;-- processses the mail&lt;br /&gt;xp_stopmail&lt;-- Stops the mail session&lt;br /&gt;&lt;br /&gt;We will concentrate on First two and the last one in the list above.You can read about these SPs under : http://msdn.microsoft.com/en-us/library/ms186841.aspx?PHPSESSID=lm71lj7i6gj5fjtebtb2srl4n3&lt;br /&gt;This link is for sp_findnextmsg but has link to all other SPs and XPs.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The Issue that we faced.&lt;br /&gt;-------------------------&lt;br /&gt;One of the job was not sending the mail after completion .SQL Mail was connecting to Exchange server successfully before .&lt;br /&gt;Outlook 2000 client was installed on the Win 2K server (and was working fine under SQL Server service account).&lt;br /&gt;Although we concentrated mostly troubleshooting SQLMail it was SQL Agent mail issue actually .&lt;br /&gt;But Since troubleshooting steps are same for both , we resolved the issue .&lt;br /&gt;&lt;br /&gt; TroubleShooting done&lt;br /&gt;       &lt;br /&gt; -&gt; Logged in to the Server &gt; opened the QA and ran sp_stopmail .Success&lt;br /&gt; -&gt; Sp_startmail ....Took 10 mins to start and with error.&lt;br /&gt; -&gt; The error was :&lt;br /&gt;  Server: Msg 18025, Level 16, State 1, Line 0&lt;br /&gt;  xp_startmail: failed with mail error 0x80040111&lt;br /&gt;  -&gt; We tried to send the test mail using xp_sendmail&lt;br /&gt;  xp_sendmail 'abhay.chaudhary@in.ibm.com','test'&lt;br /&gt;  Server: Msg 18025, Level 16, State 1, Line 0&lt;br /&gt;  xp_sendmail: failed with mail error 0x80040111&lt;br /&gt; -&gt; Assuming that the Profile might be corrupt we created nwe profile through control panel &gt;&gt; Mail option .&lt;br /&gt; -&gt; To our surprise we could not see that profile in the drop down list of both SQL Mail and Agent properties.&lt;br /&gt; -&gt; So we failed there as well .We have the new profile , but we cant use it .Another Big question ? WHY ?&lt;br /&gt; -&gt; Agent logs were showing this :[260] Unable to start mail session (reason: Unable to logon (reason: Unable to get the default MAPI Message Store due to MAPI  &lt;br /&gt;                    error 273: The information store could not be opened); check the mail profile and/or the SQLSERVERAGENT service startup account)&lt;br /&gt; -&gt; After wasting time on 18025 we concentrated on Error 0x80040111&lt;br /&gt; -&gt; Found KB 238119 (List of Extended MAPI numeric result codes)&lt;br /&gt; -&gt; found that the error means : MAPI_E_LOGON_FAILED&lt;br /&gt; -&gt; Now we were clear that this is an authentication issue.&lt;br /&gt; -&gt; SQL Agent mail was not able to talk to Exchange Server.&lt;br /&gt; -&gt; The exchange Engineer cleared that since both the servers can ping each other and we can use outlook web using the same account under Exchange is running , there is no isues with &lt;br /&gt;                      Exchange Mail box .&lt;br /&gt; -&gt; He was pretty convincing.&lt;br /&gt; -&gt; Then we found that (Actually we already knew that )in the SQL Mail configuration it was mentioned that we need to make sure that in we are logged in to the server using the SQL Server &lt;br /&gt;                      service account.&lt;br /&gt; -&gt; That is what we have not done and were not able to do actually (Since begening) because of some permission issues on that account while logging on to the Win 2k Server.&lt;br /&gt; -&gt; Since rest all trials were failing , we decided to force ourselves for one last time in resolving this issue after loggin gon tho the server using SQL Server domain account .&lt;br /&gt; -&gt; The Intel team helped us in doing that .&lt;br /&gt; -&gt; We logged on to the server &gt;&gt; created a new profile &gt;&gt; Changed the SQL Agent setting to point to that profile (which was now visible..wow).&lt;br /&gt; -&gt; Started the mail session using xp_startmail.&lt;br /&gt;  SQL Mail session started.&lt;br /&gt; -&gt; Sent a test mail : xp_sendmail 'abhay.chaudhary@in.ibm.com','test'&lt;br /&gt;  Mail sent.&lt;br /&gt; -&gt; That resolved the issue.&lt;br /&gt;&lt;br /&gt;Do's to solve this issue&lt;br /&gt;--------------------------&lt;br /&gt;-&gt; Ping the exchange server or the POP3 Server and make sure its a success.&lt;br /&gt;-&gt; Make sure that the Domain account for SQL Server(including agent) , Exchange and OS are same .&lt;br /&gt;-&gt; Stop the mail session first as it might be Stuck.&lt;br /&gt;-&gt; Start the mail session .If it works , fine .&lt;br /&gt;-&gt; If not then read the MAPI error and match it with the KB 238199 to understand the root cause .&lt;br /&gt;-&gt; In one of the situations when I was testing it on Lotus Notes to POP 3 account on Gmail I got 8004011d which means MAPI_E_FAILONEPROVIDER (due to slow network)&lt;br /&gt;-&gt; Check the Agent logs and make sure MAPI32.dll exists (Using MAPI32.DLL from C:\WINDOWS\SYSTEM32 (version 1.0.2536.0))&lt;br /&gt;-&gt; Make sure the mapistub.dll exists in C:\WINDOWS\SYSTEM32 folder &lt;br /&gt;-&gt; You can also test you MAPI profile : xp_test_mapi_profile 'hello'&lt;br /&gt;-&gt; Create the new profile and see if that helps .If it does it means that the previous profile was corrupt(We did not test this in our case and created a new profile straightaway).&lt;br /&gt;&lt;br /&gt;Don'ts&lt;br /&gt;---------&lt;br /&gt;Never try to resolve this issue without logging on to the server with SQL Server service account .&lt;br /&gt;&lt;br /&gt;Hope this helps .&lt;br /&gt;let me know your comments ..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-1518599237460504849?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/1518599237460504849/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=1518599237460504849&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1518599237460504849'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1518599237460504849'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/06/xpsendmail-failed-with-mail-error.html' title='xp_sendmail: failed with mail error 0x80040111'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-8583664565487100562</id><published>2010-01-05T17:18:00.000+05:30</published><updated>2010-01-05T18:05:25.486+05:30</updated><title type='text'>All about locking , blocking and deadlocking ....Part 5</title><content type='html'>&lt;em&gt;&lt;strong&gt;This is the last one in this series .Let me know if you have any comments : Good or Bad (",)&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How to reduce blocking and deadlocks:&lt;/strong&gt;&lt;br /&gt;I can give you one answer from my own and then we will see more : Do not commit the stupidity that I did in the example in the previous post (deadlock example).&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;As a DBA &lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;-&gt; Make sure that there are proper Indexes on tables and that they are actually being used.sometimes we feel relaxed after creating the indexes .But the query might be written in such a way that , that particular index might not be used and we might be doing scan instead of seek .One Such example is not using SARGable arguments (Now dont ask whats that ..we will discuss some other day or refer BOL).&lt;br /&gt;&lt;br /&gt;-&gt; Make sure you rebuild the indexes regularly based on the fragmentation level (you might be having so many scripts to do that).Do not bother to rebuild if the number of pages are less than 1000.rebuilding index will recompute the stats &lt;br /&gt;&lt;br /&gt;-&gt; Check if the Query is doing parallelism .If yes then Try everything else before running the query with maxdop hint.Many a times under CPU pressure the ECIDs have to wait on CPUs as its been taken by other threads.Thus causing blocking and or deadlocking .&lt;br /&gt;&lt;br /&gt;-&gt; Although the auto-update stats is ON by default.It does not mean that you should not update the stats .I will not cover this fact in detail here .Check auto-update statistics in BOL and you will know a lot ....trust me .&lt;br /&gt;&lt;br /&gt;-&gt; Any query that is going to do sorts in tempdb will surely take a lot of time as compared to in database sorting .For more on this check the facts on my Blog entry &lt;a href="http://ms-abhay.blogspot.com/2009/11/sorts-spills-in-tempdb-due-to-incorrect.html"&gt;http://ms-abhay.blogspot.com/2009/11/sorts-spills-in-tempdb-due-to-incorrect.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;-&gt; make sure that you are not facing disk IOs contention even after following steps .Perfmon will show high Disk queue length .Normally DQL of 2 per spindle is OK&lt;br /&gt;&lt;br /&gt;-&gt; Check on what resource the query is waiting using sysprocesses .It might be Network IO as well .&lt;br /&gt;&lt;br /&gt;-&gt; When you do a bulk insert disable the indexes and enable them during the time of least activity so that it can catch up to the new rows and update the stats accordingly .Or better go for rebuilding it after the bulk insert or delete.&lt;br /&gt;&lt;br /&gt;-&gt; Do not play with the locks option in sp_configure .I would suggest to keep the default setting of 0.&lt;br /&gt;&lt;br /&gt;-&gt; Deadlocks can occur due to memory pressure .When concurrent requests are waiting for memory grants that cannot be satisfied with the available memory,a deadlock can occur.For example,two concurrent queries,Q1 and Q2,acquire 10MB and 20MB of memory respectively.If each query needs 30MB and the total available memory is 20MB,then Q1 and Q2 must wait for each other to release memory.This results in a deadlock.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;As a Developer &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;-&gt; Use Temp tables instead of temp variables .Or test both and see which one works better .There is a great debate outside on this topic.&lt;br /&gt;&lt;br /&gt;-&gt; Use as less Adhoc queries as possible .There might be situations where too many adhoc queries kicks off the cached plans of SPs and in turn those SPs will &lt;br /&gt;again be recompiled.If you want to use Adhoc queries use EXEC or sp_executesql and the plans will be cached.E.g. exec ('select * from t2') .First time it took 10 seconds .Second time it took 5 seconds.&lt;br /&gt;&lt;br /&gt;-&gt; Keep Small batches and transactions .Do not run a lot of transactions from one connection or SPs and try to achieve everything in one go.&lt;br /&gt;&lt;br /&gt;-&gt; Try to avoid Sorts in tempdb by creating and calling the temp table from the same SP and not from other SP .Google or Bing on SORT IN TEMPDB&lt;br /&gt;&lt;br /&gt;-&gt; Its not always true to say that more tempdb files will improveperformance .Your SAN should be capable enough to do that .&lt;br /&gt;&lt;br /&gt;-&gt; Choose Isolation level as per requirement .If you can live with read-uncommitted , go for it .&lt;br /&gt;&lt;br /&gt;-&gt; Its not bad to go for Snapshot isolation level but it will stress your tempdb.&lt;br /&gt;&lt;br /&gt;-&gt; Keep your table normalized so that you use the DISTINCT clause as less as possible .But make sure you do not over normalize the tables else you will be    &lt;br /&gt;ending up making your query more complex to understand for optimizer as it will  have more joins .&lt;br /&gt;&lt;br /&gt;-&gt; One of the most important reasons for blocking and deadlocking could be lock escalation .If you have a slightest doubt that your query is going for lock   &lt;br /&gt;escalation , use Lock:Escalation event in profiler and see if its actually happening .If you find it happening , check if the same SPID is the blocker or  &lt;br /&gt;being blocked as well .you can disable lock escalation by enabling trace flag 1211   But I would not suggest that.To avoid lock escalation modify your query &lt;br /&gt;to take less locks.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Tip :&lt;/strong&gt;&lt;br /&gt;Mostly I have seen that, if the deadlocking issue comes right after the application goes live then its the application fault (the way it synchronizes the &lt;br /&gt;access to the data) .But if the application owner says that everything was fine and he is facing the deadlocks all of a suden then some major data change &lt;br /&gt;might have happened in the tables that might be causing blocking and deadlocking .One such cause is " Parameter Sniffing ".&lt;br /&gt;&lt;br /&gt;Sometimes we do a select in such a way that we crosses the threshold of in-database sort and the sort goes to tempdb &lt;br /&gt;(http://ms-abhay.blogspot.com/2009/11/sorts-spills-in-tempdb-due-to-incorrect.html) .In this case we need to keep on testing the query until we find the threshold where the query spills the sorts in the tempdb and reduce the value of the column in the where clause.&lt;br /&gt;&lt;br /&gt;Both Developer and DBA has to work together in resolving such issues.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;SET DEADLOCK_PRIORITY Option&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Sometimes , you might wish that in any case a particular transaction should not be treated as a victim in the event of deadlock.&lt;br /&gt;In that case you can set the deadlock_priority of the trasnaction higher than others.An example could be a case of an update and select , you might be ready &lt;br /&gt;to rollback the select but you want the update to be successful .&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Which session is chosen as the deadlock victim depends on each session's deadlock priority:&lt;/em&gt;&lt;br /&gt;-If both sessions have the same deadlock priority, the instance of SQL Server chooses the session that is less expensive to roll back as the deadlock victim. &lt;br /&gt;For example, if both sessions have set their deadlock priority to HIGH, the  instance will choose as a victim the session it estimates is less costly to roll &lt;br /&gt;back.&lt;br /&gt;&lt;br /&gt;-If the sessions have different deadlock priorities, the session with the lowest &lt;br /&gt;deadlock priority is chosen as the deadlock victim.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;Unresolved Deadlocks&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;You need not to bother about it .If it happens open a case with Microsoft as a prooduct bug .Either they have the hotfix or they dont .&lt;br /&gt;In the error log you will find the deadlock graph and the Dump information .&lt;br /&gt;&lt;br /&gt;*******************************************************************************&lt;br /&gt;2007-09-12 11:43:53.51 spid4s      *&lt;br /&gt;2007-09-12 11:43:53.51 spid4s      * BEGIN STACK DUMP:&lt;br /&gt;2007-09-12 11:43:53.51 spid4s      *   09/12/07 11:43:53 spid 4&lt;br /&gt;2007-09-12 11:43:53.51 spid4s      *&lt;br /&gt;2007-09-12 11:43:53.51 spid4s      * Unresolved deadlock&lt;br /&gt;2007-09-12 11:43:53.51 spid4s      *&lt;br /&gt;2007-09-12 11:43:53.51 spid4s      *&lt;br /&gt;2007-09-12 11:43:53.51 spid4s      *&lt;br /&gt;*******************************************************************************&lt;br /&gt;You will also see Cost:(N/A) and deadlock victim=process0 in the deadlock graph.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;Few references&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;Batch Compilation, Recompilation, and Plan Caching Issues in SQL Server 2005&lt;br /&gt;http://technet.microsoft.com/hi-in/library/cc966425(en-us).aspx&lt;br /&gt;&lt;br /&gt;How to resolve blocking problems that are caused by lock escalation in SQL Server&lt;br /&gt;http://support.microsoft.com/kb/323630&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-8583664565487100562?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/8583664565487100562/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=8583664565487100562&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/8583664565487100562'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/8583664565487100562'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/01/all-about-locking-blocking-and_05.html' title='All about locking , blocking and deadlocking ....Part 5'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-842106431817216805</id><published>2010-01-05T17:07:00.000+05:30</published><updated>2010-01-05T17:18:14.248+05:30</updated><title type='text'>All about locking , blocking and deadlocking ....Part 4</title><content type='html'>continuing from the previous 3 entries ............&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;Blocking &lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;So far we have executed many queries and seen blocking as well.But I would still like to discuss blocking a bit more ...&lt;br /&gt;Use sysprocesses DMV/Table to find blocking .This has 3 advanages .One that you will see only the blocking SPIDs and not all the SPIDs by using sp_lock.&lt;br /&gt;Two , you will be able to see head of the blocking chain. Three , you wil be able to see on what resource the SPID is waiting for .Once you have all the knowledge above you can surely use sp_lock to get some more information .   &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Lab&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1st User &lt;/strong&gt;&lt;br /&gt;set transaction isolation level serializable&lt;br /&gt;begin tran &lt;br /&gt;update t1 set c1 = 3000 where c2 &lt; 3000&lt;br /&gt;--rollback&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;2nd user &lt;/strong&gt;&lt;br /&gt;set transaction isolation level serializable&lt;br /&gt;begin tran&lt;br /&gt;select * from t1&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Now check the sysprocesses DMV (I am using 2005) :&lt;/strong&gt;&lt;br /&gt;select * from sys.sysprocesses where blocked &lt;&gt;0&lt;br /&gt;&lt;br /&gt;You will notice that lastwaittype is LCK_M_IS &lt;br /&gt;This means that the SPID which is being blocked is actually waiting for an IS lock to grab but cannot and being blockd by another spid.&lt;br /&gt;The SPID that is blocking is shown in the "Blocked" column .&lt;br /&gt;You can cross check by running sp_lock &lt;SPID&gt;.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Now if you run one more query :&lt;/strong&gt;&lt;br /&gt;set transaction isolation level serializable&lt;br /&gt;begin tran&lt;br /&gt;select * from t1&lt;br /&gt;&lt;br /&gt;You will notice the now there are 2 rows in the sysprocesses DMV where blocked &lt;&gt;0&lt;br /&gt;here you will see :&lt;br /&gt;&lt;br /&gt;SPID A is blocked by SPID B --&gt; SPID B is blocked by SPID C &lt;br /&gt;So who is the actual culprit ..yes its C and is called as the head of the blockign chain .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Now a tough question for you :&lt;/strong&gt;&lt;br /&gt;Why SPID A is blocked by SPID B and not C ? .....Think :) ..&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Deadlocks&lt;/strong&gt;&lt;br /&gt;you have already seen blocking ..&lt;br /&gt;Lets try our hands at creating a deadlock.I am not going to explain what is a deadlock .&lt;br /&gt;&lt;br /&gt;For the benefit of all I will keep the Isolation level to serializable .&lt;br /&gt;It will help us in creating deadlocks easily .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Lab &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;First do this :&lt;/strong&gt;&lt;br /&gt;select count(*) from t2&lt;br /&gt;select count(*) from t1&lt;br /&gt;&lt;br /&gt;If the number of rows are same then we are good to go .&lt;br /&gt;If not, then drop the table with less number of rows and recreate it with the help of another table .&lt;br /&gt;How to Do it .......check previous updates ...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;First Window :&lt;/strong&gt;&lt;br /&gt;set transaction isolation level serializable&lt;br /&gt;go&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t3 set c2 = 230 where c2 &gt; 1000 and c3 &gt; 700&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Second Window :&lt;/strong&gt;&lt;br /&gt;set transaction isolation level serializable&lt;br /&gt;go&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t2 set c3 = 230 where c2 &gt; 1000 and c3 &gt; 700&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;First Window :&lt;/strong&gt;&lt;br /&gt;begin tran &lt;br /&gt;select * from t2&lt;br /&gt;--rollback&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Second Window :&lt;/strong&gt;&lt;br /&gt;begin tran &lt;br /&gt;select * from t3&lt;br /&gt;--rollback&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You will see that the SPID in second window will be the deadlock victim:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Msg 1205, Level 13, State 56, Line 2&lt;br /&gt;Transaction (Process ID 52) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Like this you can create many deadlocks&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How to capture the deadlock Graph&lt;/strong&gt;&lt;br /&gt;There are 2 ways :&lt;br /&gt;&lt;br /&gt;&lt;em&gt;- Use Traceflag 1204 &lt;-- for 2000 and 1222 &lt;-- for 2005 and above.&lt;br /&gt;- Use WMI class deadlock_graph to capture the graph for SQL Server 2005 and above(for 2000 its a bit tricky .Hence not mentioning it here.)&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Using TraceFlag 1222&lt;/strong&gt;&lt;br /&gt;dbcc traceon(1222 , -1)&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;Create the deadlock (I am creating the same one as mentioned above)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Using WMI Class and SQL Server Agent &lt;/strong&gt;&lt;br /&gt;Please go through one of my previous post : http://ms-abhay.blogspot.com/2009/09/wmi-alert-for-deadlocking-no-need-to.html&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How to read the deadlock graph&lt;/strong&gt;&lt;br /&gt;Check the Error logs and copy the deadlock information on a separate notepad window.&lt;br /&gt;You can find my analysis below:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;deadlock-list&lt;br /&gt; deadlock victim=process968d48&lt;br /&gt;  process-list&lt;br /&gt;   process id=process968d48 taskpriority=0 logused=543996 waitresource=OBJECT: 8:629577281:0  waittime=3359 ownerId=29121 transactionname=user_transaction lasttranstarted=2009-12-28T15:40:39.240 XDES=0x3e8f838 lockMode=IS schedulerid=2 kpid=6124 status=suspended spid=52 sbid=0 ecid=0 priority=0 transcount=2 lastbatchstarted=2009-12-28T15:40:56.500 lastbatchcompleted=2009-12-28T15:40:39.413 lastattention=2009-12-28T15:31:16.907 clientapp=Microsoft SQL Server Management Studio - Query hostname=abchaudh hostpid=1336 loginname=abchaudh\Abhay isolationlevel=serializable (4) xactid=29121 currentdb=8 lockTimeout=4294967295 clientoption1=671090784 clientoption2=390200&lt;br /&gt;    executionStack&lt;br /&gt;     frame procname=adhoc line=2 stmtstart=26 sqlhandle=0x02000000bea8742faf157cd9e8e65d380d705fefe8dfb182&lt;br /&gt;select * from t3     &lt;br /&gt;    inputbuf&lt;br /&gt;begin tran &lt;br /&gt;select * from t3    &lt;br /&gt;   process id=process969018 taskpriority=0 logused=576116 waitresource=OBJECT: 8:597577167:0  waittime=10000 ownerId=28599 transactionname=user_transaction lasttranstarted=2009-12-28T15:40:34.780 XDES=0x3e8f290 lockMode=IS schedulerid=2 kpid=8140 status=suspended spid=53 sbid=0 ecid=0 priority=0 transcount=2 lastbatchstarted=2009-12-28T15:40:49.873 lastbatchcompleted=2009-12-28T15:40:34.907 lastattention=2009-12-28T15:27:27.483 clientapp=Microsoft SQL Server Management Studio - Query hostname=abchaudh hostpid=1336 loginname=abchaudh\Abhay isolationlevel=serializable (4) xactid=28599 currentdb=8 lockTimeout=4294967295 clientoption1=671090784 clientoption2=390200&lt;br /&gt;    executionStack&lt;br /&gt;     frame procname=adhoc line=2 stmtstart=26 sqlhandle=0x02000000b7cdeb20804433e7571f29d85516ff688d005724&lt;br /&gt;select * from t2     &lt;br /&gt;    inputbuf&lt;br /&gt;begin tran &lt;br /&gt;select * from t2    &lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;resource-list&lt;br /&gt;   objectlock lockPartition=0 objid=597577167 subresource=FULL dbid=8 objectname=deadlocktest.dbo.t2 id=lockcc7f700 mode=X associatedObjectId=597577167&lt;br /&gt;    owner-list&lt;br /&gt;     owner id=process968d48 mode=X&lt;br /&gt;    waiter-list&lt;br /&gt;     waiter id=process969018 mode=IS requestType=wait&lt;br /&gt;   objectlock lockPartition=0 objid=629577281 subresource=FULL dbid=8 objectname=deadlocktest.dbo.t3 id=lockcc7f780 mode=X associatedObjectId=629577281&lt;br /&gt;    owner-list&lt;br /&gt;     owner id=process969018 mode=X&lt;br /&gt;    waiter-list&lt;br /&gt;     waiter id=process968d48 mode=IS requestType=wait&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Analysis :&lt;br /&gt;----------&lt;br /&gt;Divide the output into 2 parts : Deadlock list and resource list &lt;br /&gt;&lt;br /&gt;process968d48&lt;br /&gt;--------------&lt;br /&gt;logused=543996&lt;br /&gt;waitresource=OBJECT: 8:629577281:0 &lt;-- here 8 is DBID ,629577281 is the object ID and 0 is heap &lt;br /&gt;lockMode=IS&lt;br /&gt;spid=52 &lt;br /&gt;sbid=0 &lt;-- Its the Batch ID .It will be 0 until the application is using MARS (check BOL for MARS)&lt;br /&gt;ecid=0 &lt;-- zero means no paralelism is going on (Refer BOL for Query Parallelism)&lt;br /&gt;transcount=2 &lt;-- We are running 2 transaction under this SPID (select and update)&lt;br /&gt;isolationlevel=serializable &lt;br /&gt;currentdb=8 &lt;br /&gt;procname=adhoc (select * from t3) &lt;-- Its an adhoc query&lt;br /&gt;inputbuf =&lt;br /&gt;begin tran &lt;br /&gt;select * from t3  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;process969018&lt;br /&gt;--------------&lt;br /&gt;logused=576116 &lt;br /&gt;waitresource=OBJECT: 8:597577167:0 &lt;br /&gt;lockMode=IS &lt;br /&gt;spid=53 &lt;br /&gt;sbid=0 &lt;br /&gt;ecid=0 &lt;br /&gt;transcount=2 &lt;br /&gt;isolationlevel=serializable&lt;br /&gt;currentdb=8 &lt;br /&gt;procname=adhoc (Select * from t2)&lt;br /&gt;inputbuf=&lt;br /&gt;begin tran &lt;br /&gt;select * from t2  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Story &lt;br /&gt;---------&lt;br /&gt;-&gt; At the time of deadlock 2 queries were running (under SPID 52 and 53) .&lt;br /&gt;-&gt; The processes were process968d48 for SPID 52 and process969018 for SPID 53&lt;br /&gt;-&gt; process968d48 took X lock on table T2 and requested IS on table T3 ..which was blocked by process969018&lt;br /&gt;-&gt; process969018 took X lock on table T3 and requested IS on table T2.. which was blocked by process968d48&lt;br /&gt;-&gt; deadlock victim is process968d48&lt;br /&gt;&lt;br /&gt;Why process968d48 is deadlock victim ?&lt;br /&gt;Because it has less undo to rollback .&lt;br /&gt;&lt;br /&gt;How do you know if it has less undo ?&lt;br /&gt;See log used values .&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Rest ..........in next blog ....keep looking ...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-842106431817216805?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/842106431817216805/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=842106431817216805&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/842106431817216805'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/842106431817216805'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2010/01/all-about-locking-blocking-and.html' title='All about locking , blocking and deadlocking ....Part 4'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-3519852030097030795</id><published>2009-12-23T15:38:00.001+05:30</published><updated>2009-12-23T15:38:24.952+05:30</updated><title type='text'>All about locking , blocking and deadlocking ....Part 3</title><content type='html'>Isolation Levels &lt;br /&gt;&lt;br /&gt;Read uncommitted &lt;br /&gt;An isolation level where Dirty Reads , non-Repeatable reads and Phantom reads are possible .&lt;br /&gt;least amount of blocking.&lt;br /&gt;&lt;br /&gt;Read committed &lt;br /&gt;An isolation level where non-Repeatable reads and Phantom reads are possible .&lt;br /&gt;Reades will block writers only until the read is going on .But writers will block readers &lt;br /&gt;&lt;br /&gt;Repeatable read&lt;br /&gt;An isolation level where Phantom reads are possible .&lt;br /&gt;&lt;br /&gt;Serializable&lt;br /&gt;An isolation level where Dirty Reads , Repeatable reads and Phantom reads are not possible .&lt;br /&gt;&lt;br /&gt;Snapshot&lt;br /&gt;This Isolation keeps the previous committed copy of the row in tempdb and hence avoids blocking .It does no Dirty reads , Phantom reads or non-repeatable reads.&lt;br /&gt;I will not be adding any Demos for this Isolation level .You can use all the demos give so far and in future .The only points you need to remember are :&lt;br /&gt;&lt;br /&gt;-&gt; before setting the isolation level to snapshot do &lt;br /&gt;alter database deadlocktest set allow_snapshot_isolation on&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;-&gt; Check the snapshots and rew version using these DMVs&lt;br /&gt;     sys.dm_tran_active_snapshot_database_transactions&lt;br /&gt;     sys.dm_tran_active_transactions&lt;br /&gt;     sys.dm_tran_current_transaction&lt;br /&gt;     sys.dm_tran_transactions_snapshot&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Demo : Dirty Read&lt;br /&gt;I hope you have all the Tables with you that we have created before .&lt;br /&gt;If not , recreate them and we are ready to go :&lt;br /&gt;&lt;br /&gt;1st Window :&lt;br /&gt;&lt;br /&gt;set transaction isolation level read uncommitted &lt;br /&gt;go&lt;br /&gt;begin tran &lt;br /&gt;update t1 set c1 = c1+5&lt;br /&gt;--rollback&lt;br /&gt;&lt;br /&gt;2nd Window :&lt;br /&gt;set transaction isolation level read uncommitted&lt;br /&gt;go&lt;br /&gt;begin tran&lt;br /&gt;select * from t1&lt;br /&gt;--rollback&lt;br /&gt;&lt;br /&gt;There is no blocking and the data that is not committed was read in window 2.This is called as Dirty read where an uncommitted data can be read.&lt;br /&gt;This is only possible in read uncommitted .Try changing the isolation level to read committed and you will see blocking .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Demo : Non-repeatable Read&lt;br /&gt;Since its possible in read-committed isolation level as well , I am usihg it instead of read - uncommitted isolation level .&lt;br /&gt;&lt;br /&gt;1st Window&lt;br /&gt;set transaction isolation level read committed&lt;br /&gt;go&lt;br /&gt;begin tran&lt;br /&gt;select * from t1 where c1=240&lt;br /&gt;--rollback&lt;br /&gt;&lt;br /&gt;2nd Window&lt;br /&gt;set transaction isolation level read committed&lt;br /&gt;go&lt;br /&gt;begin tran &lt;br /&gt;update t1 set c1=240 where c1&gt;200&lt;br /&gt;commit&lt;br /&gt;&lt;br /&gt;3rd Window&lt;br /&gt;begin tran&lt;br /&gt;select * from t1 where c1=240&lt;br /&gt;--rollback&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I know your confusion and anger .You might say I am stupid and its obvious that once the data is committed we can see its committed values :) ...&lt;br /&gt;But lets imagine this :&lt;br /&gt;&lt;br /&gt;-&gt; The select in the first window is on millions of    rows and is still running .&lt;br /&gt;-&gt; The update in the second row quickly comppleted in    few mili seconds .&lt;br /&gt;-&gt; The third window started another select .&lt;br /&gt;-&gt; Finally both 1st and 3rd transactions finished .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The 1st Select * will see a different value and the second one will see a different one .&lt;br /&gt;&lt;br /&gt;Am I right .........:D&lt;br /&gt;&lt;br /&gt;But my question is Why the update transcation was allowed to change the data when there was a select on the whole table in the 1st window ??&lt;br /&gt;If that update is blocked then I cannot see the changed values at all.&lt;br /&gt;Why the update was not blocked even though I am doing a Select under begin tran and still not committed it ??&lt;br /&gt;Why it looks like the S-lock is compatible with X-lock (selecy takes S lock)??&lt;br /&gt;&lt;br /&gt;This is called as non-repeatable read .&lt;br /&gt;&lt;br /&gt;The answer lies in the property of read-committed Isolation level.&lt;br /&gt;In this Isolation level or in read-uncommitted isolation level , the S-locks are not kept till the transaction is rolledback or committed.&lt;br /&gt;As soon as the read is over the lock exits .&lt;br /&gt;&lt;br /&gt;And that is the reason you were able to update the rows .&lt;br /&gt;&lt;br /&gt;Question &lt;br /&gt;In one window you are doing select * from Table X under begin tran.&lt;br /&gt;In another window you are doing Drop table X .&lt;br /&gt;Will you be able to drop the table ??&lt;br /&gt;&lt;br /&gt;I am sure you know the answer .Still try it yourself.&lt;br /&gt;Also ,Try the above lab (where you are updating the rows to 240) in repeatable read or serializable mode.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Demo : Phantom reads&lt;br /&gt;Phantom reads occur when an insert or delete action is performed against a row that belongs to a range of rows being read by another transaction. The transaction's first read of the range of rows shows a row that no longer exists in the second or succeeding read as a result of a deletion by a different transaction.Same is for insertion .&lt;br /&gt;&lt;br /&gt;Imagine , if you are doing select * from customers table where date &gt; 12/12/2012 and date &lt; 15/12/2012&lt;br /&gt;Another transaction inserted 200 more rows in this range after the first transaction read it (but the transaction is not yet committed).The third transaction also did a selsct and got 200 more rows ...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Be ready to get confused again ....but I will try my best not to get you confused ...&lt;br /&gt;&lt;br /&gt;Lets create a small table &lt;br /&gt;&lt;br /&gt;create table phantom (p1 int,p2 int)&lt;br /&gt;go&lt;br /&gt;insert into phantom values (1,2)&lt;br /&gt;go 10&lt;br /&gt;insert into phantom values (3,4)&lt;br /&gt;go 10&lt;br /&gt;insert into phantom values (5,6)&lt;br /&gt;go 10&lt;br /&gt;insert into phantom values (7,8)&lt;br /&gt;go 10&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ist Window &lt;br /&gt;&lt;br /&gt;set transaction isolation level repeatable read &lt;br /&gt;go&lt;br /&gt;begin tran &lt;br /&gt;select * from phantom where p1 &gt; 1 and p2 &gt; 4&lt;br /&gt;[remember this transaction is still running on millions of rows and trying to fetch the data]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2nd window &lt;br /&gt;set transaction isolation level repeatable read &lt;br /&gt;go&lt;br /&gt;begin tran &lt;br /&gt;insert into phantom values (5,8) &lt;br /&gt;commit&lt;br /&gt;&lt;br /&gt;[Assume here that the first transaction has already read the rows falling in to the range 1 and 4 and i s still running ....while second transaction committed very quickly.]&lt;br /&gt;&lt;br /&gt;3rd window&lt;br /&gt;set transaction isolation level repeatable read &lt;br /&gt;go&lt;br /&gt;begin tran &lt;br /&gt;select * from phantom where p1 &gt; 1 and p2 &gt; 4&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;By the end when both 1st and 3rd trasnaction finishes there will be a difference of 1 row.&lt;br /&gt;Try the same in serializable i.e. inserting the new row in 2nd window and see if you are allowed to do so :D .......&lt;br /&gt;Fire me any question you have .........&lt;br /&gt;&lt;br /&gt;Next we will discuss about Blocking and Deadlocking ...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-3519852030097030795?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/3519852030097030795/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=3519852030097030795&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/3519852030097030795'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/3519852030097030795'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/12/all-about-locking-blocking-and_23.html' title='All about locking , blocking and deadlocking ....Part 3'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-5135208326730242744</id><published>2009-12-19T15:20:00.000+05:30</published><updated>2009-12-19T15:44:55.430+05:30</updated><title type='text'>Games Port Play</title><content type='html'>Yesterday evening, I was winding up when my collegue  came and said :&lt;br /&gt;&lt;br /&gt;"I have a 2008 instance which when I connect to shows me the right insance name but the version is 3073 which is 2005 and the databases also belongs to 2005 instance" .&lt;br /&gt;This means that , I invited you to my house #X, you followed a route and came to my house .But you found that its not my house and somebody else's house Y even though the house number is correct  .How is that possible ...........&lt;br /&gt;&lt;br /&gt;After resolving the issue I reproduced the issue for better understanding .&lt;br /&gt;&lt;br /&gt;screenshot :&lt;br /&gt;&lt;br /&gt;I have one 2000 instance , one 2005 instance and one 2008 instance showing below &lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_SqLnRbOtgHE/SyykCIs7ofI/AAAAAAAAArc/lixRxPvK1lk/s1600-h/right.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 340px; height: 53px;" src="http://2.bp.blogspot.com/_SqLnRbOtgHE/SyykCIs7ofI/AAAAAAAAArc/lixRxPvK1lk/s400/right.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5416884808422498802" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I did something and here is the new screenshot :&lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_SqLnRbOtgHE/SyylUVs4PeI/AAAAAAAAArk/gPXu0-SKoOI/s1600-h/wrong.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 340px; height: 63px;" src="http://4.bp.blogspot.com/_SqLnRbOtgHE/SyylUVs4PeI/AAAAAAAAArk/gPXu0-SKoOI/s400/wrong.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5416886220661210594" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Test 1:&lt;br /&gt;-----------&lt;br /&gt;Assuming that there might be some issue with SSMS / SQLWB (in short assuming management Studio got corrupted ), I connected wih the 2008 instance using SQLCMD&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_SqLnRbOtgHE/SyylnO4gtpI/AAAAAAAAArs/1cV0gULFAZc/s1600-h/sqlcmd.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 153px;" src="http://3.bp.blogspot.com/_SqLnRbOtgHE/SyylnO4gtpI/AAAAAAAAArs/1cV0gULFAZc/s400/sqlcmd.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5416886545248466578" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;April is 2008 instance but its showing as 2000 instance .So Management studio is not corrupt and we need not uninstall it .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Test 2 :&lt;br /&gt;-----------&lt;br /&gt;Tried to connect to April using Named Pipe protocol instead of TCPIP&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_SqLnRbOtgHE/Syyl58l9R8I/AAAAAAAAAr0/lU7XjqzKzcU/s1600-h/namedpipes.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 398px; height: 156px;" src="http://3.bp.blogspot.com/_SqLnRbOtgHE/Syyl58l9R8I/AAAAAAAAAr0/lU7XjqzKzcU/s400/namedpipes.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5416886866756323266" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;It was successful and showing the right version 10.0.1600.So there is no isue with the Named pipe query .&lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_SqLnRbOtgHE/SyymJpdNAVI/AAAAAAAAAr8/HfxcctQJsvc/s1600-h/npconnect.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 88px;" src="http://2.bp.blogspot.com/_SqLnRbOtgHE/SyymJpdNAVI/AAAAAAAAAr8/HfxcctQJsvc/s400/npconnect.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5416887136497238354" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Test 3 :&lt;br /&gt;----------&lt;br /&gt;Found the port on which April is listening through registry and tried to connect using the port &lt;br /&gt;&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_SqLnRbOtgHE/Syymwg-76tI/AAAAAAAAAsE/UR0m1LhB_nQ/s1600-h/1414+connect.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 147px;" src="http://4.bp.blogspot.com/_SqLnRbOtgHE/Syymwg-76tI/AAAAAAAAAsE/UR0m1LhB_nQ/s400/1414+connect.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5416887804237703890" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;and the result was :&lt;br /&gt;&lt;br /&gt;&lt;a href="http://3.bp.blogspot.com/_SqLnRbOtgHE/Syym_r5GNbI/AAAAAAAAAsM/B1iauhiVARU/s1600-h/1414+failed.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 88px;" src="http://3.bp.blogspot.com/_SqLnRbOtgHE/Syym_r5GNbI/AAAAAAAAAsM/B1iauhiVARU/s400/1414+failed.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5416888064864040370" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;It means that April is not listening on PORT 1414.Then on which port its listening ??&lt;br /&gt;So I decided to create an alias to force April to listen on 1414 port .&lt;br /&gt;I used Client Network utility (CLICONFG) to create the alias .&lt;br /&gt;Guess what ..........there was already an alias which was meant for April but was pointing to port 1918 .&lt;br /&gt;On 1918 SQL Server 2000 was listening ....[used netstat -abn] ......&lt;br /&gt;Removed that alias and created the new one forcing April to listen on its own port 1414....&lt;br /&gt;And it worked .......2005 also had the same issue ...&lt;br /&gt;&lt;br /&gt;Not sure if its a Bug as its possible only from higher version to lower version and not from lower to higher version &lt;br /&gt;i.e. its possible that SQL 2008 or 2005 listen on 2000 port but not vice versa ...&lt;br /&gt;&lt;br /&gt;Let me log the bug and see what happens ........&lt;br /&gt;&lt;br /&gt;Hence the mistry was resolved ...&lt;br /&gt;&lt;br /&gt;Happy learning .....&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-5135208326730242744?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/5135208326730242744/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=5135208326730242744&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5135208326730242744'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5135208326730242744'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/12/games-port-play.html' title='Games Port Play'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_SqLnRbOtgHE/SyykCIs7ofI/AAAAAAAAArc/lixRxPvK1lk/s72-c/right.bmp' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-6444333986752657511</id><published>2009-12-18T19:08:00.001+05:30</published><updated>2009-12-18T19:08:52.759+05:30</updated><title type='text'>All about locking , blocking and deadlocking ....Part 2</title><content type='html'>Now , we know about :&lt;br /&gt;&lt;br /&gt;Locks &lt;br /&gt;Types of locks (S,U,X)&lt;br /&gt;Lock compatibility with each other .&lt;br /&gt;&lt;br /&gt;Before going further , let me breifly explain you about Intent locks.Mainly Its IS and IX .&lt;br /&gt;&lt;br /&gt;Both Intent-Exclusive and Intent-Shared are used so that there should be no problem for Shared or Exclusive locks .&lt;br /&gt;In other words the traffic police blocks the read if any big minister is about to come , fearing that the minister might get late or stopped if the the road is not blocked for public used .But the road will be actually used only when the minister's vehicle will come .&lt;br /&gt;&lt;br /&gt;So the intent locks are just a way to ensure better concurrency in accessing the data .&lt;br /&gt;For other types of locks please refer BOL or the links I referred in my previous post.&lt;br /&gt;&lt;br /&gt;Lets move forward ....&lt;br /&gt;&lt;br /&gt;Lock Escalation &lt;br /&gt;-----------------&lt;br /&gt;Each lock takes 96 bytes worth memory (lock manager gives it).So the more locks are there the more memory will be used ....&lt;br /&gt;&lt;br /&gt;Under certain circumstances the Engine realizes that the resources are gettin gwasted and that it needs to change the several smaller level locks to fewer higher level locks.This is called as lock escalation .You can overrride by using locking hints (use BOL for locking hints )&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;these circumstances are :&lt;br /&gt;&lt;br /&gt;1)&lt;br /&gt;When a single Transact-SQL statement acquires 5,000 locks on a single table or index.&lt;br /&gt;&lt;br /&gt;2)&lt;br /&gt;When the number of locks in an instance of the Database Engine exceeds memory (60% of Max server memory) or configuration thresholds(using sp-configure 'locks' option).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Test :&lt;br /&gt;--------&lt;br /&gt;Lock escalation LAB &lt;br /&gt;====================&lt;br /&gt;&lt;br /&gt;Under sp_configure setting for 5000 locks&lt;br /&gt;------------------------------------------&lt;br /&gt;&lt;br /&gt;use master &lt;br /&gt;go&lt;br /&gt;sp_configure 'locks',5000&lt;br /&gt;go&lt;br /&gt;reconfigure with override&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Restart the instance as this setting is non dynamic .Then copy the code below in one query window .&lt;br /&gt;After creating the table run the first update statement unde begin tran and notice the number of locks using sp_locks.&lt;br /&gt;Then rollback the tran and try with another update statement .You will notice that before the number of locks reaches 60% of 5000 lock escalation occurs.&lt;br /&gt;&lt;br /&gt;USE [deadlocktest]&lt;br /&gt;GO&lt;br /&gt;SET ANSI_NULLS ON&lt;br /&gt;GO&lt;br /&gt;SET QUOTED_IDENTIFIER ON&lt;br /&gt;GO&lt;br /&gt;SET ANSI_PADDING ON&lt;br /&gt;GO&lt;br /&gt;CREATE TABLE [dbo].[t1](&lt;br /&gt; [c1] [int] NULL,&lt;br /&gt; [c2] [int] NULL,&lt;br /&gt; [c3] [int] NULL,&lt;br /&gt; [c4] [char](5000) NULL&lt;br /&gt;) ON [PRIMARY]&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;SET ANSI_PADDING OFF&lt;br /&gt;GO&lt;br /&gt;declare @val int&lt;br /&gt;set @val = 2000&lt;br /&gt;while @val &gt;0&lt;br /&gt;begin &lt;br /&gt;insert into t1 values (@val,@val,@val,@val)&lt;br /&gt;set @val=@val-1&lt;br /&gt;end&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;update t1 set c2 = 1600 where c1 &gt; 700 and c1 &lt;1000&lt;br /&gt;go&lt;br /&gt;update t1 set c2 = 1650 where c1 &gt; 900 and c1 &lt;1200&lt;br /&gt;go&lt;br /&gt;update t1 set c2 = 1700 where c1 &gt; 1100 and c1 &lt;1400&lt;br /&gt;go&lt;br /&gt;update t1 set c2 = 1800 where c1 &gt; 1300 and c1 &lt;1600&lt;br /&gt;go&lt;br /&gt;update t1 set c2 = 1850 where c1 &gt; 1500 and c1 &lt;1800&lt;br /&gt;go&lt;br /&gt;update t1 set c2 = 1900 where c1 &gt; 1700 and c1 &lt;2000&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t1 set c2 = 231 where c2 &gt; 1800 and c3 &gt; 700&lt;br /&gt;--rollback&lt;br /&gt;--sp_lock&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t1 set c2 = 231 where c2 &gt; 1700 and c3 &gt; 700&lt;br /&gt;--rollback&lt;br /&gt;--sp_lock&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t1 set c2 = 231 where c2 &gt; 1655 and c3 &gt; 700&lt;br /&gt;--rollback&lt;br /&gt;--sp_lock&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t1 set c2 = 231 where c2 &gt; 1654 and c3 &gt; 700&lt;br /&gt;--rollback&lt;br /&gt;--sp_lock&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t1 set c2 = 231 where c2 &gt; 1650 and c3 &gt; 700&lt;br /&gt;--rollback&lt;br /&gt;--sp_lock&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t1 set c2 = 231 where c2 &gt; 1600 and c3 &gt; 700&lt;br /&gt;--rollback&lt;br /&gt;--sp_lock&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t1 set c2 = 231 where c2 &gt; 1550 and c3 &gt; 700&lt;br /&gt;sp_lock&lt;br /&gt;rollback&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Under sp_configure setting for 0 locks(which means maximum)&lt;br /&gt;-----------------------------------------------------------&lt;br /&gt;&lt;br /&gt;The table and data is same .Just run the update queries below as you were running above and roll them back after checking the number of locks.&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t1 set c2 = 231 where c2 &gt; 1800 and c3 &gt; 700&lt;br /&gt;--rollback&lt;br /&gt;--sp_lock&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t1 set c2 = 231 where c2 &gt; 1700 and c3 &gt; 700&lt;br /&gt;--rollback&lt;br /&gt;--sp_lock&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t1 set c2 = 231 where c2 &gt; 1655 and c3 &gt; 700&lt;br /&gt;--rollback&lt;br /&gt;--sp_lock&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t1 set c2 = 231 where c2 &gt; 1600 and c3 &gt; 700&lt;br /&gt;--rollback&lt;br /&gt;--sp_lock&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t1 set c2 = 231 where c2 &gt; 1550 and c3 &gt; 700&lt;br /&gt;--sp_lock&lt;br /&gt;--rollback&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;update dbo.t1 set c2 = 231 where c2 &gt; 100 and c3 &gt; 200&lt;br /&gt;--rollback&lt;br /&gt;--sp_lock&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After knowing about locks , their compatibility and lock escalation lets talk about Isolation levels .&lt;br /&gt;Broadly , there are 4 Isolation levels :&lt;br /&gt;&lt;br /&gt;-Read Uncommitted &lt;br /&gt;-Read committed &lt;br /&gt;-Repeatable read &lt;br /&gt;-Serializable &lt;br /&gt;&lt;br /&gt;SQL Server 2005 introduced to more choices &lt;br /&gt;-READ_COMMITTED_SNAPSHOT option for Read committed Isolation level &lt;br /&gt;-Snapshot Isolation Level &lt;br /&gt;&lt;br /&gt;We differentiate the Isolation levels on the basis of Dirty Reads , Non-repeatable reads and Phantom reads.&lt;br /&gt;we need to know about them first .But if I start explaining them I will use these isolation levels again and you will be confused.&lt;br /&gt;So I will be explaining these three reads as well as Isolation levels in parallel .&lt;br /&gt;for theory purpose :&lt;br /&gt;&lt;br /&gt;Dirty reads : We can read the uncommitted data &lt;br /&gt;Repeatable read : A transaction Selects the data without committing &gt;&gt; B transaction is able to modify the data &gt;&gt; A transaction sees the changed data .&lt;br /&gt;Phantom reads : the ability to insert the data by one transaction in to the range of values which is being read by other transaction .&lt;br /&gt;&lt;br /&gt;Rest ...............in next blog ..&lt;br /&gt;&lt;br /&gt;Happy learning ..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-6444333986752657511?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/6444333986752657511/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=6444333986752657511&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/6444333986752657511'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/6444333986752657511'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/12/all-about-locking-blocking-and_18.html' title='All about locking , blocking and deadlocking ....Part 2'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-8638712148713893767</id><published>2009-12-17T19:10:00.000+05:30</published><updated>2009-12-17T19:11:58.596+05:30</updated><title type='text'>All about locking , blocking and deadlocking ....Part 1</title><content type='html'>Locks &lt;br /&gt;------&lt;br /&gt;Locks are the objects that helps in access synchronization for objects like Schema , database , tables , extents ect .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Types of locks &lt;br /&gt;---------------&lt;br /&gt;&lt;br /&gt;Shared (S) locks&lt;br /&gt;-----------------&lt;br /&gt;allows us to read the data by running the select queries .During the time Shared lock exist no other transaction can modify the data being read .The good part it that these locks are released as soon as the select completes even though the transaction might still be running .But there is an exception .This does not hold true if the isolation level is Repeatable Read or serializable .Why ???? because the Shared locks are not released and are kept till the transaction commits or rolls back .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Test &lt;br /&gt;-----&lt;br /&gt;&lt;br /&gt;1st Qquery window&lt;br /&gt;-------------------&lt;br /&gt;Create table Shared_test(sh int)&lt;br /&gt;go&lt;br /&gt;declare @sht int&lt;br /&gt;set @sht=50&lt;br /&gt;while @sht &gt;0&lt;br /&gt;begin &lt;br /&gt;Insert into shared_test values (@sht)  &lt;br /&gt;set @sht=@sht-1&lt;br /&gt;end&lt;br /&gt;go&lt;br /&gt;begin tran &lt;br /&gt;select * from shared_test&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2nd Qquery window&lt;br /&gt;------------------ &lt;br /&gt;sp_lock&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;/*you will notice that there is no lock on that object*/&lt;br /&gt;&lt;br /&gt;drop table shared_test&lt;br /&gt;go &lt;br /&gt;&lt;br /&gt;/*The drop will be successful*/&lt;br /&gt;&lt;br /&gt;Again 1st Qquery window&lt;br /&gt;-----------------------&lt;br /&gt;Rollback&lt;br /&gt;go&lt;br /&gt;set transaction isolation level repeatable read&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;Create table Shared_test(sh int)&lt;br /&gt;go&lt;br /&gt;declare @sht int&lt;br /&gt;set @sht=50&lt;br /&gt;while @sht &gt;0&lt;br /&gt;begin &lt;br /&gt;Insert into shared_test values (@sht)  &lt;br /&gt;set @sht=@sht-1&lt;br /&gt;end&lt;br /&gt;go&lt;br /&gt;begin tran &lt;br /&gt;select * from shared_test&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Again 2nd Qquery window&lt;br /&gt;-------------------------&lt;br /&gt;sp_lock&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;/*you will notice that there is no lock on that object*/&lt;br /&gt;&lt;br /&gt;drop table shared_test&lt;br /&gt;go &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Result:&lt;br /&gt;---------&lt;br /&gt;You will see that there are a lot of shared locks on the RID (row identifier for each row)and the Drop will be blocked (try doing sp_lock from another window to see the SCH-M lock in wait state).&lt;br /&gt;&lt;br /&gt;Compatibility &lt;br /&gt;--------------&lt;br /&gt;Shared locks are compatible only with Shared , Intent Shared and update locks.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Exclusive(X) locks&lt;br /&gt;-------------------&lt;br /&gt;Its the most strict lock .Unless you are in read-uncommitted isolation level or using NOLOCK hint you will be blocked...&lt;br /&gt;&lt;br /&gt;Compatibility &lt;br /&gt;---------------&lt;br /&gt;Exclusive lock will only be compatible with SCH-S(Shared Schema) and RI-N(Insert Range Null) locks.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Update (U) locks&lt;br /&gt;-----------------&lt;br /&gt;Before understanding about the update locks let me tell you that whenever we update , insert or delete we do two operations : Searching where to insert update or delete and doing that action .&lt;br /&gt;&lt;br /&gt;Seaching is done using Shared locks and completing the action of insert , update or delete will be done by the exclusive lock (both covered above).&lt;br /&gt;&lt;br /&gt;Other important point that you have read above (search where (",)..) that in isolation level higher than read committed the shared locks are kept and not released till the end of transaction .So Imagine that there is no UPDATE locks and you and your friend both are updating x rows to a different values in the same table from 2 different client machines , at the same time and in isolation level repeatable read (we will learn about Isolation levels in sometime ) .I forgot to mention that the transaction is not committed.since the shared locks are compatible with shared locks , you both will be granted the shared locks ....fine..&lt;br /&gt;&lt;br /&gt;Now , the X mode lock of A friend is not compatible with S mode lock of another friend named B ..so Blocking occure as X mode is not able to get converted to S mode .Similarly , the same will happen with B friend as well (I will leave it up to you to guess)...and this will cause deadlock..&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Update lock will ensure that No two transactions can try to update the same resource at the same time ...further till the update resource is doing the searching it will show you as U in sp_lock .The moment it tries to modify the row , U mode disappear and X mode is shown.&lt;br /&gt;&lt;br /&gt;Test :&lt;br /&gt;&lt;br /&gt;I am sure you still have the same two queryanalyzer windows open with repeatable read isolation level.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1st Query Window &lt;br /&gt;------------------&lt;br /&gt;There is already a select going on .But for your understanding I am typing the same again :&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;select * from shared_test&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2nd Query Window&lt;br /&gt;-----------------&lt;br /&gt;If you have not yet stopped the previous transaction of dropping the table , then stop it .&lt;br /&gt;run this command &lt;br /&gt;&lt;br /&gt;begin tran&lt;br /&gt;update Shared_test set sh=(sh*2) where sh &gt; 35&lt;br /&gt;&lt;br /&gt;It will be blocked for sure &lt;br /&gt;&lt;br /&gt;1st Query Window &lt;br /&gt;------------------&lt;br /&gt;sp_lock&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Result:&lt;br /&gt;---------&lt;br /&gt;among other locks, you will see(modified for better view) :&lt;br /&gt;&lt;br /&gt;51 RID  1:18773:0  X    CNVT&lt;br /&gt;51 TAB             IX   GRANT&lt;br /&gt;51 PAG  1:18773    IX   GRANT&lt;br /&gt;51 RID  1:18773:0  U    GRANT&lt;br /&gt;53 RID  1:18773:0  S    GRANT&lt;br /&gt;53 PAG  1:18773    IS   GRANT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here ,&lt;br /&gt;18873 is the page id&lt;br /&gt;1 is the datafile&lt;br /&gt;0 is the row id&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1)&lt;br /&gt;SPID 53 took IS lock on page 18773 and then S lock on rowid 0 fearing if someone tries to modify the page should be blocked ....agreed&lt;br /&gt;&lt;br /&gt;2)&lt;br /&gt;SPID 51 took U lock row id 0 of page 18773 which is allowed as S and U locks are compatible.Remember internally its also S lock at this moment .The moment it tries to change something it will be converted to X lock and will no forther be U lock any more ---&gt; 51 then moved ahead and before trying to take the X lock on the RID it first took the IX lock on the page (in case someone drops the object which its trying to modify)which is granted because IS and IX are compatible .&lt;br /&gt;&lt;br /&gt;But when U lock on RID 1:18773:0 tried to convert in to X lock , It got blocked and you can see CNVT ..&lt;br /&gt;&lt;br /&gt;But this test was not exactly the example that I gave when I was talking about the U locks&lt;br /&gt;&lt;br /&gt;So lets try what i said ...2 updates on the same table and same rows ...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Test &lt;br /&gt;-----&lt;br /&gt;make sure you rollback all the transactions on the 2 QA windows and remove all the query text .&lt;br /&gt;&lt;br /&gt;1st Window &lt;br /&gt;------------&lt;br /&gt;Set transaction isolation level repeatable read&lt;br /&gt;go&lt;br /&gt;begin tran&lt;br /&gt;update Shared_test set sh=(sh*2) where sh &gt; 35&lt;br /&gt;&lt;br /&gt;2nd window &lt;br /&gt;------------&lt;br /&gt;Set transaction isolation level repeatable read&lt;br /&gt;go&lt;br /&gt;begin tran&lt;br /&gt;update Shared_test set sh=(sh*2) where sh &gt; 35&lt;br /&gt;&lt;br /&gt;1st Window &lt;br /&gt;------------&lt;br /&gt;sp_lock&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Results:&lt;br /&gt;-----------&lt;br /&gt;&lt;br /&gt;51 741577680  PAG  1:18773    IU  GRANT&lt;br /&gt;51 741577680  RID  1:18773:0  U   WAIT&lt;br /&gt;51 741577680  TAB             IX  GRANT&lt;br /&gt;53 741577680  TAB             IX  GRANT&lt;br /&gt;53 741577680  PAG  1:18773    IX  GRANT&lt;br /&gt;53 741577680  RID  1:18773:0  X   GRANT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1)&lt;br /&gt;&lt;br /&gt;53 took IX on page before X on rowid (I will explain later on why IX and IS are taken) which is right and then IX on table &lt;br /&gt;&lt;br /&gt;2)&lt;br /&gt;&lt;br /&gt;53 also took IX on table (IX and IX are compatible) and IU on page (IX and IU are compatible) .But U and X are not compatible and hence blocking.Had there been no U it would have been a deadlock ....&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Like this do some testing on your own and gain some knowlwdge..&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Referance :&lt;br /&gt;Lock Compatibility (Database Engine):&lt;br /&gt;http://msdn.microsoft.com/en-us/library/ms186396(SQL.90).aspx&lt;br /&gt;&lt;br /&gt;SP_LOCK :&lt;br /&gt;http://msdn.microsoft.com/en-us/library/aa238824(SQL.80).aspx&lt;br /&gt;&lt;br /&gt;Happy learning !!!!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-8638712148713893767?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/8638712148713893767/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=8638712148713893767&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/8638712148713893767'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/8638712148713893767'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/12/all-about-locking-blocking-and.html' title='All about locking , blocking and deadlocking ....Part 1'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-1380644777125158303</id><published>2009-12-16T13:37:00.000+05:30</published><updated>2009-12-16T13:41:38.674+05:30</updated><title type='text'>Let me know what you would like me to post and research upon :)</title><content type='html'>Dear Blog Visitors ,&lt;br /&gt;&lt;br /&gt;So far I have been blogging on the issues i have faced and research done related to SQL Server 2005 (not yet started 2008).&lt;br /&gt;&lt;br /&gt;However , This might or might not interest you as the probability of you facing the same issue as I have faced is rare ..&lt;br /&gt;&lt;br /&gt;So for the benefit of all , I am ready to assist anyone on the SQL Server issues or any kind of request ..&lt;br /&gt;&lt;br /&gt;Please add your requests as comments or mail me at hi_abhay78@yahoo.co.in / 1978abhay@gmail.com&lt;br /&gt;&lt;br /&gt;Happy learning ...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-1380644777125158303?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/1380644777125158303/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=1380644777125158303&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1380644777125158303'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1380644777125158303'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/12/let-me-know-what-you-would-like-me-to.html' title='Let me know what you would like me to post and research upon :)'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-7851144889538556445</id><published>2009-11-27T14:38:00.000+05:30</published><updated>2009-11-27T19:46:58.640+05:30</updated><title type='text'>Sorts Spills in tempdb due to incorrect behavour by Query optimizer...</title><content type='html'>This one is really bothering me .I tried n tried n tried but failed to understand why is it happening ....&lt;br /&gt;&lt;br /&gt;To give you a brief description , A query runs in 25-45 ms for x rows but the same query runs 15-20 times slower if i just add 1 row or a dozen more rows in some other caese (you will see it later)...If i see the execution plans , its totally identical .The only difference is that , the query which is slower does sorting in tempdb instead of in the user database where its been executing ...&lt;br /&gt;&lt;br /&gt;Here we go :&lt;br /&gt;&lt;br /&gt;create table SQLDBA (a1 int primary key clustered,a2 int,a3 char(2000))&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;begin tran &lt;br /&gt;go&lt;br /&gt;declare @i int&lt;br /&gt;set @i=1&lt;br /&gt;while @i &lt;=200000&lt;br /&gt;begin &lt;br /&gt;insert into SQLDBA values (@i,rand() * 2000000,replicate('a',2000))&lt;br /&gt;set @i=@i+1&lt;br /&gt;end&lt;br /&gt;commit tran&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;update statistics SQLDBA with fullscan&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So , we created a table with 3 columns and inserted 200000 rows to it .&lt;br /&gt;Now I will  run 2 queries :&lt;br /&gt;&lt;br /&gt;set statistics time on &lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;/* Good Query */&lt;br /&gt;declare @a1 int,@a2 int , @a3 char(2000)&lt;br /&gt;select @a1=a1 ,@a2=a2,@a3=a3 from SQLDBA&lt;br /&gt;Where a1 &lt;3000&lt;br /&gt;order by a2&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;/* Bad Query */&lt;br /&gt;declare @a1 int,@a2 int , @a3 char(2000)&lt;br /&gt;select @a1=a1 ,@a2=a2,@a3=a3 from SQLDBA&lt;br /&gt;Where a1 &lt;3079&lt;br /&gt;order by a2&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;Notice that there are only 79 more rows .But if you execute them on SQL Server 2005 SP3 as I did with 2 GB RAM , the 1st query runs in approax 15-22 secs .While the second query runs in 320-410 secs.Try it yourself .You will see some difference in duration as its hardware specific.Also , in my case it was running OK till 3078 rows . Yes, the execution time when a1 &lt;3000 or a1 &lt;3078 is almost similar .If I increase just 1 more row it degrades the performance .&lt;br /&gt;&lt;br /&gt;NOTE : You might have to find out this threshold limit on your machine .In my case it was 3078 .The moment I use 3079 ..Booooommmmmmmmm&lt;br /&gt;&lt;br /&gt;So why its happening :D ......&lt;br /&gt;&lt;br /&gt;-Setting Statistics profile to ON showed that The Subtree cost is 2.5% more ..which is fine .&lt;br /&gt;&lt;br /&gt;-Setting Statistics IO to ON showed :&lt;br /&gt;&lt;br /&gt;Table 'SQLDBA'. Scan count 1, logical reads 1007, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.&lt;br /&gt;&lt;br /&gt;SQL Server Execution Times:&lt;br /&gt;   CPU time = 31 ms,  elapsed time = 34 ms.&lt;br /&gt;SQL Server parse and compile time: &lt;br /&gt;   CPU time = 0 ms, elapsed time = 1 ms.&lt;br /&gt;&lt;br /&gt;Table 'SQLDBA'. Scan count 1, logical reads 1034, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.&lt;br /&gt;&lt;br /&gt;SQL Server Execution Times:&lt;br /&gt;   CPU time = 16 ms,  elapsed time = 344 ms.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So , looks like this is Neither a CPU issue (query that runs faster is taking more CPU time) nor an IO issue as there are no physical reads.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;One thing that I found when I took the XML output of the execution plan was that the good query was always taking compile time 2 and the bad query was taking 0 ....this was again strange to me.&lt;br /&gt;&lt;br /&gt;Totaly stuck ..........&lt;br /&gt;&lt;br /&gt;Then I searched many DMVs related to query execution and used  sys.dm_exec_query_memory_grants DMV which show the row for each query that is waiting for the memory or those waited and acquired but will not show the querries that do not have to wait for the memory grant .&lt;br /&gt;&lt;br /&gt;surprisingly , it was showing only one query in the output and that was the query taking more time .Strange but true .Why its waiting for memory when there is enough RAM on my server and max server memory is unlimited.&lt;br /&gt;&lt;br /&gt;sys.dm_exec_query_stats also shows that bad query is doing around 100 physical reads while good one is doing none.&lt;br /&gt;&lt;br /&gt;Then i queried sys.dm_exec_query_memory_grants:&lt;br /&gt;&lt;br /&gt;select granted_memory_kb,used_memory_kb,max_used_memory_kb&lt;br /&gt;from sys.dm_exec_query_memory_grants&lt;br /&gt;where session_id in (51,52)&lt;br /&gt;&lt;br /&gt;found that good query is using very less memory out of granted but bad query using full and more then that .....how ........&lt;br /&gt;&lt;br /&gt;Because whatever extra memory it needs for sorting is coming form tempdb :&lt;br /&gt;&lt;br /&gt;select num_of_reads,num_of_bytes_read,num_of_writes,num_of_bytes_written&lt;br /&gt;From sys.dm_io_virtual_file_stats(db_id('tempdb'),1)&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So looks like Optimizer is not able to allocate the right amount of memory to the bad query such that it does not go to tempdb .......NOPE i am incorrect i think ..because if you see the number of rows in where condition the amount of memory given looks directly proportional .....S oallocating memory to the query does not seems to be a problem here ..the problem is why the query is using more memory that it needs to spill to tempdb .....&lt;br /&gt;&lt;br /&gt;Let me give you one more example that will further open your eyes :D ...&lt;br /&gt;&lt;br /&gt;set statistics time on &lt;br /&gt;GO&lt;br /&gt;declare @a1 int,@a2 int , @a3 char(2000)  &lt;br /&gt;select top 100 @a1=a1 ,@a2=a2,@a3=a3 from SQLDBA  &lt;br /&gt;Where a1 &lt;3000  &lt;br /&gt;order by a2&lt;br /&gt;&lt;br /&gt;Go&lt;br /&gt;&lt;br /&gt;declare @a1 int,@a2 int , @a3 char(2000)  &lt;br /&gt;select top 101 @a1=a1 ,@a2=a2,@a3=a3 from SQLDBA&lt;br /&gt;Where a1 &lt;3000  &lt;br /&gt;order by a2&lt;br /&gt;&lt;br /&gt;Now , these queries are identical in any respect except that in the second query I am doing select top 101 ...just 1 row extra ....and see the difference ...HELL ....&lt;br /&gt;And the status is same here if you go through the DMVs etc ..Even if you wrap up in a SP or use different hints ....it wont help ...&lt;br /&gt;&lt;br /&gt;However you will see that In this case i.e. the second one 1 MB of memory is given to both the queries and nonoe of them is consuming the complete memory given ...but still the bad query is doing Sort spills to tempDB .....So its proved that granting of memory to the queries by the optimizer is Correct ...but its the way query sorts in tempdb and also the usage of memory by the query that looks incorrect here ...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So whats happening ........ :D ...Why just one extra row makes the query to spill to tempdb for sorting ....(use profiler to see if sorting in happening)..&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;NOW , TRY THIS ....&lt;br /&gt;&lt;br /&gt;On my machine i have 2GB  RAM .....i capped max server memory to 100MB...&lt;br /&gt;And then the query was running fine top 100 and top 101 and the previous query all are running well except that the bad query takes more time once in 7-8 attampts (sometimes less or sometimes more)....&lt;br /&gt;&lt;br /&gt;Looks like something is related to memory regions or chunks ...not sure , I may be incorrect ....Something is really wrong .....&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Filing a bug ..&lt;br /&gt;&lt;br /&gt;Happy learning ...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-7851144889538556445?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/7851144889538556445/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=7851144889538556445&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/7851144889538556445'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/7851144889538556445'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/11/sorts-spills-in-tempdb-due-to-incorrect.html' title='Sorts Spills in tempdb due to incorrect behavour by Query optimizer...'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-7570662633020365123</id><published>2009-11-20T13:42:00.000+05:30</published><updated>2009-11-20T14:52:57.930+05:30</updated><title type='text'>Creating SQL Server Alerts using WMI classes- Part 1</title><content type='html'>When we create alerts or when we try to create script we search net a lot .We get some thing but we do not get all what we look for .And then we stop pursuing it ...&lt;br /&gt;&lt;br /&gt;I was given a task to create SQl Server alerts (as many as I can).I could find a couple of scripts ready but that did not satisfy my requirement as everyone creats the scripts as per their needs .&lt;br /&gt;&lt;br /&gt;So I decided to do everything on my own and hence sharing my experiance with you .&lt;br /&gt;To know what kind of alerts you can create go through this file &lt;br /&gt;&lt;br /&gt;&lt;a href="http://2.bp.blogspot.com/_SqLnRbOtgHE/SwZTlHXtO2I/AAAAAAAAAp8/TaoUIUUah3w/s1600/alert_list.gif"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 89px; height: 400px;" src="http://2.bp.blogspot.com/_SqLnRbOtgHE/SwZTlHXtO2I/AAAAAAAAAp8/TaoUIUUah3w/s400/alert_list.gif" border="0" alt=""id="BLOGGER_PHOTO_ID_5406100299803605858" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You will be amazed to see that almost everything is covered here :-) ..&lt;br /&gt;&lt;br /&gt;Let us start now by creating an alert that will notify us whenever a new database is created .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Pre-requsites :&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;-&gt; Need to be SQL Server 2005 SP2 or above or SQL Server 2008 as there is a bug in RTM or SP1 .&lt;br /&gt;&lt;br /&gt;-&gt; We need to execute it in master (do not change the script to be run in your user database).This is because Master captures the metadata of all the databases including itself .If you create it in anyother database then it will not work .Other scripts will also work only for that user database .&lt;br /&gt;&lt;br /&gt;-&gt; Make sure the SQL Server Agent is started and make sure that "REPLACE TOKENS FOR ALL JOB RESPONSES TO ALERTS" option is checked under Agent properties -&gt; Alert system .&lt;br /&gt;&lt;br /&gt;-&gt; Read the code a few times and understand it .You might have to change it as per your need .&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;CODE : &lt;br /&gt;Part 1:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;/*******************************************************************************************&lt;br /&gt;*  This script will create an Alert to Monitor Create DATABASE event&lt;br /&gt;*  The alert will run a job and the job will enter data in a table.&lt;br /&gt;*&lt;br /&gt;*  For any suggestion contact :gur.sethi@in.ibm.com and abhay.chaudhary@in.ibm.com&lt;br /&gt;*******************************************************************************************/&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* Step 1: creating the table to capture the Event information */&lt;br /&gt;&lt;br /&gt;USE Master&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Create_database]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)&lt;br /&gt;DROP TABLE [dbo].[Create_database]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;CREATE TABLE [dbo].[Create_database] (&lt;br /&gt;[PostTime] [datetime] NOT NULL ,&lt;br /&gt;[Instance] varchar(20),&lt;br /&gt;[DatabaseName] varchar(20),&lt;br /&gt;[computerName] Varchar(20),&lt;br /&gt;[Loginname] Varchar(20),&lt;br /&gt;[TSQLCommand] varchar (1000),&lt;br /&gt;[RecordID] [int] IDENTITY (1,1) NOT FOR REPLICATION NOT NULL,&lt;br /&gt;[Flag] [int] NOT NULL CONSTRAINT [DF_Create_database_Flag]  DEFAULT ((0))&lt;br /&gt;) ON [PRIMARY]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;CREATE INDEX [Create_database_IDX01] ON [dbo].[Create_database]([Posttime]) WITH FILLFACTOR = 100 ON [PRIMARY]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;/*Step 2 : Creating the Job that will enter values into the table created above*/&lt;br /&gt;/*Service account and sql operator option are optional and hence commented*/&lt;br /&gt;&lt;br /&gt;USE [msdb]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = N'Capture Create_Database Event')&lt;br /&gt;EXEC msdb.dbo.sp_delete_job @job_name = N'Capture Create_Database Event', @delete_unused_schedule=1&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;--DECLARE @ServiceAccount varchar(128)&lt;br /&gt;--SET @ServiceAccount = N'&lt;job_owner_account&gt;'&lt;br /&gt;--DECLARE @SQLOperator varchar(128)&lt;br /&gt;--SET @SQLOperator = N'&lt;sql_agent_operator&gt;'&lt;br /&gt;&lt;br /&gt;BEGIN TRANSACTION&lt;br /&gt;DECLARE @ReturnCode INT&lt;br /&gt;SELECT @ReturnCode = 0&lt;br /&gt;&lt;br /&gt;IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)&lt;br /&gt;BEGIN&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;DECLARE @jobId BINARY(16)&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Capture Create_Database Event', &lt;br /&gt;@enabled=1, &lt;br /&gt;@notify_level_eventlog=2, &lt;br /&gt;@notify_level_email=3, &lt;br /&gt;@notify_level_netsend=0, &lt;br /&gt;@notify_level_page=0, &lt;br /&gt;@delete_level=0, &lt;br /&gt;@description=N'Job for responding to Create_database events', &lt;br /&gt;@category_name=N'[Uncategorized (Local)]', &lt;br /&gt;--@owner_login_name=@ServiceAccount, &lt;br /&gt;--@notify_email_operator_name=@SQLOperator, &lt;br /&gt;@job_id = @jobId OUTPUT&lt;br /&gt;&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;&lt;br /&gt;/*Step 3: Insert graph into LogEvents*/&lt;br /&gt;&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Insert data into LogEvents', &lt;br /&gt;@step_id=1, &lt;br /&gt;@cmdexec_success_code=0, &lt;br /&gt;@on_success_action=1, &lt;br /&gt;@on_success_step_id=0, &lt;br /&gt;@on_fail_action=2, &lt;br /&gt;@on_fail_step_id=0, &lt;br /&gt;@retry_attempts=0, &lt;br /&gt;@retry_interval=0, &lt;br /&gt;@os_run_priority=0, @subsystem=N'TSQL', &lt;br /&gt;@command=N'&lt;br /&gt;&lt;br /&gt;INSERT INTO Create_database (&lt;br /&gt;PostTime, &lt;br /&gt;Instance,&lt;br /&gt;DatabaseName,&lt;br /&gt;Computername,&lt;br /&gt;LoginName,&lt;br /&gt;TSQLCommand&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;VALUES (&lt;br /&gt;GETDATE(), &lt;br /&gt;N''$(ESCAPE_NONE(WMI(SQLInstance)))'',&lt;br /&gt;N''$(ESCAPE_NONE(WMI(DatabaseName)))'',&lt;br /&gt;N''$(ESCAPE_NONE(WMI(ComputerName)))'',&lt;br /&gt;N''$(ESCAPE_NONE(WMI(Loginname)))'',&lt;br /&gt;N''$(ESCAPE_NONE(WMI(TSQLCommand)))''&lt;br /&gt;)', &lt;br /&gt;@database_name=N'master', &lt;br /&gt;@flags=0&lt;br /&gt;&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;COMMIT TRANSACTION&lt;br /&gt;&lt;br /&gt;GOTO EndSave&lt;br /&gt;&lt;br /&gt;QuitWithRollback:&lt;br /&gt;IF (@@TRANCOUNT &gt; 0) ROLLBACK TRANSACTION&lt;br /&gt;EndSave:&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;/*Creating the alert and associating it with the Job to be fired */&lt;br /&gt;&lt;br /&gt;USE [msdb]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = N'Respond to Create_database')&lt;br /&gt;EXEC msdb.dbo.sp_delete_alert @name=N'Respond to Create_database'&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;DECLARE @server_namespace varchar(255)&lt;br /&gt;IF ISNULL(CHARINDEX('\', @@SERVERNAME), 0) &gt; 0&lt;br /&gt;SET @server_namespace = N'\\.\root\Microsoft\SqlServer\ServerEvents\' + SUBSTRING(@@SERVERNAME, ISNULL(CHARINDEX('\', @@SERVERNAME), 0) + 1, LEN(@@SERVERNAME) - ISNULL(CHARINDEX('/', @@SERVERNAME), 0))&lt;br /&gt;ELSE&lt;br /&gt;SET @server_namespace = N'\\.\root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER'&lt;br /&gt;&lt;br /&gt;EXEC msdb.dbo.sp_add_alert @name=N'Respond to Create_database',&lt;br /&gt;@enabled=1, &lt;br /&gt;@notification_message=N'Your Message', &lt;br /&gt;@wmi_namespace=@server_namespace, &lt;br /&gt;@wmi_query=N'SELECT * FROM Create_database', &lt;br /&gt;@job_name='Capture Create_Database Event' ;&lt;br /&gt;&lt;br /&gt;EXEC msdb.dbo.sp_add_notification @alert_name=N'Respond to Create_database', @operator_name=N'Test', @notification_method = 1&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;--select * from master..Create_database&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How it works :&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;As soon as the database is created WMI class create_database will generate an event and trigger the alert through SQL Server agent .The alert will in turn execute the job that will insert the event information to the table we have created .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Part 2:&lt;/strong&gt;&lt;br /&gt;This part will send a mail to the desired user that an alert has been fired .&lt;br /&gt;This can be achieved by :&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;1) Using Database mail (including creating an operator)and choosing the option in the job itself for notifying the operator .&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;2) Using custom based CDO message via VBscript and execute it using XP_cmdshell as a job step.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Mail.vbs :&lt;/em&gt;&lt;br /&gt;Set objEmail = CreateObject("CDO.Message")&lt;br /&gt;objEmail.From = "abhay.chaudhary@in.ibm.com"&lt;br /&gt;objEmail.To = "abhay.chaudhary@in.ibm.com"&lt;br /&gt;objEmail.Subject = "Mail for you using CDO :-) "&lt;br /&gt;objEmail.Textbody = "Hi sir this mail has been sent without using SQL Server and from WMI script."&lt;br /&gt;objEmail.AddAttachment "C:\Script repository\Alerts\final Alerts\readme.txt"&lt;br /&gt;objEmail.Send&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;3) Using the Stored procedure below :&lt;/strong&gt;&lt;br /&gt;/* Step 5: Create a stored proc for sending the [Create_database] information as .CSV file */&lt;br /&gt; &lt;br /&gt;Create proc [dbo].[Create_database_rpt] &lt;br /&gt;as&lt;br /&gt;DECLARE @SQL varchar(2000)&lt;br /&gt;DECLARE @date varchar (2000)&lt;br /&gt;DECLARE @File varchar(1000)&lt;br /&gt;select @date= convert(date,GETDATE())&lt;br /&gt;SET @SQL = 'select * from [Create_database] where flag = 0'&lt;br /&gt;SET @File = 'Deadlock report'+@date+'.csv'&lt;br /&gt; &lt;br /&gt;EXECUTE msdb.dbo.sp_send_dbmail&lt;br /&gt;@profile_name = 'test',&lt;br /&gt;@recipients = 'your email.com',&lt;br /&gt;@subject = '[Create_database] report',&lt;br /&gt;@body = '***URGENT***Attached please find the Create Database report',&lt;br /&gt;@query =@SQL ,&lt;br /&gt;@attach_query_result_as_file = 1,&lt;br /&gt;@query_attachment_filename = @file,&lt;br /&gt;@query_result_header = 1,&lt;br /&gt;@query_result_separator = ' ',&lt;br /&gt;@query_result_no_padding = 1,&lt;br /&gt;@query_result_width = 32767 &lt;br /&gt;&lt;br /&gt;/* Step 6: Changing the flag to 1 so that next time this information is not sent*/ &lt;br /&gt;update dbo.[Create_database] set flag = 1 where flag = 0&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;Like this Try your hands on different alerts by going through the classes copied above .You can also go through the classes at MSDN :&lt;em&gt;http://msdn.microsoft.com/en-us/library/ms186449(SQL.90).aspx&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Hope this helps .I am also learning ropes on WMI and will post some good stuff as soon as I am ready .Keep reading as there is much more to come .&lt;br /&gt;&lt;br /&gt;Happy learning .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-7570662633020365123?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/7570662633020365123/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=7570662633020365123&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/7570662633020365123'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/7570662633020365123'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/11/creating-sql-server-alerts-using-wmi.html' title='Creating SQL Server Alerts using WMI classes- Part 1'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_SqLnRbOtgHE/SwZTlHXtO2I/AAAAAAAAAp8/TaoUIUUah3w/s72-c/alert_list.gif' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-4051982568382394231</id><published>2009-11-20T13:19:00.000+05:30</published><updated>2009-11-20T13:40:54.259+05:30</updated><title type='text'>Msg 3132, Level 16, State 1, Line 1</title><content type='html'>Today as soon as i reached office in the morning , an issue came up which was related to restoring of SQL Server database .The issue was that we were not able to restore one of the user database backups taken on some remote server .&lt;br /&gt;&lt;br /&gt;The error we were getting was :&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Msg 3132, Level 16, State 1, Line 1&lt;br /&gt;The media set has 2 media families but only 1 are provided. All members must be provided.&lt;br /&gt;Msg 3013, Level 16, State 1, Line 1&lt;br /&gt;RESTORE DATABASE is terminating abnormally.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;There was some .bak say test.bak file, which we were trying to restore and getting the error above.&lt;br /&gt;&lt;br /&gt;This error says that there are 2 media families and only 1 has been provided .&lt;br /&gt;Media families here means a Disk or a tape .If we take it as disk , then it means that  "The backup was taken on two backup devices or say backup files (in case you have not created disk devices)" . This kind of backup is called as a srtipped backup where both the backup devices have some part of backup but not complete.&lt;br /&gt;&lt;br /&gt;But the guy who took the backp says that he did nothing special that made the stripped backup i.e. he did not take the stripped backup at all .&lt;br /&gt;&lt;br /&gt;Then how come the stripped backup took place on it own ....this was pretty strange.&lt;br /&gt;&lt;br /&gt;I checked this issue through Bing and google and most of the people were saying the same that they never did intend to take the stripped backup .&lt;br /&gt;&lt;br /&gt;Now, i had to prove the client that we are missing one backup device here or we are missing one .bak file , I did a small repro :&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;USE master&lt;br /&gt;GO&lt;br /&gt;EXEC master.dbo.sp_addumpdevice  &lt;br /&gt; @devtype = N'disk', &lt;br /&gt; @logicalname = N'rest_issue', &lt;br /&gt; @physicalname = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\rest_issue.bak'&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;EXEC master.dbo.sp_addumpdevice  &lt;br /&gt; @devtype = N'disk', &lt;br /&gt; @logicalname = N'rest_issue_1', &lt;br /&gt; @physicalname = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\rest_issue_1.bak'&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;backup database testdba to rest_issue,rest_issue1&lt;br /&gt;restore database testdba from rest_issue &lt;-- used only one mediaset &lt;br /&gt;&lt;br /&gt;Msg 3132, Level 16, State 1, Line 1&lt;br /&gt;The media set has 2 media families but only 1 are provided. All members must be provided.&lt;br /&gt;Msg 3013, Level 16, State 1, Line 1&lt;br /&gt;RESTORE DATABASE is terminating abnormally.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;restore database testdba from rest_issue,rest_issue1 &lt;-- used both mediaset &lt;br /&gt;&lt;br /&gt;Restore was successful..&lt;br /&gt;So the error was genuine and working fine .&lt;br /&gt;&lt;br /&gt;Further ,If you think that you will restore only 1 file i.e. data file and leave the log file using option &lt;strong&gt;partial&lt;/strong&gt; , even that will not work as the backup for data file is also stripped.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Restore filelistonly will tell you the files in the backup set &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Restore headeronly will give us the MediasetID number and other information &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Restore labelonly will give us the BindingID number and other information&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Restore verifyonly will fail with the same error if you use it on one file as it needs both the files &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Solution :&lt;/strong&gt;There is no solution to this issue you need to find out another device else it will not work (use restore headeronly and labelonly ,backupmediafamily, backupset for assistance) and use both the files to restore .Once you have it , you can issue this &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;command :&lt;/strong&gt;&lt;br /&gt;Restore database ibmdba from anoop_issue,anoop_issue1 with replace &lt;br /&gt;OR Restore database ibmdba from disk =&lt;path&gt; , disk =&lt;path&gt; with replace &lt;br /&gt;&lt;br /&gt;Why Hhis happens :)&lt;br /&gt;&lt;br /&gt;This will happen if :&lt;br /&gt;&lt;br /&gt;1) You have created two(or more) backup devices and taken backup on 2 &lt;br /&gt;(or more) devices or you can say stripped backup and while restoring yo uare using only one .&lt;br /&gt;&lt;br /&gt;2) You are using GUI to take the backup without seeing that the backup is going to more than 1 device or files .If you select both the devices/files it will take stripped backups .If you insert 2 devices / files but select NONE of them then also it will happen (That should not happen and should give us the error "Please select a device") .And thats where the bug is .&lt;br /&gt;&lt;br /&gt;So the BUG is :&lt;br /&gt;-------------------------&lt;br /&gt;&lt;br /&gt;If a user do not select a device in the backup set when more than one devices are existing , by default SQL Server selects all the devices and not giving the error "please select the device"....&lt;br /&gt;&lt;br /&gt;If this default behaviour is by design then its not the correct design and should be changed .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Repro of this issue through GUI :&lt;/strong&gt;&lt;br /&gt;-&gt; right click adventure works database &gt; Tasks &gt; backup&lt;br /&gt;-&gt; Under Destination remove anything if its mentioned by default.&lt;br /&gt;-&gt; Click on Add &gt; a new box will pop up &gt; select backup device you have created&lt;br /&gt;-&gt; you will get the device name &gt; click on OK.&lt;br /&gt;-&gt; Again click on Add &gt;a new box will pop up &gt; select another backup device .&lt;br /&gt;-&gt; You will see that both the backup devices are unselected now (",).&lt;br /&gt;-&gt; If now you click ok it will take the backup .Ideally it should give the error    that "please select the device".&lt;br /&gt;&lt;br /&gt;I have filed a bug with MS through connect...&lt;br /&gt;&lt;br /&gt;Happy learning&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-4051982568382394231?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/4051982568382394231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=4051982568382394231&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4051982568382394231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4051982568382394231'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/11/msg-3132-level-16-state-1-line-1.html' title='Msg 3132, Level 16, State 1, Line 1'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-3618756558881490332</id><published>2009-10-07T16:53:00.000+05:30</published><updated>2009-10-07T17:02:15.875+05:30</updated><title type='text'>Error 14262:The specified server xxxxx019 does not exist</title><content type='html'>I got this error when I was trying to setup logshipping .I was strange &lt;br /&gt;I checked the select * from sys.servers output and i was getting the entry of the server there .......whats wrong then .&lt;br /&gt;&lt;br /&gt;I tried to ping that server using the server name .But it was timed out .I then tried to use the IP of that server while pinging with -a option and guess what ...&lt;br /&gt;I found the different servername there ..... :D &lt;br /&gt;&lt;br /&gt;this was the issue .Some admin changed the Server name which SQL Server did not pick u automatically .&lt;br /&gt;&lt;br /&gt;i used sp_addserver and sp_drop server to add the right server and everything was on track ...&lt;br /&gt;&lt;br /&gt;Regards&lt;br /&gt;Abhay&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-3618756558881490332?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/3618756558881490332/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=3618756558881490332&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/3618756558881490332'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/3618756558881490332'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/10/error-14262the-specified-server.html' title='Error 14262:The specified server xxxxx019 does not exist'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-3320958868188890636</id><published>2009-10-07T16:31:00.000+05:30</published><updated>2009-10-07T16:40:25.989+05:30</updated><title type='text'>MSDTC was unable to read its configuration information. (Exception from HRESULT: 0x8004D027)</title><content type='html'>I was installing SP2 on SQL Server 2005 x64 RTM ...Everything went fine but it got stuck at Notification Services and Client Tools .&lt;br /&gt;&lt;br /&gt;The error SNIP is :&lt;br /&gt;&lt;strong&gt;Error            : Failed to install and configure assemblies D:\Program Files\Microsoft SQL Server (x86)\90\NotificationServices\9.0.242\Bin\microsoft.sqlserver.notificationservices.dll in the COM+ catalog. Error: -2146233087&lt;br /&gt;&lt;br /&gt;Error message    : Unknown error 0x80131501&lt;br /&gt;Error description: MSDTC was unable to read its configuration information. (Exception from HRESULT: 0x8004D027)&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;So , there was some issue with MSDTC ....and I am no tthe MSDTC guy ......&lt;br /&gt;If you do not install Notification services,reporting services and client tools , MSDTC errror will not pop up ....&lt;br /&gt;&lt;br /&gt;Moreover there is an option to retry on the error window .&lt;br /&gt;&lt;br /&gt;-&gt; I checked and found that MSDTC service was running fine .&lt;br /&gt;-&gt; I also checked if my account has all the priveleges at the domain level bla bla bla ..&lt;br /&gt;&lt;br /&gt;-&gt; Finally , i uninstalled and reinstalled MSDTC [DOS &gt;&gt; msdtc -uninstall and then MSDTC -install &gt;&gt; start MSDTC if its not].&lt;br /&gt;&lt;br /&gt;once done , I clicked on retry and it worked just fine ...&lt;br /&gt;We had the similar issue on another server and we resolved it in similar way ...&lt;br /&gt;&lt;br /&gt;Hope it helps you too ..&lt;br /&gt;&lt;br /&gt;Regards&lt;br /&gt;Abhay&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-3320958868188890636?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/3320958868188890636/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=3320958868188890636&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/3320958868188890636'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/3320958868188890636'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/10/msdtc-was-unable-to-read-its.html' title='MSDTC was unable to read its configuration information. (Exception from HRESULT: 0x8004D027)'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-5659056974816753104</id><published>2009-10-06T16:50:00.000+05:30</published><updated>2009-10-15T15:54:48.060+05:30</updated><title type='text'>Getting SQL Server inventory for all the instances of SQL Server 2005 and above</title><content type='html'>This one really ate my head but finally came up with something .We (thanks to Sethi who an equal partner in taking the pain) have completely automated it but due to a bug in Excel or Microsoft SQL Server I could not export all the data to one Excel sheet .Result is that you need to copy the output and paste it to the excel sheet .mail me any changeso you are looking for or if you have issue swith the output (hint : check the query tab in SSMS and change ot appropriately :D).&lt;br /&gt;&lt;br /&gt;You need to have the CMS servers (SQL Server 2008 Express) and all the instances registered .      &lt;br /&gt;      &lt;br /&gt;      &lt;br /&gt;-&gt; This script will run on 2000,2005 and 2008 and will be using SQL Server express CMS as well.&lt;br /&gt;-&gt; We can live without SQL Server 2008 CMS but then the code will be 364 lines x numbers of server .&lt;br /&gt;-&gt; This Script will first check if SQL Server is 2000 or above and will only execute the code based on that check .&lt;br /&gt;-&gt; We can also print the output in to excel sheet using openrowset and opendatasource but its throwing a bug when multiple instances try to update the excel sheet using distributed transactions .&lt;br /&gt;-&gt; So we have decided to get the output all together in Query Analyzer and paste it to the excel Sheet.&lt;br /&gt;-&gt; Let us know if you need that code as well and we will add it as comment.&lt;br /&gt;-&gt; The CMS should have connectivity to all the servers (It has to be the Central Server)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Part 1:&lt;br /&gt;-------&lt;br /&gt;&lt;br /&gt;-- Install SQL Server 2008 Express Edition and open the management studio (Start -&gt; Run -&gt; SSMS)&lt;br /&gt;-- Go to View --&gt; Registered servers &lt;br /&gt;-- Right click on the Central Management Servers and select Register Central Management Servers&lt;br /&gt;-- Select the Express instance and register it .&lt;br /&gt;-- open the test.regsrvr file in SSMS .&lt;br /&gt;-- You will see few values inside various TAGS starting with &lt;&gt; and ending with &lt;/&gt;.&lt;br /&gt;-- If you see line 48 you will see the server group name .In our case its "test":&lt;br /&gt; &lt;sml:Uri&gt;/RegisteredServersStore/ServerGroup/DatabaseEngineServerGroup/ServerGroup/Test&lt;/sml:Uri&gt;&lt;br /&gt;-- Do a CTRL+ F and also choose replace .You can give any name instead of test and replace it or keep the same name .&lt;br /&gt;-- Now search for the tag &lt;RegisteredServers:RegisteredServers&gt; here you will see three instances registered .Its Line 72.&lt;br /&gt;-- You can remove or add the instance names here .&lt;br /&gt;-- All you need to do is copy the below code -&gt; change the instance name -&gt; and paste it back in the code just before the &lt;/sfc:Collection&gt; TAG:&lt;br /&gt;              &lt;sfc:Reference sml:ref="true"&gt;&lt;br /&gt;                &lt;sml:Uri&gt;/RegisteredServersStore/ServerGroup/DatabaseEngineServerGroup/ServerGroup/Test/RegisteredServer/abchaudh\ASLAN&lt;/sml:Uri&gt;&lt;br /&gt;              &lt;/sfc:Reference&gt;&lt;br /&gt;-- Repeat the activity for as many instances as you want .&lt;br /&gt;-- Now go to line 96 and you will see the individual instance information .The code will be like this :&lt;br /&gt;&lt;br /&gt;   &lt;document&gt;&lt;br /&gt;      &lt;docinfo&gt;&lt;br /&gt;        &lt;aliases&gt;&lt;br /&gt;          &lt;alias&gt;/RegisteredServersStore/ServerGroup/DatabaseEngineServerGroup/ServerGroup/Test/RegisteredServer/abchaudh\ASLAN&lt;/alias&gt;&lt;br /&gt;        &lt;/aliases&gt;&lt;br /&gt;        &lt;sfc:version DomainVersion="1" /&gt;&lt;br /&gt;      &lt;/docinfo&gt;&lt;br /&gt;      &lt;data&gt;&lt;br /&gt;        &lt;RegisteredServers:RegisteredServer xmlns:RegisteredServers="http://schemas.microsoft.com/sqlserver/RegisteredServers/2007/08" xmlns:sfc="http://schemas.microsoft.com/sqlserver/sfc/serialization/2007/08" xmlns:sml="http://schemas.serviceml.org/sml/2007/02" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;&lt;br /&gt;          &lt;RegisteredServers:Parent&gt;&lt;br /&gt;            &lt;sfc:Reference sml:ref="true"&gt;&lt;br /&gt;              &lt;sml:Uri&gt;/RegisteredServersStore/ServerGroup/DatabaseEngineServerGroup/ServerGroup/Test&lt;/sml:Uri&gt;&lt;br /&gt;            &lt;/sfc:Reference&gt;&lt;br /&gt;          &lt;/RegisteredServers:Parent&gt;&lt;br /&gt;          &lt;RegisteredServers:Name type="string"&gt;abchaudh\ASLAN&lt;/RegisteredServers:Name&gt;&lt;br /&gt;          &lt;RegisteredServers:Description type="string" /&gt;&lt;br /&gt;          &lt;RegisteredServers:ServerName type="string"&gt;abchaudh\ASLAN&lt;/RegisteredServers:ServerName&gt;&lt;br /&gt;          &lt;RegisteredServers:ServerType type="ServerType"&gt;DatabaseEngine&lt;/RegisteredServers:ServerType&gt;&lt;br /&gt;          &lt;RegisteredServers:ConnectionStringWithEncryptedPassword type="string"&gt;server=abchaudh\ASLAN;integrated security=true&lt;/RegisteredServers:ConnectionStringWithEncryptedPassword&gt;&lt;br /&gt;          &lt;RegisteredServers:CredentialPersistenceType type="CredentialPersistenceType"&gt;None&lt;/RegisteredServers:CredentialPersistenceType&gt;&lt;br /&gt;        &lt;/RegisteredServers:RegisteredServer&gt;&lt;br /&gt;      &lt;/data&gt;&lt;br /&gt;    &lt;/document&gt;&lt;br /&gt;&lt;br /&gt;-- Just change the instance name with your instance and paste it just before line 167 i.e. before the tag &lt;/instances&gt;&lt;br /&gt;-- Repeat this step i.e. add as many instances as needed be .&lt;br /&gt;-- Thats it .Save this file and close it .&lt;br /&gt;-- Go back to the CMS tab --&gt; right click the CMS instance under Central management servers --&gt; tasks --&gt; Import&lt;br /&gt;-- Import this test.regsrvr file .&lt;br /&gt;-- You will see the instances registered under the 2008 Express instance.&lt;br /&gt;-- Click on the Express instance and open a new Query .&lt;br /&gt;-- Paste the code below in Part 2 and execute it .&lt;br /&gt;&lt;br /&gt;NOTE : Make 2 different groups . One for SQL Server 2000 instances and another for 2005/2008 instances .Use the same test.regsrvr file .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Part 2:&lt;br /&gt;--------&lt;br /&gt;--Step 1: Setting NULLs and quoted identifiers to ON and checking the version of SQL Server &lt;br /&gt;  GO&lt;br /&gt;  SET ANSI_NULLS ON&lt;br /&gt;  GO&lt;br /&gt;  SET QUOTED_IDENTIFIER ON&lt;br /&gt;  GO&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'prodver') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)                        &lt;br /&gt;drop table prodver&lt;br /&gt;create table prodver ([index] int, Name nvarchar(50),Internal_value int, Charcater_Value nvarchar(50))&lt;br /&gt;insert into prodver exec xp_msver 'ProductVersion'&lt;br /&gt; if (select substring(Charcater_Value,1,1)from prodver)!=8&lt;br /&gt; begin&lt;br /&gt; &lt;br /&gt;                   &lt;br /&gt;-- Step 2: This code will be used if the instance is Not SQL Server 2000 &lt;br /&gt;&lt;br /&gt;  Declare @image_path nvarchar(100)                        &lt;br /&gt;  Declare @startup_type int                        &lt;br /&gt;  Declare @startuptype nvarchar(100)                        &lt;br /&gt;  Declare @start_username nvarchar(100)                        &lt;br /&gt;  Declare @instance_name nvarchar(100)                        &lt;br /&gt;  Declare @system_instance_name nvarchar(100)                        &lt;br /&gt;  Declare @log_directory nvarchar(100)                        &lt;br /&gt;  Declare @key nvarchar(1000)                        &lt;br /&gt;  Declare @registry_key nvarchar(100)                        &lt;br /&gt;  Declare @registry_key1 nvarchar(300)                        &lt;br /&gt;  Declare @registry_key2 nvarchar(300)                        &lt;br /&gt;  Declare @IpAddress nvarchar(20)                        &lt;br /&gt;  Declare @domain nvarchar(50)                        &lt;br /&gt;  Declare @cluster int                        &lt;br /&gt;  Declare @instance_name1 nvarchar(100)                        &lt;br /&gt;-- Step 3: Reading registry keys for IP,Binaries,Startup type ,startup username, errorlogs location and domain.&lt;br /&gt;  SET @instance_name = coalesce(convert(nvarchar(100), serverproperty('InstanceName')),'MSSQLSERVER');                        &lt;br /&gt;  If @instance_name!='MSSQLSERVER'                        &lt;br /&gt;  Set @instance_name=@instance_name                       &lt;br /&gt;  &lt;br /&gt;      Set @instance_name1= coalesce(convert(nvarchar(100), serverproperty('InstanceName')),'MSSQLSERVER');                        &lt;br /&gt;  If @instance_name1!='MSSQLSERVER'                        &lt;br /&gt;  Set @instance_name1='MSSQL$'+@instance_name1                        &lt;br /&gt;  EXEC master.dbo.xp_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\Instance Names\SQL', @instance_name, @system_instance_name output;                        &lt;br /&gt;                        &lt;br /&gt;  Set @key=N'SYSTEM\CurrentControlSet\Services\' +@instance_name1;                        &lt;br /&gt;  SET @registry_key = N'Software\Microsoft\Microsoft SQL Server\' + @system_instance_name + '\MSSQLServer\Parameters';                        &lt;br /&gt;  If @registry_key is NULL                        &lt;br /&gt;  set @instance_name=coalesce(convert(nvarchar(100), serverproperty('InstanceName')),'MSSQLSERVER');                        &lt;br /&gt;  EXEC master.dbo.xp_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\Instance Names\SQL', @instance_name, @system_instance_name output;                        &lt;br /&gt;&lt;br /&gt;  SET @registry_key = N'Software\Microsoft\Microsoft SQL Server\' + @system_instance_name + '\MSSQLServer\Parameters';                        &lt;br /&gt;  SET @registry_key1 = N'Software\Microsoft\Microsoft SQL Server\' + @system_instance_name + '\MSSQLServer\supersocketnetlib\TCP\IP1';                        &lt;br /&gt;  SET @registry_key2 = N'SYSTEM\ControlSet001\Services\Tcpip\Parameters\';                        &lt;br /&gt;                        &lt;br /&gt;  EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@key,@value_name='ImagePath',@value=@image_path OUTPUT                        &lt;br /&gt;  EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@key,@value_name='Start',@value=@startup_type OUTPUT                        &lt;br /&gt;  EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@key,@value_name='ObjectName',@value=@start_username OUTPUT                        &lt;br /&gt;  EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@registry_key,@value_name='SQLArg1',@value=@log_directory OUTPUT                        &lt;br /&gt;  EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@registry_key1,@value_name='IpAddress',@value=@IpAddress OUTPUT                        &lt;br /&gt;  EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@registry_key2,@value_name='Domain',@value=@domain OUTPUT                        &lt;br /&gt;                        &lt;br /&gt;  Set @startuptype=  (select 'Start Up Mode' =                        &lt;br /&gt;     CASE                        &lt;br /&gt;     WHEN @startup_type=2 then 'AUTOMATIC'                        &lt;br /&gt;     WHEN @startup_type=3 then 'MANUAL'                        &lt;br /&gt;     WHEN @startup_type=4 then 'Disabled'                        &lt;br /&gt;     END)                        &lt;br /&gt;                        &lt;br /&gt;--Step 4: Getting the cluster node names if the server is on cluster .else this value will be NULL.&lt;br /&gt;&lt;br /&gt;  declare @Out nvarchar(400)                        &lt;br /&gt;  SELECT @Out = COALESCE(@Out+'' ,'') + Nodename                        &lt;br /&gt;  from sys.dm_os_cluster_nodes                        &lt;br /&gt;                        &lt;br /&gt;-- Step 5: printing Server details &lt;br /&gt;                        &lt;br /&gt;   SELECT                       &lt;br /&gt;   @domain as 'Domain',                      &lt;br /&gt;   serverproperty('ComputerNamePhysicalNetBIOS') as 'MachineName',                      &lt;br /&gt;   CPU_COUNT as 'CPUCount',&lt;br /&gt;   (physical_memory_in_bytes/1048576) as 'PhysicalMemoryMB',                      &lt;br /&gt;   @Ipaddress as 'IP_Address',                      &lt;br /&gt;   @instance_name1 as 'InstanceName',&lt;br /&gt;   @image_path as 'BinariesPath',                      &lt;br /&gt;   @log_directory as 'ErrorLogsLocation',                      &lt;br /&gt;   @start_username as 'StartupUser',                      &lt;br /&gt;   @Startuptype as 'StartupType',                      &lt;br /&gt;   serverproperty('Productlevel') as 'ServicePack',                      &lt;br /&gt;   serverproperty('edition') as 'Edition',                      &lt;br /&gt;   serverproperty('productversion') as 'Version',                      &lt;br /&gt;   serverproperty('collation') as 'Collation',                      &lt;br /&gt;   serverproperty('Isclustered') as 'ISClustered',                      &lt;br /&gt;   @out as 'ClusterNodes',                      &lt;br /&gt;   serverproperty('IsFullTextInstalled') as 'ISFullText'                       &lt;br /&gt;   From sys.dm_os_sys_info                         &lt;br /&gt;                      &lt;br /&gt;&lt;br /&gt;-- Step 6: Printing database details &lt;br /&gt;    &lt;br /&gt;   SELECT                       &lt;br /&gt;   serverproperty ('ComputerNamePhysicalNetBIOS') as 'Machine'                      &lt;br /&gt;   ,@instance_name1 as InstanceName,                      &lt;br /&gt;   (SELECT 'file_type' =                      &lt;br /&gt;     CASE                      &lt;br /&gt;      WHEN s.groupid &lt;&gt; 0 THEN 'data'                      &lt;br /&gt;      WHEN s.groupid = 0 THEN 'log'                      &lt;br /&gt;     END) AS 'fileType'                      &lt;br /&gt;    , d.dbid as 'DBID'                      &lt;br /&gt;    , d.name AS 'DBName'                      &lt;br /&gt;    , s.name AS 'LogicalFileName'                      &lt;br /&gt;    , s.filename AS 'PhysicalFileName'                      &lt;br /&gt;     , (s.size * 8 / 1024) AS 'FileSizeMB' -- file size in MB                      &lt;br /&gt;     , d.cmptlevel as 'CompatibilityLevel'                      &lt;br /&gt;     , DATABASEPROPERTYEX (d.name,'Recovery') as 'RecoveryModel'                      &lt;br /&gt;     , DATABASEPROPERTYEX (d.name,'Status') as 'DatabaseStatus' ,                     &lt;br /&gt;     --, d.is_published as 'Publisher'                      &lt;br /&gt;     --, d.is_subscribed as 'Subscriber'                      &lt;br /&gt;     --, d.is_distributor as 'Distributor' &lt;br /&gt;     (SELECT 'is_replication' =                      &lt;br /&gt;    CASE                      &lt;br /&gt;   WHEN d.category = 1 THEN 'Published'                      &lt;br /&gt;   WHEN d.category = 2 THEN 'subscribed'                      &lt;br /&gt;   WHEN d.category = 4 THEN 'Merge published'&lt;br /&gt;   WHEN d.category = 8 THEN 'merge subscribed'&lt;br /&gt;   Else 'NO replication'&lt;br /&gt;   END) AS 'Is_replication'                      &lt;br /&gt;     , m.mirroring_state as 'MirroringState'                      &lt;br /&gt;   --INTO master.[dbo].[databasedetails]                      &lt;br /&gt;   FROM                      &lt;br /&gt;   sys.sysdatabases d INNER JOIN sys.sysaltfiles s                      &lt;br /&gt;   ON                      &lt;br /&gt;   d.dbid=s.dbid                      &lt;br /&gt;   INNER JOIN sys.database_mirroring m                      &lt;br /&gt;   ON                      &lt;br /&gt;   d.dbid=m.database_id                      &lt;br /&gt;   ORDER BY                      &lt;br /&gt;   d.name                      &lt;br /&gt;          &lt;br /&gt;          &lt;br /&gt;          &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--Step 7 :printing Backup details                       &lt;br /&gt;&lt;br /&gt;   Select distinct                             &lt;br /&gt;   b.machine_name as 'ServerName',                        &lt;br /&gt;   b.server_name as 'InstanceName',                        &lt;br /&gt;   b.database_name as 'DatabaseName',                            &lt;br /&gt;   d.database_id 'DBID',                            &lt;br /&gt;   CASE b.[type]                                  &lt;br /&gt;   WHEN 'D' THEN 'Full'                                  &lt;br /&gt;   WHEN 'I' THEN 'Differential'                                  &lt;br /&gt;   WHEN 'L' THEN 'Transaction Log'                                  &lt;br /&gt;   END as 'BackupType'                                 &lt;br /&gt;   --INTO [dbo].[backupdetails]                        &lt;br /&gt;   from sys.databases d inner join msdb.dbo.backupset b                            &lt;br /&gt;   On b.database_name =d.name                        &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;End&lt;br /&gt;else&lt;br /&gt;&lt;br /&gt; begin&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--Step 8: If the instance is 2000 this code will be used.&lt;br /&gt;&lt;br /&gt; declare @registry_key4 nvarchar(100)                        &lt;br /&gt; declare @Host_Name varchar(100)&lt;br /&gt; declare @CPU varchar(3)&lt;br /&gt; declare @nodes nvarchar(400)&lt;br /&gt; set @nodes =null /* We are not able to trap the node names for SQL Server 2000 so far*/&lt;br /&gt; declare @mirroring varchar(15)&lt;br /&gt; set @mirroring ='NOT APPLICABLE' /*Mirroring does not exist in SQL Server 2000*/&lt;br /&gt; Declare @reg_node1 varchar(100)&lt;br /&gt; Declare @reg_node2 varchar(100)&lt;br /&gt; Declare @reg_node3 varchar(100)&lt;br /&gt; Declare @reg_node4 varchar(100)&lt;br /&gt;   &lt;br /&gt; SET @reg_node1 = N'Cluster\Nodes\1'&lt;br /&gt; SET @reg_node2 = N'Cluster\Nodes\2'&lt;br /&gt; SET @reg_node3 = N'Cluster\Nodes\3'&lt;br /&gt; SET @reg_node4 = N'Cluster\Nodes\4'&lt;br /&gt;   &lt;br /&gt; Declare @image_path1 varchar(100)&lt;br /&gt; Declare @image_path2 varchar(100)&lt;br /&gt; Declare @image_path3 varchar(100)&lt;br /&gt; Declare @image_path4 varchar(100)&lt;br /&gt; &lt;br /&gt; set @image_path1=null&lt;br /&gt; set @image_path2=null&lt;br /&gt; set @image_path3=null&lt;br /&gt; set @image_path4=null&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; Exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@reg_node1, @value_name='NodeName',@value=@image_path1 OUTPUT&lt;br /&gt; Exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@reg_node2, @value_name='NodeName',@value=@image_path2 OUTPUT&lt;br /&gt; Exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@reg_node3, @value_name='NodeName',@value=@image_path3 OUTPUT&lt;br /&gt; Exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@reg_node4, @value_name='NodeName',@value=@image_path4 OUTPUT&lt;br /&gt; &lt;br /&gt;    IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'nodes') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)                        &lt;br /&gt; drop table nodes&lt;br /&gt; Create table nodes (name varchar (20))&lt;br /&gt;    insert into nodes values (@image_path1)&lt;br /&gt;    insert into nodes values (@image_path2)&lt;br /&gt;    insert into nodes values (@image_path3)&lt;br /&gt;    insert into nodes values (@image_path4)&lt;br /&gt;    --declare @Out nvarchar(400)                        &lt;br /&gt;    --declare @value nvarchar (20)&lt;br /&gt;    SELECT @Out = COALESCE(@Out+'/' ,'') + name from nodes where name is not null&lt;br /&gt;      &lt;br /&gt;-- Step 9: Reading registry keys for Number of CPUs,Binaries,Startup type ,startup username, errorlogs location and domain.&lt;br /&gt; &lt;br /&gt; SET @instance_name = coalesce(convert(nvarchar(100), serverproperty('InstanceName')),'MSSQLSERVER');&lt;br /&gt; IF @instance_name!='MSSQLSERVER'&lt;br /&gt;&lt;br /&gt; BEGIN&lt;br /&gt;  set @system_instance_name=@instance_name&lt;br /&gt;  set @instance_name='MSSQL$'+@instance_name&lt;br /&gt;&lt;br /&gt;  SET @key=N'SYSTEM\CurrentControlSet\Services\' +@instance_name;&lt;br /&gt;  SET @registry_key = N'Software\Microsoft\Microsoft SQL Server\' + @system_instance_name + '\MSSQLServer\Parameters';&lt;br /&gt;  SET @registry_key1 = N'Software\Microsoft\Microsoft SQL Server\' + @system_instance_name + '\Setup';&lt;br /&gt;  SET @registry_key2 = N'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\';&lt;br /&gt;  SET @registry_key4 = N'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;  EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@registry_key1,@value_name='SQLPath',@value=@image_path OUTPUT&lt;br /&gt;  EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@key,@value_name='Start',@value=@startup_type OUTPUT&lt;br /&gt;  EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@key,@value_name='ObjectName',@value=@start_username OUTPUT&lt;br /&gt;  EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@registry_key,@value_name='SQLArg1',@value=@log_directory OUTPUT&lt;br /&gt;  EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@registry_key2,@value_name='Domain',@value=@domain OUTPUT&lt;br /&gt;  EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@registry_key4,@value_name='NUMBER_OF_PROCESSORS',@value=@CPU OUTPUT                        &lt;br /&gt; &lt;br /&gt;&lt;br /&gt; END&lt;br /&gt;&lt;br /&gt; IF @instance_name='MSSQLSERVER'&lt;br /&gt;  BEGIN&lt;br /&gt;   SET @key=N'SYSTEM\CurrentControlSet\Services\' +@instance_name;&lt;br /&gt;   SET @registry_key = N'Software\Microsoft\MSSQLSERVER\MSSQLServer\Parameters';&lt;br /&gt;   SET @registry_key1 = N'Software\Microsoft\MSSQLSERVER\Setup';&lt;br /&gt;   SET @registry_key2 = N'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\';&lt;br /&gt;   SET @registry_key4 = N'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'                                                &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;   EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@registry_key1,@value_name='SQLPath',@value=@image_path OUTPUT&lt;br /&gt;   EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@key,@value_name='Start',@value=@startup_type OUTPUT&lt;br /&gt;   EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@key,@value_name='ObjectName',@value=@start_username OUTPUT&lt;br /&gt;   EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@registry_key,@value_name='SQLArg1',@value=@log_directory OUTPUT&lt;br /&gt;   --EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@registry_key1,@value_name='IpAddress',@value=@IpAddress OUTPUT&lt;br /&gt;   EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@registry_key2,@value_name='Domain',@value=@domain OUTPUT&lt;br /&gt;   EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@registry_key4,@value_name='NUMBER_OF_PROCESSORS',@value=@CPU OUTPUT                         &lt;br /&gt;&lt;br /&gt;  END&lt;br /&gt;   set @startuptype= (select 'Start Up Mode' =&lt;br /&gt;     CASE&lt;br /&gt;     WHEN @startup_type=2 then 'AUTOMATIC'&lt;br /&gt;     WHEN @startup_type=3 then 'MANUAL'&lt;br /&gt;     WHEN @startup_type=4 then 'Disabled'&lt;br /&gt;     END)&lt;br /&gt;&lt;br /&gt;--Step 10 : Using ipconfig and xp_msver to get physical memory and IP&lt;br /&gt;&lt;br /&gt;   IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'tmp') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)                      &lt;br /&gt;   DROP TABLE tmp&lt;br /&gt;   create table tmp (server varchar(100)default cast( serverproperty ('Machinename') as varchar),[index] int, name sysname,internal_value int,character_value varchar(30))&lt;br /&gt;   insert into tmp([index],name,internal_value,character_value) exec xp_msver PhysicalMemory&lt;br /&gt; &lt;br /&gt;   IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'ipadd') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)                      &lt;br /&gt;   drop table ipadd&lt;br /&gt;   create table ipadd (server varchar(100)default cast( serverproperty ('Machinename') as varchar),IP varchar (100))&lt;br /&gt;   insert into ipadd (IP)exec xp_cmdshell 'ipconfig'&lt;br /&gt;   delete from ipadd where ip not like '%IP Address.%' or IP is null&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- Step 11 : Getting the Server details &lt;br /&gt;&lt;br /&gt;   SELECT  top 1              &lt;br /&gt;   @domain as 'Domain',                      &lt;br /&gt;   serverproperty('Machinename') as 'MachineName',                      &lt;br /&gt;   @CPU as 'CPUCount',&lt;br /&gt;   cast (t.internal_value as bigint) as PhysicalMemoryMB,&lt;br /&gt;   cast(substring ( I.IP , 44,41) as nvarchar(20))as IP_Address,&lt;br /&gt;   serverproperty('Instancename') as 'InstanceName',                      &lt;br /&gt;   @image_path as 'BinariesPath',                      &lt;br /&gt;   @log_directory as 'ErrorLogsLocation',                      &lt;br /&gt;   @start_username as 'StartupUser',                      &lt;br /&gt;   @Startuptype as 'StartupType',                      &lt;br /&gt;   serverproperty('Productlevel') as 'ServicePack',                      &lt;br /&gt;   serverproperty('edition') as 'Edition',                      &lt;br /&gt;   serverproperty('productversion') as 'Version',                      &lt;br /&gt;   serverproperty('collation') as 'Collation',                      &lt;br /&gt;   serverproperty('Isclustered') as 'ISClustered',                      &lt;br /&gt;   @Out as 'ClustreNodes',&lt;br /&gt;   serverproperty('IsFullTextInstalled') as 'ISFullText'                       &lt;br /&gt;   From tmp t inner join IPAdd I&lt;br /&gt;   on t.server = I.server&lt;br /&gt;&lt;br /&gt;-- Step 12 : Getting the instance details &lt;br /&gt;&lt;br /&gt;   SELECT                       &lt;br /&gt;   serverproperty ('Machinename') as 'Machine',                      &lt;br /&gt;   serverproperty ('Instancename') as 'InstanceName',                      &lt;br /&gt;   (SELECT 'file_type' =                      &lt;br /&gt;     CASE                      &lt;br /&gt;     WHEN s.groupid &lt;&gt; 0 THEN 'data'                      &lt;br /&gt;     WHEN s.groupid = 0 THEN 'log'                      &lt;br /&gt;    END) AS 'fileType'                      &lt;br /&gt;    , d.dbid as 'DBID'                      &lt;br /&gt;    , d.name AS 'DBName'                      &lt;br /&gt;    , s.name AS 'LogicalFileName'                      &lt;br /&gt;    , s.filename AS 'PhysicalFileName'                      &lt;br /&gt;    , (s.size * 8 / 1024) AS 'FileSizeMB' -- file size in MB                      &lt;br /&gt;    ,d.cmptlevel as 'CompatibilityLevel'                      &lt;br /&gt;    , DATABASEPROPERTYEX (d.name,'Recovery') as 'RecoveryModel'                      &lt;br /&gt;    , DATABASEPROPERTYEX (d.name,'Status') as 'DatabaseStatus' ,                     &lt;br /&gt;    (SELECT 'is_replication' =                      &lt;br /&gt;    CASE                      &lt;br /&gt;    WHEN d.category = 1 THEN 'Published'                      &lt;br /&gt;    WHEN d.category = 2 THEN 'subscribed'                      &lt;br /&gt;    WHEN d.category = 4 THEN 'Merge published'&lt;br /&gt;    WHEN d.category = 8 THEN 'merge subscribed'&lt;br /&gt;    Else 'NO replication'&lt;br /&gt;     END) AS 'Is_replication',&lt;br /&gt;     @Mirroring as 'MirroringState'&lt;br /&gt;    FROM                      &lt;br /&gt;   sysdatabases d INNER JOIN sysaltfiles s                      &lt;br /&gt;   ON                      &lt;br /&gt;   d.dbid=s.dbid                      &lt;br /&gt;   ORDER BY                      &lt;br /&gt;   d.name                      &lt;br /&gt;&lt;br /&gt;-- Step 13 : Getting backup details &lt;br /&gt;&lt;br /&gt;   Select distinct                             &lt;br /&gt;   b.machine_name as 'ServerName',                        &lt;br /&gt;   b.server_name as 'InstanceName',                        &lt;br /&gt;   b.database_name as 'DatabaseName',                            &lt;br /&gt;   d.dbid 'DBID',                            &lt;br /&gt;   CASE b.[type]                                  &lt;br /&gt;   WHEN 'D' THEN 'Full'                                  &lt;br /&gt;   WHEN 'I' THEN 'Differential'                                  &lt;br /&gt;   WHEN 'L' THEN 'Transaction Log'                                  &lt;br /&gt;   END as 'BackupType'                                 &lt;br /&gt;   from sysdatabases d inner join msdb.dbo.backupset b                            &lt;br /&gt;   On b.database_name =d.name   &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- Step 14: Dropping the table we created for IP and Physical memory&lt;br /&gt;&lt;br /&gt;   Drop Table TMP&lt;br /&gt;   Drop Table IPADD&lt;br /&gt;   drop table Nodes&lt;br /&gt;  &lt;br /&gt;   end&lt;br /&gt;   go&lt;br /&gt;&lt;br /&gt;-- Step 15 : Setting Nulls and Quoted identifier back to Off &lt;br /&gt;&lt;br /&gt;   SET ANSI_NULLS OFF&lt;br /&gt;   GO&lt;br /&gt;   SET QUOTED_IDENTIFIER OFF&lt;br /&gt;   GO&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Happy learning &lt;br /&gt;Abhay&lt;br /&gt;hi_abhay78@yaoo.co.in&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-5659056974816753104?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/5659056974816753104/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=5659056974816753104&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5659056974816753104'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5659056974816753104'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/10/getting-sql-server-inventory-for-all.html' title='Getting SQL Server inventory for all the instances of SQL Server 2005 and above'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-8818202628607803475</id><published>2009-10-06T15:53:00.000+05:30</published><updated>2009-10-06T16:45:57.909+05:30</updated><title type='text'>what if yo udo not know the servers to whic hlogins belong......</title><content type='html'>Request :&lt;br /&gt;I was give a text file with a list of logins to be removed from SQL Servers as those employees were no more existing .I asked if they know the server names where the logins exist .The answer was an expected NO ....made my task more dificult .But I had to do it . I came out with a script that can be used to find the instance name where the logins exist .I have not created the script to remove those logins as its pretty simple ,but have explained in brief what can be done .So my juniors will do it :) ...&lt;br /&gt;&lt;br /&gt;Requirements :&lt;br /&gt;-&gt;  SQL Server 2008 Express edition [Central management Servers]&lt;br /&gt; We will be using it to execute queries on a group of servers and getting the consolidated result .&lt;br /&gt; &lt;br /&gt;-&gt;  .regsrvr file &lt;br /&gt; We will modify this file and add steps to add more servers instead of registering instances manually one by one .&lt;br /&gt;&lt;br /&gt;-&gt;  login_info view&lt;br /&gt; This view will keep the information about all the logins having users and schemas associated with them .If there is a login which has no user associated with it , it will not show up in this view.&lt;br /&gt;-&gt;  Instances table&lt;br /&gt; This will keep the list of all the 2005 instances in a domain .&lt;br /&gt;-&gt;  Del_logins table&lt;br /&gt; This will keep the list of all the logins that have to be searched for deletion.&lt;br /&gt;&lt;br /&gt;-&gt;  Instances.txt&lt;br /&gt; This will keep the list of the instances that will be BCPed in to instances table &lt;br /&gt;&lt;br /&gt;-&gt;  logins.txt &lt;br /&gt; This will have the list of all the logins that have to be deleted.This wil be BCPed to del_login table&lt;br /&gt;-&gt;  BCP &lt;br /&gt; We will be using BCP in ,to import values from instances.txt and logins.txt.&lt;br /&gt;&lt;br /&gt;-&gt;  :connect&lt;br /&gt; We wil be using :connect to connect to instances and and doing BCP in.&lt;br /&gt;&lt;br /&gt;-&gt; WMI &lt;br /&gt; We will use WMI to copy files to different servers .   &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Important :&lt;br /&gt;Before doing anything you need to register the servers in the CMS .&lt;br /&gt;register a couple of servers and then export the .regsrvr file somewhere.&lt;br /&gt;open that file in SQl Server QA .You can easily see the pattern of instance registration .Just copy the same as many time as there are the instances and change the instance names .Import it back and you have the instances under the server group name .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--Step 1: create login_info view on all servers using CMS.&lt;br /&gt;&lt;br /&gt;use master &lt;br /&gt;go&lt;br /&gt;create view login_info as &lt;br /&gt;select d.name as [user_name],d.type_desc as [user_type],s.name as[login_name],s.type_desc as [login_type],d.default_schema_name as [schema_name]&lt;br /&gt;from sys.database_principals d right outer join sys.server_principals s&lt;br /&gt;on d.sid =s.sid&lt;br /&gt;where s.type not in ('R')&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;--Step 2:Copy the logins.txt that the client gave to all the 2005 servers in the common drive .&lt;br /&gt;--this is a VBS file which will copy test.doc to different servers listed in computers.txt.&lt;br /&gt;&lt;br /&gt;Const ForReading = 1&lt;br /&gt;Const OverwriteExisting = TRUE&lt;br /&gt;&lt;br /&gt;Set objFSO = CreateObject("Scripting.FileSystemObject")&lt;br /&gt;Set objFile = objFSO.OpenTextFile("C:\Scripts\Computers.txt")&lt;br /&gt;&lt;br /&gt;Do Until objFile.AtEndOfStream&lt;br /&gt;    strComputer = objFile.ReadLine&lt;br /&gt;    strRemoteFile = "\\" &amp; strComputer &amp; "\C$\Scripts\LOGINS.TXT"&lt;br /&gt;    objFSO.CopyFile "C:\Scripts\Test.doc", strRemoteFile, OverwriteExisting&lt;br /&gt;Loop&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- step 3: Create a text file instances.txt with 2005 instance names on any one server with SQL Server installed .&lt;br /&gt;-- you can copy it from the inventory or try importing it with xp_cmdshell using OSQL -L and inporting it to a table &lt;br /&gt;/*&lt;br /&gt;sp_configure 'show advanced options',1&lt;br /&gt;reconfigure with override&lt;br /&gt;sp_configure 'xp_cmdshell',1&lt;br /&gt;reconfigure with override&lt;br /&gt;&lt;br /&gt;create table test (ins varchar(30))&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;insert into test exec xp_cmdshell 'osql -L'&lt;br /&gt;&lt;br /&gt;Then delete few unnecessary rows or you need to modify the output by &gt;&gt; Query &gt;&gt; Query options &lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;-- Step 4: Create the instances table in the 2005 instance server you copied the file above.&lt;br /&gt;&lt;br /&gt;use master &lt;br /&gt;go&lt;br /&gt;Create table instances (iname sysname) &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-- Step 5: BCP in the instance names from the instances.txt files to instances table .&lt;br /&gt;   xp_cmdshell 'bcp master.dbo.instances in c:\temp\instances.txt -T -c -S&lt;servername\instancename&gt;&lt;br /&gt;&lt;br /&gt;-- sTEP 6: create del_logins in all the instances using CMS&lt;br /&gt; create table master.dbo.del_logins (lname varchar(50))&lt;br /&gt;&lt;br /&gt;-- Step 7: BCP in values from the text file to the del_login table (run this command on the same server where you have instances table .Copy the output to the CMS and execute)&lt;br /&gt;&lt;br /&gt; Create table #inst (iname sysname,flag int identity (1,1) )     &lt;br /&gt; Insert into #inst select iname from instances    &lt;br /&gt; Declare @@flag1 int    &lt;br /&gt; Select @@flag1 =max (flag) from #inst    &lt;br /&gt; While @@flag1 &gt;0    &lt;br /&gt; Begin     &lt;br /&gt; Declare @string nvarchar (100)    &lt;br /&gt; DECLARE @string1 nvarchar(50)&lt;br /&gt; Declare @iname sysname     &lt;br /&gt; Select @iname =iname from #inst where flag=@@flag1    &lt;br /&gt; Set @string ='xp_cmdshell '+ '''bcp master.dbo.del_logins in c:\temp\logins.txt -T -c -S'  +@iname+''''&lt;br /&gt; set @string1= ':connect' +@iname&lt;br /&gt; print @string1&lt;br /&gt; print @string     &lt;br /&gt; print 'GO' &lt;br /&gt; Set @@flag1 =@@flag1 -1    &lt;br /&gt; End    &lt;br /&gt; Drop table #inst  &lt;br /&gt;&lt;br /&gt;-- Step 8: We need to run an intersect query in CMS&lt;br /&gt;&lt;br /&gt;select login_name from master.dbo.login_info&lt;br /&gt;intersect &lt;br /&gt;select lname from master.dbo.del_logins&lt;br /&gt;&lt;br /&gt;Result :&lt;br /&gt;----------&lt;br /&gt;&lt;br /&gt;This output will give you the logins that exist on the different servers .And then you can drop those logins one by one .&lt;br /&gt;&lt;br /&gt;Other way to drop the logins is to create a table with servername , login name and a flag default to an identity starting with 1.&lt;br /&gt;&lt;br /&gt;create the SP around the  intesect output and then insert it to this table .&lt;br /&gt;run it in the while loop and drop the logins .&lt;br /&gt;&lt;br /&gt;You can also create the scrip to change the schema to DBO before dropping the users and logins.&lt;br /&gt;&lt;br /&gt;mail me for any clarification at : hi_abhay78@yahoo.co.in&lt;br /&gt;&lt;br /&gt;Happy learning..&lt;br /&gt;Abhay&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-8818202628607803475?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/8818202628607803475/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=8818202628607803475&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/8818202628607803475'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/8818202628607803475'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/10/what-if-yo-udo-not-know-servers-to-whic.html' title='what if yo udo not know the servers to whic hlogins belong......'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-6979051455471012128</id><published>2009-10-03T19:07:00.000+05:30</published><updated>2009-10-03T19:44:00.312+05:30</updated><title type='text'>SQL 2008 setup failes : This Process does not possess the SeSecurity privilege' privilege which is required for this operation.</title><content type='html'>Just got off this case on an idle Saturday :) ....let me share it .&lt;br /&gt;&lt;br /&gt;SQL Server 2008 on windows server 2008 .........I just hate this combination ...sorry but i really do ...&lt;br /&gt;&lt;br /&gt;Actually , i hate windows server 2008 because of its too many security restrictions ..&lt;br /&gt;&lt;br /&gt;anyway lets come straigh to the topic .&lt;br /&gt;&lt;br /&gt;The error is :&lt;strong&gt;This Process does not possess the SeSecurity privilege' privilege which is required for this operation&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This is Manage Auditing and Security Log right which can be seen in the local security settings (start &gt;&gt; run &gt;&gt; secpol.msc &gt;&gt; local policies &gt;&gt; User rights assignments). for more information see : http://msdn.microsoft.com/en-us/library/ms813959.aspx and http://msdn.microsoft.com/en-us/library/bb530716(VS.85).aspx.&lt;br /&gt;&lt;br /&gt;Access to the security event log is governed by SeSecurityPrivilege.Holders of the privilege have Read, Clear, and Backup permission.  Holders of SeAuditPrivilege can write to the log via internal LSA APIs only.LocalSystem can write to the security event log via the ReportEvent API due to permission granted via the log ACL.&lt;br /&gt;&lt;br /&gt;By default, these are the privilege assignments:&lt;br /&gt;&lt;br /&gt;SeSecurityPrivilege      Administrators, LocalSystem&lt;br /&gt;SeAuditPrivilege         LocalSystem&lt;br /&gt;&lt;br /&gt;So , you need to add your domain account or the domain group to which you belong in to this policy ......and yes you need to reboot the server.&lt;br /&gt;&lt;br /&gt;After reboot you will see SWEET &lt;strong&gt;Success&lt;/strong&gt;...&lt;br /&gt;&lt;br /&gt;Hope this helps ..&lt;br /&gt;&lt;br /&gt;Regards&lt;br /&gt;Abhay&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-6979051455471012128?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/6979051455471012128/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=6979051455471012128&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/6979051455471012128'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/6979051455471012128'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/10/sql-2008-setup-failes-this-process-does.html' title='SQL 2008 setup failes : This Process does not possess the SeSecurity privilege&apos; privilege which is required for this operation.'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-53800937998590507</id><published>2009-09-25T17:15:00.000+05:30</published><updated>2009-09-25T17:26:52.479+05:30</updated><title type='text'>No connection could be made because the target machine actively refused it.</title><content type='html'>I faced this situation yesterday .&lt;br /&gt;We were using Tivoli to connect to SQL Server 2005 (Clustered instance) to take backups.&lt;br /&gt;&lt;br /&gt;But it was failing with the error (not printing the complee error here):&lt;br /&gt;&lt;strong&gt;No connection could be made because the target machine actively refused it. &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;I asked myself why the server is refusing the client request ??&lt;br /&gt;Since the connection was failing , this issue had to do with connectivity .&lt;br /&gt;&lt;br /&gt;I started checking few things :&lt;br /&gt;&lt;br /&gt;1) Port on which SQL is listening &lt;br /&gt;2) named or default instance &lt;br /&gt;3) Protocols enabled @ server level and @ client level .&lt;br /&gt;&lt;br /&gt;It was a default instance on some port other than 1433 (as hackers can catch it easily).We found that it was SQL Server that was using this port ...how ??&lt;br /&gt;By connecting to SQL Server through management studio using &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;tcp:servername\instancename , portname&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;and it connected .We also did netstat -aon and or -aonb(this takes a lot of time as it also finds the exe name) and confirmed that only SQL Server is using this port.&lt;br /&gt;&lt;br /&gt;Then we checked SQL Server Client network utility (cliconfg) and found that no protocols were enabled .We enabled named pipes and TCP/IP (not sure how it got disabled).&lt;br /&gt;&lt;br /&gt;Tried to connect tivoli which failed again .Finally we forcibly made tivoli to connect to SQL Server usin gthat port by creating a TCP/IP alias ...&lt;br /&gt;This worked and our issue got resolved ..&lt;br /&gt;&lt;br /&gt;In past I found that the port SQL Server is using is either blocked or being used by other application .I that case stop that application and create the alias .&lt;br /&gt;&lt;br /&gt;Hope this helps !!!&lt;br /&gt;&lt;br /&gt;Regards&lt;br /&gt;Abhay&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-53800937998590507?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/53800937998590507/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=53800937998590507&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/53800937998590507'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/53800937998590507'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/09/no-connection-could-be-made-because.html' title='No connection could be made because the target machine actively refused it.'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-4689808981278355228</id><published>2009-09-14T13:58:00.000+05:30</published><updated>2009-09-14T14:36:31.461+05:30</updated><title type='text'>A significant part of sql server process memory has been paged out.</title><content type='html'>First of all : &lt;br /&gt;There is no solution to this issue in Windows 2003 (You might have lost the confidence after reading this :) ...read it fully).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is the sample error that we get :&lt;br /&gt;2007-01-23 16:30:10.14 spid1s A significant part of sql server process memory has been paged out. This may result in a performance degradation. Duration: 0 seconds. Working set (KB): 1086400, committed (KB): 2160928, memory utilization: 50%.&lt;br /&gt;&lt;br /&gt;Lets try to understand this error first :&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Duration&lt;/strong&gt; : the time or interval or gap after which this error has been reported. Here 0 means that this is the first time on that day , that this error occured.You will see a fixed pattern of duration .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Working set&lt;/strong&gt; :The memory pages kept in the RAM for the use of process/threads.Remember that this is set approximately by the OS and its the OS that can trim it or add to it if it see that too many pages ar ein RAM for a process and it needs to give minimum bare pages to some other process which it cannot .In our case its roughly 1 GB . Check wikipedia for a better definition (http://en.wikipedia.org/wiki/Working_set)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Committed &lt;/strong&gt;: The actual memory committed by SQL Server .NO one should be able to take this memory from SQL Server or deallocate it .Not even the OS .But it can be paged :) by the OS and thats what it does.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Memory Utilization&lt;/strong&gt; : the actual memory utilization by SQL Server after its working set is paged out .In this case its 50 which means the remaining 50 has been paged out .Had it been 2% then the remaining 98% is paged out .This error will start apperaing once the working set of SQL Server trims equal to or more than 50%&lt;br /&gt;&lt;br /&gt;Now , one can easily deduce that 2GB RAM was committed [see commited in the error] but only 1 GB was the working set (see the error again) .So 50% is the current working set as compared to its committed value .Remaining 50% in in the disk and hence SQL Server will have to go for Hard page fault in case the page its looking for is on the disk .&lt;br /&gt;&lt;br /&gt;Many a times you will see that on a cluster it will simply failover .This is because of the same effect .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;Why it happens ??&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Every process needs A contiguous chunk of memory but memory is largely fragmented ...&lt;br /&gt;Some EXEs needs large chunks of contiguous memory .So even if there is enough memory available , its fragmented .And thats the cause of this issue .&lt;br /&gt;&lt;br /&gt;When troubleshooting these type of issues, the key is to find out why the physical memory on the server gets exhausted and creates a situation that forces sql server to scale its memory usage back. As long as the available memory is below the limits for which Windows keeps sending low memory notification, sql server has no option but to scale itself back to avoid poor performance. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;More on the dynamic memory management capabilities of sql server is discussed in the topic http://msdn2.microsoft.com/en-us/library/ms178145.aspx &lt;br /&gt;&lt;br /&gt;There are a few situations where SQL Server Process working set might be paged out by Windows despite these memory resource notification mechanism. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-&gt; If windows is not sending the correct notifications to all listening processes at the right moment and thresholds. &lt;br /&gt;&lt;br /&gt;-&gt; If SQL Server is not responding fast enough to the low memory resource notification from Windows. &lt;br /&gt;&lt;br /&gt;-&gt; Conditions in Windows where working sets of all processes are trimmed. &lt;br /&gt;&lt;br /&gt;-&gt; Windows might decide to trim a certain percentage of working set of various or  specific processes. &lt;br /&gt;&lt;br /&gt;-&gt; Incorrect usage of memory management functions by Device Drivers. &lt;br /&gt;&lt;br /&gt;SQL Server memory management is designed to dynamically adjust the committed memory based on the amount of available memory on the system. SQL Server does this to avoid being paged out by the OS memory manager with the help of some APIs. &lt;br /&gt;&lt;br /&gt;SQL Server registers with the memory resource notifications of Windows. If a low memory notification comes from Windows, sql server scales its memory usage down. When windows sends the high memory notification, sql server can grow its memory usage target. The Win32 API's being used for these are documented in http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/creatememoryresourcenotification.asp &lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;Solutions&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;This issue can be fake or real .Do not panic if that workign ser is low , say in KBs or you get these errors when SQL Server starts up .&lt;br /&gt;&lt;br /&gt;But if its the other way out then you can go through options i have mentioned below .If eventually nothing works , then you need to dig out who on the server needs so much of memory that makes OS to trim SQL Server's working set .&lt;br /&gt;&lt;br /&gt;KNOWN ISSUES[Please go through each of it and apply as relevant]: &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;Microsoft has found some known issues that may cause the SQL Server 2005 process working set to be trimmed. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;Issue1: &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;For more information, click the following article number to view the article in the Microsoft Knowledge Base: &lt;br /&gt;&lt;br /&gt;905865 The sizes of the working sets of all the processes in a console session may be trimmed when you use Terminal Services to log on to or log off from a computer that is running Windows Server 2003 &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;Issue2: &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;Computers that are running Windows Server 2003 can be too aggressive when they cache dirty buffers if there is an application performing buffered I/O, such as a file copy operation. This behavior can cause the working set in SQL Server to be trimmed. For more information, click the following article number to view the article in the Microsoft Knowledge Base: &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;920739 You may experience a decrease in overall system performance when you are copying files that are larger than approximately 500 MB in Windows Server 2003 Service Pack 1 or Service Pack 2 &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;Issue3: &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;On a computer that is running SQL Server, applications may use the system cache too much. Therefore, the operating system will trim the working set of SQL Server or of other applications. If you notice that the application uses the system cache too much, you can use some memory management functions in the application. These functions control the system cache space that file IO operations can use in the application. For example, you can use the SetSystemFileCacheSize function and the GetSystemFileCacheSize function to control the system cache space that file IO operations can use. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;Issue4: &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;Additionally, third-party device drivers that use the MmAllocateContiguousMemory function and specify the value of the HighestAcceptableAddress parameter to less than 4 gigabytes (GB) may also cause the SQL Server 2005 64-bit working set to be trimmed. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;Currently, the iLO Management Channel Interface Driver (Cpqcidrv.sys) from Hewlett-Packard is known to cause this issue on x64 editions of SQL Server 2005. &lt;br /&gt;&lt;br /&gt;The integrated Lights-Out Management (iLO) Interface Driver update for Windows Server 2003 is available at the following Hewlett-Packard Web site: &lt;br /&gt;&lt;br /&gt;http://h20000.www2.hp.com/bizsupport/TechSupport/Document.jsp?lang=en&amp;cc=us&amp;objectID=c00688313&amp;jumpid=reg_R1002_USEN &lt;br /&gt;&lt;br /&gt;The problem is fixed in this driver update. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;Issue5: &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;Broadcom driver bxvbda.sys caused memory trimming via MmAllocateContiguousMemory() &lt;br /&gt;&lt;br /&gt;This driver is in Windows 2003 SP2, and OEM'ed from DELL and HP,  but originally from Broadcom. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;Disabling the advanced functionality from the driver may fully resolve the issue. In order to do that you have to do 2 things: &lt;br /&gt;&lt;br /&gt;- On Windows 2003 Sp1, apply the hotfix download from http://support.microsoft.com/default.aspx?scid=kb;EN-US;936594 and perform the below mentioned registry changes. On Windows 2003 Sp2, just perform the below mentioned registry changes. &lt;br /&gt;&lt;br /&gt;- Disable TCP Chimney, TCPA, and RSS using the registry entries &lt;br /&gt;&lt;br /&gt;[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters] &lt;br /&gt;&lt;br /&gt;"DisableTaskOffload"=dword:00000001 &lt;br /&gt;&lt;br /&gt;"EnableTCPA"=dword:00000000 &lt;br /&gt;&lt;br /&gt;"EnableRSS"=dword:00000000 &lt;br /&gt;&lt;br /&gt;"EnableTCPChimney"=dword:00000000 &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;TCP Chimney is a stateful offload. TCP Chimney offload enables TCP/IP processing to be offloaded to network adapters that can handle the TCP/IP processing in hardware. Each TCP Chimney offload-capable network adapter has a finite number of connections that it can support in hardware. TCP connections will be offloaded to hardware as long as the hardware can support these connections. After the hardware offload connection limit has been reached, all additional connections are handled by the host stack. &lt;br /&gt;&lt;br /&gt;Side effects: the NIC will actually function better &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;Article on the affect of the setting: http://support.microsoft.com/default.aspx?scid=kb;EN-US;912222 &lt;br /&gt;&lt;br /&gt;Article on how this setting affects SQL operations: http://support.microsoft.com/default.aspx?scid=kb;EN-US;918483 &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;Issue 6: &lt;br /&gt;&lt;br /&gt;938486 A Windows Server 2003-based computer becomes unresponsive because of a memory manager trimming operation that is caused by an indeterminate module that requests lots of memory &lt;br /&gt;&lt;br /&gt;http://support.microsoft.com/default.aspx?scid=kb;EN-US;938486 &lt;br /&gt;&lt;br /&gt;This kernel hotfix limits the number of trim operation per process to 8,192 pages. Previously, the memory manager would try to trim one-quarter of the working set size of a process. This can help to a certain extent on some of the processes being paged out. &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;ACTION PLAN that you can follow :   &lt;br /&gt;&lt;br /&gt;1. Cap SQL Server Max server memory to 75% of RAM and min to say , 1 GB . &lt;br /&gt;2. Increasing the LowMemoryThreshold value. &lt;br /&gt;Set the LowMemoryThreshold value (in MB), so the OS will notify applications such as SQL on low memory conditions much earlier. &lt;br /&gt;&lt;br /&gt;In Regedit -&gt; go to &lt;br /&gt;&lt;br /&gt;HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\SessionManager\MemoryManagement &lt;br /&gt;&lt;br /&gt;Right click on the right pane, &lt;br /&gt;&lt;br /&gt;Select New -&gt; select click DWORD Value -&gt; enter LowMemoryThreshold &lt;br /&gt;&lt;br /&gt;Double Click LowMemoryThreshold -&gt; value (choose decimal) -&gt; 650 &lt;br /&gt;&lt;br /&gt;Reboot required to take effect. &lt;br /&gt;&lt;br /&gt;Default values per MSDN: &lt;br /&gt;&lt;br /&gt;“The default level of available memory that signals a low-memory-resource notification event is approximately 32 MB per 4 GB, to a maximum of 64 MB. The default level that signals a high-memory-resource notification event is three times the default low-memory value.” &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;3. Disable TCP Chimney, TCPA, and RSS using the registry entries [mentioned above in known issues # 5] &lt;br /&gt;&lt;br /&gt;4.Reboot the server for the registry values to take effect . &lt;br /&gt;&lt;br /&gt;5. If needed be involve the OS(platforms) team to find out if there is any memory leak (chance of this is very less, but still) . &lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;References : &lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;http://support.microsoft.com/kb/918483 &lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;GOOD NEWS :&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;Lock Pages in memory option is available in SQL Server STD edition from SQL Server 2005 SP3 CU4 and SQL Server 2008 SP1 CU2 onwards .&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;CAUTION:&lt;/strong&gt;&lt;/em&gt;  &lt;br /&gt;LPIM should be the last resort that you should opt for .In worst case if you have to opt for it ,make sure you cap SQL Server Max server memory to 75% of RAm or might be less .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Happy Learning !!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-4689808981278355228?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/4689808981278355228/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=4689808981278355228&amp;isPopup=true' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4689808981278355228'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4689808981278355228'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/09/significant-part-of-sql-server-process.html' title='A significant part of sql server process memory has been paged out.'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-4697623647211464450</id><published>2009-09-12T00:34:00.001+05:30</published><updated>2009-09-12T00:41:20.428+05:30</updated><title type='text'>Recreating Builtin/administrator account in SQL Server 2005</title><content type='html'>Someone at client's site removed the builtin admin from SQL Server as it was one of the risks mentioned in the agreement .Everything was fine .&lt;br /&gt;&lt;br /&gt;However,during maintenance SQL server did not come up after the server reboot .They tried it with SA but they also forgot the SA pasword :-) ....awesome ...&lt;br /&gt;They were about to uninstall and reinstall SQL server when we finally did the steps below .It took me a lot of time but one of the options worked (with my previous MS experience ofcourse :) ).Below are the repro steps and the solution .&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Repro of issue :&lt;br /&gt;&lt;br /&gt;1) Delete the Builtin/administrator account .&lt;br /&gt;2) tested it through sqlcmd and got the error 18456 Level 14 State 1.&lt;br /&gt;3) assume that i have forgotten the SA password as well.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;Solution:&lt;br /&gt;&lt;br /&gt;1) Stop SQL Server service and start it with -m&lt;br /&gt;2) go to C:\Program Files\Microsoft SQL Server\90\Tools\Binn through cmd prompt&lt;br /&gt;3) type sqlcmd -E and hit enter .If its named instance then sqlcmd -    &lt;br /&gt;   -SServer\instance -E and hit enter.&lt;br /&gt;4) you will get &gt; sign &lt;br /&gt;5) commands you need to use&lt;br /&gt;   use master &lt;br /&gt;   go&lt;br /&gt;   CREATE LOGIN [BUILTIN\Administrators] FROM WINDOWS WITH DEFAULT_DATABASE=  &lt;br /&gt;   [master], DEFAULT_LANGUAGE=[us_english]&lt;br /&gt;   go&lt;br /&gt;&lt;br /&gt;6) You are done.Exit out of it .&lt;br /&gt;7) restart you SQL Server service without -m parameter.&lt;br /&gt;&lt;br /&gt;Happy learning .....&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-4697623647211464450?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/4697623647211464450/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=4697623647211464450&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4697623647211464450'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4697623647211464450'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/09/recreating-builtinadministrator-account.html' title='Recreating Builtin/administrator account in SQL Server 2005'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-1033231650351015308</id><published>2009-09-10T20:44:00.000+05:30</published><updated>2009-09-10T20:59:46.190+05:30</updated><title type='text'>Script to copy errors form error log and get it through mail .</title><content type='html'>This tim ei was asked to create job/SP that is capable to send a daily mail to DBAs with selected errors form error logs. Below are the steps to create a stored procedure to copy the errors from errorlogs to a table and then send the table as an attachment to our inbox .You might have to modify it as per your need .Or you can use WMI for SQL Server errorlogs ..I did not try that yet ...but will post it once done ...&lt;br /&gt;&lt;br /&gt;for mailing you can also use CDO...will post that stuff soon :) &lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Steps included are :&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;1) Creating database mail account &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;2)Creating database mail  profile&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;3) increasing the errorlogs to a default of 50 from 7&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;4) creating a table to store xp_readerrorlogs values &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;5) filtering the errors though a query&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;5) using database mail to send the output as an attachment to inbox&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;6) Finally recycling the errorlog&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;USE [msdb]&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;/*Step 1:Creating a database mail account */&lt;br /&gt;&lt;br /&gt;EXECUTE msdb.dbo.sysmail_add_account_sp&lt;br /&gt;&lt;br /&gt; @account_name = 'Test1',&lt;br /&gt;&lt;br /&gt; @description = 'Test account for Database Mail',&lt;br /&gt;&lt;br /&gt; @email_address = 'your_email.com',&lt;br /&gt;&lt;br /&gt; @display_name = 'Test1',&lt;br /&gt;&lt;br /&gt; @mailserver_name = 'smtp.&lt;domain&gt;.com'&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;/*Step 2:Creating a database mail profile */&lt;br /&gt;&lt;br /&gt;EXECUTE msdb.dbo.sysmail_add_profile_sp&lt;br /&gt;&lt;br /&gt; @profile_name = 'TestProfile',&lt;br /&gt;&lt;br /&gt; @description = 'Test Profile for database mail'&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;/*Step 3: adding database mail account to database profile created earlier*/&lt;br /&gt;&lt;br /&gt;EXECUTE msdb.dbo.sysmail_add_profileaccount_sp&lt;br /&gt;&lt;br /&gt; @profile_name = 'TestProfile',&lt;br /&gt;&lt;br /&gt; @account_name = 'Test1',&lt;br /&gt;&lt;br /&gt; @sequence_number = 1&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;/*Step 4:To make the TestProfile we created a default public profile */&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;EXECUTE msdb.dbo.sysmail_add_principalprofile_sp&lt;br /&gt;&lt;br /&gt; @profile_name = 'TestProfile',&lt;br /&gt;&lt;br /&gt; @principal_name = 'default',&lt;br /&gt;&lt;br /&gt; @is_default = 1 ;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;/* To increase the number of error logs to 50 :&lt;br /&gt;&lt;br /&gt;1: regedit &gt;&gt; HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\&lt;instancename&gt;\MSSQLServer&lt;br /&gt;&lt;br /&gt;2: create a REG_DWORD key 'NumErrorlogs' and set the value to 50&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;/* Step 6:create a table for keeping the error log values */&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;USE [master]&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;SET ANSI_NULLS ON&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;SET QUOTED_IDENTIFIER ON&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;SET ANSI_PADDING ON&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;CREATE TABLE [dbo].[errorlog](&lt;br /&gt;&lt;br /&gt; [logdate] [date] NULL,&lt;br /&gt;&lt;br /&gt; [processinfo] [varchar](20) NULL,&lt;br /&gt;&lt;br /&gt; [line] [varchar](1000) NULL&lt;br /&gt;&lt;br /&gt;) ON [PRIMARY]&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;SET ANSI_PADDING OFF&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;/* Step 7: Create a stored proc for :&lt;br /&gt;&lt;br /&gt;-&gt; Truncating the table we created above .&lt;br /&gt;&lt;br /&gt;-&gt; Inserting the values from error log into the table we created above &lt;br /&gt;&lt;br /&gt;-&gt; Sending the mail .&lt;br /&gt;&lt;br /&gt;-&gt; cycling the errorlog&lt;br /&gt;&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Create proc [dbo].[ErrorlogEmail] &lt;br /&gt;&lt;br /&gt;as&lt;br /&gt;&lt;br /&gt;truncate table errorlog&lt;br /&gt;&lt;br /&gt;insert into errorlog exec xp_readerrorlog&lt;br /&gt;&lt;br /&gt;DECLARE @SQL varchar(2000)&lt;br /&gt;&lt;br /&gt;DECLARE @date varchar (2000)&lt;br /&gt;&lt;br /&gt;DECLARE @File varchar(1000)&lt;br /&gt;&lt;br /&gt;select @date= convert(date,GETDATE())&lt;br /&gt;&lt;br /&gt;SET @SQL = 'select * from errorlog where line like (''%Severity%'') or line like (''15 seconds'') or line like (''%latch%'')or line like (''%BEGIN STACK DUMP%'')or line like (''%time-out%'')and logdate = convert(date,GETDATE())'&lt;br /&gt;&lt;br /&gt;SET @File = 'Errorlog report'+@date+'.csv'&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;EXECUTE msdb.dbo.sp_send_dbmail&lt;br /&gt;&lt;br /&gt;@profile_name = 'test',&lt;br /&gt;&lt;br /&gt;@recipients = 'your email.com',&lt;br /&gt;&lt;br /&gt;@subject = 'Errorlog report',&lt;br /&gt;&lt;br /&gt;@body = 'Attached please find the Daily errorlog report',&lt;br /&gt;&lt;br /&gt;@query =@SQL ,&lt;br /&gt;&lt;br /&gt;@attach_query_result_as_file = 1,&lt;br /&gt;&lt;br /&gt;@query_attachment_filename = @file,&lt;br /&gt;&lt;br /&gt;@query_result_header = 1,&lt;br /&gt;&lt;br /&gt;@query_result_separator = ' ',&lt;br /&gt;&lt;br /&gt;@query_result_no_padding = 1,&lt;br /&gt;&lt;br /&gt;@query_result_width = 32767 &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;/* Step 8: recycle errorlog */&lt;br /&gt;&lt;br /&gt;EXEC master.sys.sp_cycle_errorlog&lt;br /&gt;&lt;br /&gt;print 'Error log recycled'&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Hope this helps ...&lt;br /&gt;&lt;br /&gt;Happy Learning ...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-1033231650351015308?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/1033231650351015308/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=1033231650351015308&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1033231650351015308'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1033231650351015308'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/09/script-to-copy-errors-form-error-log.html' title='Script to copy errors form error log and get it through mail .'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-2107575721514422657</id><published>2009-09-02T19:09:00.000+05:30</published><updated>2009-09-02T19:57:43.286+05:30</updated><title type='text'>WMI alert that can detect any alteration to the SP [SQL 2005 and above]</title><content type='html'>This is the WMI alert that can detect any alteration to the Stored Procedure .Its going to tell you the date , login name , user name , object name .&lt;br /&gt;Like this we can create the alert on anything you want .As I said in my previous post ,WMI is very flexible , uses less resources and much faster .&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* Step 1: creating the table to capture the Alter Proc information */&lt;br /&gt;&lt;br /&gt;USE adventureworks&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[Alterprocevents]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)&lt;br /&gt;DROP TABLE [dbo].[Alterprocevents]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;CREATE TABLE [dbo].[Alterprocevents] (&lt;br /&gt;[AlertTime] [datetime] NOT NULL ,&lt;br /&gt;[Object_name] varchar(100),&lt;br /&gt;[Login_Name] varchar(100),&lt;br /&gt;[user_name] varchar(100),&lt;br /&gt;[RecordID] [int] IDENTITY (1,1) NOT FOR REPLICATION NOT NULL,&lt;br /&gt;[Flag] [int] NOT NULL CONSTRAINT [DF_AlterprocEvents_Flag]  DEFAULT ((0))&lt;br /&gt;) ON [PRIMARY]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;--CREATE INDEX [Alterproc_IDX01] ON [dbo].[Alterprocevents]([AlertTime]) WITH FILLFACTOR = 100 ON [PRIMARY]&lt;br /&gt;--GO&lt;br /&gt;&lt;br /&gt;/*Step 2 : Creating the Job that will enter values into the Alterprocevents table created above*/&lt;br /&gt;/*Error handling is also added and we are running it in a transaction*/&lt;br /&gt;USE [msdb]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = N'Capture Alter proc event')&lt;br /&gt;EXEC msdb.dbo.sp_delete_job @job_name = N'Capture Alter proc event', @delete_unused_schedule=1&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;BEGIN TRANSACTION&lt;br /&gt;DECLARE @ReturnCode INT&lt;br /&gt;SELECT @ReturnCode = 0&lt;br /&gt;&lt;br /&gt;IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)&lt;br /&gt;BEGIN&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;DECLARE @jobId BINARY(16)&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Capture Alter proc event', &lt;br /&gt;@enabled=1, &lt;br /&gt;@notify_level_eventlog=2, &lt;br /&gt;@notify_level_email=3, &lt;br /&gt;@notify_level_netsend=0, &lt;br /&gt;@notify_level_page=0, &lt;br /&gt;@delete_level=0, &lt;br /&gt;@description=N'Job for responding to Capture Alter proc event events', &lt;br /&gt;@category_name=N'[Uncategorized (Local)]', &lt;br /&gt;@job_id = @jobId OUTPUT&lt;br /&gt;&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;&lt;br /&gt;/*Step 3: Insert graph into LogEvents*/&lt;br /&gt;&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Insert graph into LogEvents', &lt;br /&gt;@step_id=1, &lt;br /&gt;@cmdexec_success_code=0, &lt;br /&gt;@on_success_action=1, &lt;br /&gt;@on_success_step_id=0, &lt;br /&gt;@on_fail_action=2, &lt;br /&gt;@on_fail_step_id=0, &lt;br /&gt;@retry_attempts=0, &lt;br /&gt;@retry_interval=0, &lt;br /&gt;@os_run_priority=0, @subsystem=N'TSQL', &lt;br /&gt;@command=N'&lt;br /&gt;&lt;br /&gt;INSERT INTO [dbo].[Alterprocevents](&lt;br /&gt;AlertTime, &lt;br /&gt;object_name,&lt;br /&gt;login_name,&lt;br /&gt;user_name&lt;br /&gt;)&lt;br /&gt;VALUES (&lt;br /&gt;GETDATE(), &lt;br /&gt;N''$(ESCAPE_NONE(WMI(objectname)))'',&lt;br /&gt;N''$(ESCAPE_NONE(WMI(loginname)))'',&lt;br /&gt;N''$(ESCAPE_NONE(WMI(username)))''&lt;br /&gt;)',&lt;br /&gt;@database_name=N'adventureworks', &lt;br /&gt;@flags=0&lt;br /&gt;&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;COMMIT TRANSACTION&lt;br /&gt;&lt;br /&gt;GOTO EndSave&lt;br /&gt;&lt;br /&gt;QuitWithRollback:&lt;br /&gt;IF (@@TRANCOUNT &gt; 0) ROLLBACK TRANSACTION&lt;br /&gt;EndSave:&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;/* Step 4: Creating the alert and associating it with the Job to be fired */&lt;br /&gt;&lt;br /&gt;USE [msdb]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = N'Respond to alterproc_change')&lt;br /&gt;EXEC msdb.dbo.sp_delete_alert @name=N'Respond to alterproc_change'&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;DECLARE @server_namespace varchar(255)&lt;br /&gt;IF ISNULL(CHARINDEX('\', @@SERVERNAME), 0) &gt; 0&lt;br /&gt;SET @server_namespace = N'\\.\root\Microsoft\SqlServer\ServerEvents\' + SUBSTRING(@@SERVERNAME, ISNULL(CHARINDEX('\', @@SERVERNAME), 0) + 1, LEN(@@SERVERNAME) - ISNULL(CHARINDEX('/', @@SERVERNAME), 0))&lt;br /&gt;ELSE&lt;br /&gt;SET @server_namespace = N'\\.\root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER'&lt;br /&gt;&lt;br /&gt;EXEC msdb.dbo.sp_add_alert @name=N'Respond to alterproc_change', &lt;br /&gt;@wmi_namespace=@server_namespace, &lt;br /&gt;@wmi_query=N'SELECT * FROM DDL_PROCEDURE_EVENTS', &lt;br /&gt;@job_name='Capture Alter proc event' ;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Hope you like it .&lt;br /&gt;Regards&lt;br /&gt;Abhay&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-2107575721514422657?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/2107575721514422657/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=2107575721514422657&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/2107575721514422657'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/2107575721514422657'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/09/wmi-alert-that-can-detect-any.html' title='WMI alert that can detect any alteration to the SP [SQL 2005 and above]'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-5846676849033994062</id><published>2009-09-02T19:03:00.000+05:30</published><updated>2009-09-02T19:07:57.379+05:30</updated><title type='text'>WMI alert for deadlocking (no need to configure trace flags 1222) : For SQL 2005 and above only</title><content type='html'>Before I proceed forward , I just wanted to say that scriting through WMI is amazing ..You will take some time in learning it and might get bored with syntax ...But believe me it will catch your interest as anything is posible wih it ..&lt;br /&gt;&lt;br /&gt;Here is the WMI script to trace the deadlock .Its only for SQL Server 2005 and above as I have to see if SQL Server 2000 supports WMI namespace by default.&lt;br /&gt;This also has the mailing script , which we can use for all kinds of alerts .WMI scrips are faster and less resource consuming .I have also added error handling and kept everything important in a transaction , so that it rollsback completely .This is for one database but we can configure for as many by only adding more alerts which will be using the same job.&lt;br /&gt;&lt;br /&gt;IMP : Its not going to work on RTM as there is a Bug where the job fails giving the incorrect syntax error (actualy it parses successfully).I applied SP3 and it worked .So not sure if it works on SP1 and SP2 .&lt;br /&gt;&lt;br /&gt;Part 1 : &lt;br /&gt;&lt;br /&gt;1) Creating the table to capture the deadlock information.&lt;br /&gt;2) Creating the Job that will enter values into the Deadlockevents table created above.&lt;br /&gt;3) Insert graph into LogEvents.&lt;br /&gt;4) Creating the alert and associating it with the Job to be fired.&lt;br /&gt;5) Create a stored proc for sending the deadlock information as .CSV file through the mail.&lt;br /&gt;6) Changing the flag to 1 so that next time this information is not sent.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* Step 1: creating the table to capture the deadlock information */&lt;br /&gt;&lt;br /&gt;USE &lt;DBNAME&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[DeadlockEvents]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)&lt;br /&gt;DROP TABLE [dbo].[DeadlockEvents]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;CREATE TABLE [dbo].[DeadlockEvents] (&lt;br /&gt;[AlertTime] [datetime] NOT NULL ,&lt;br /&gt;[DeadlockGraph] [xml],&lt;br /&gt;[RecordID] [int] IDENTITY (1,1) NOT FOR REPLICATION NOT NULL,&lt;br /&gt;[Flag] [int] NOT NULL CONSTRAINT [DF_DeadlockEvents_Flag]  DEFAULT ((0))&lt;br /&gt;) ON [PRIMARY]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;CREATE INDEX [DeadlockEvents_IDX01] ON [dbo].[DeadlockEvents]([AlertTime]) WITH FILLFACTOR = 100 ON [PRIMARY]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;/*Step 2 : Creating the Job that will enter values into the Deadlockevents table created above*/&lt;br /&gt;/*Service account and sql operator option are optional*/&lt;br /&gt;/*Error handling is also added and we are running it in a transaction*/&lt;br /&gt;USE [msdb]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = N'Capture Deadlock Graph')&lt;br /&gt;EXEC msdb.dbo.sp_delete_job @job_name = N'Capture Deadlock Graph', @delete_unused_schedule=1&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;DECLARE @ServiceAccount varchar(128)&lt;br /&gt;SET @ServiceAccount = N'&lt;job_owner_account&gt;'&lt;br /&gt;DECLARE @SQLOperator varchar(128)&lt;br /&gt;SET @SQLOperator = N'&lt;sql_agent_operator&gt;'&lt;br /&gt;&lt;br /&gt;BEGIN TRANSACTION&lt;br /&gt;DECLARE @ReturnCode INT&lt;br /&gt;SELECT @ReturnCode = 0&lt;br /&gt;&lt;br /&gt;IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)&lt;br /&gt;BEGIN&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;DECLARE @jobId BINARY(16)&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Capture Deadlock Graph', &lt;br /&gt;@enabled=1, &lt;br /&gt;@notify_level_eventlog=2, &lt;br /&gt;@notify_level_email=3, &lt;br /&gt;@notify_level_netsend=0, &lt;br /&gt;@notify_level_page=0, &lt;br /&gt;@delete_level=0, &lt;br /&gt;@description=N'Job for responding to DEADLOCK_GRAPH events', &lt;br /&gt;@category_name=N'[Uncategorized (Local)]', &lt;br /&gt;@owner_login_name=@ServiceAccount, &lt;br /&gt;@notify_email_operator_name=@SQLOperator, @job_id = @jobId OUTPUT&lt;br /&gt;&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;&lt;br /&gt;/*Step 3: Insert graph into LogEvents*/&lt;br /&gt;&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'Insert graph into LogEvents', &lt;br /&gt;@step_id=1, &lt;br /&gt;@cmdexec_success_code=0, &lt;br /&gt;@on_success_action=1, &lt;br /&gt;@on_success_step_id=0, &lt;br /&gt;@on_fail_action=2, &lt;br /&gt;@on_fail_step_id=0, &lt;br /&gt;@retry_attempts=0, &lt;br /&gt;@retry_interval=0, &lt;br /&gt;@os_run_priority=0, @subsystem=N'TSQL', &lt;br /&gt;@command=N'&lt;br /&gt;&lt;br /&gt;INSERT INTO DeadlockEvents (&lt;br /&gt;AlertTime, &lt;br /&gt;DeadlockGraph&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;VALUES (&lt;br /&gt;GETDATE(), &lt;br /&gt;N''$(ESCAPE_NONE(WMI(TextData)))''&lt;br /&gt;)', &lt;br /&gt;@database_name=N'master', &lt;br /&gt;@flags=0&lt;br /&gt;&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_update_job @job_id = @jobId, @start_step_id = 1&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;EXEC @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @jobId, @server_name = N'(local)'&lt;br /&gt;IF (@@ERROR &lt;&gt; 0 OR @ReturnCode &lt;&gt; 0) GOTO QuitWithRollback&lt;br /&gt;COMMIT TRANSACTION&lt;br /&gt;&lt;br /&gt;GOTO EndSave&lt;br /&gt;&lt;br /&gt;QuitWithRollback:&lt;br /&gt;IF (@@TRANCOUNT &gt; 0) ROLLBACK TRANSACTION&lt;br /&gt;EndSave:&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;/*Creating the alert and associating it with the Job to be fired */&lt;br /&gt;&lt;br /&gt;USE [msdb]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;IF EXISTS (SELECT name FROM msdb.dbo.sysalerts WHERE name = N'Respond to DEADLOCK_GRAPH')&lt;br /&gt;EXEC msdb.dbo.sp_delete_alert @name=N'Respond to DEADLOCK_GRAPH'&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;DECLARE @server_namespace varchar(255)&lt;br /&gt;IF ISNULL(CHARINDEX('\', @@SERVERNAME), 0) &gt; 0&lt;br /&gt;SET @server_namespace = N'\\.\root\Microsoft\SqlServer\ServerEvents\' + SUBSTRING(@@SERVERNAME, ISNULL(CHARINDEX('\', @@SERVERNAME), 0) + 1, LEN(@@SERVERNAME) - ISNULL(CHARINDEX('/', @@SERVERNAME), 0))&lt;br /&gt;ELSE&lt;br /&gt;SET @server_namespace = N'\\.\root\Microsoft\SqlServer\ServerEvents\MSSQLSERVER'&lt;br /&gt;&lt;br /&gt;EXEC msdb.dbo.sp_add_alert @name=N'Respond to DEADLOCK_GRAPH', &lt;br /&gt;@wmi_namespace=@server_namespace, &lt;br /&gt;@wmi_query=N'SELECT * FROM DEADLOCK_GRAPH', &lt;br /&gt;@job_name='Capture Deadlock Graph' ;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;/* Step 5: Create a stored proc for sending the deadlock information as .CSV file */&lt;br /&gt; &lt;br /&gt;Create proc [dbo].[Deadlock_rpt] &lt;br /&gt;as&lt;br /&gt;DECLARE @SQL varchar(2000)&lt;br /&gt;DECLARE @date varchar (2000)&lt;br /&gt;DECLARE @File varchar(1000)&lt;br /&gt;select @date= convert(date,GETDATE())&lt;br /&gt;SET @SQL = 'select * from deadlockevents where flag = 0'&lt;br /&gt;SET @File = 'Deadlock report'+@date+'.csv'&lt;br /&gt; &lt;br /&gt;EXECUTE msdb.dbo.sp_send_dbmail&lt;br /&gt;@profile_name = 'test',&lt;br /&gt;@recipients = 'your email.com',&lt;br /&gt;@subject = 'Deadlock report',&lt;br /&gt;@body = '***URGENT***Attached please find the deadlock report',&lt;br /&gt;@query =@SQL ,&lt;br /&gt;@attach_query_result_as_file = 1,&lt;br /&gt;@query_attachment_filename = @file,&lt;br /&gt;@query_result_header = 1,&lt;br /&gt;@query_result_separator = ' ',&lt;br /&gt;@query_result_no_padding = 1,&lt;br /&gt;@query_result_width = 32767 &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/* Step 6: Changing the flag to 1 so that next time this information is not sent*/ &lt;br /&gt;update dbo.DeadlockEvents set flag = 1 where flag = 0&lt;br /&gt;go&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Part 2:&lt;br /&gt;&lt;br /&gt;1) Creating the DbMmail account &lt;br /&gt;2) Creating a DbMail profile.&lt;br /&gt;3) Adding account to profile.&lt;br /&gt;4) making the profile as public.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;USE [msdb]&lt;br /&gt;GO&lt;br /&gt; &lt;br /&gt;/*Step 1:Creating a database mail account */&lt;br /&gt;  EXECUTE msdb.dbo.sysmail_add_account_sp&lt;br /&gt; @account_name = 'Test1',&lt;br /&gt; @description = 'Test account for Database Mail',&lt;br /&gt; @email_address = 'your_email.com',&lt;br /&gt; @display_name = 'Test1',&lt;br /&gt; @mailserver_name = 'smtp.&lt;domain&gt;.com'&lt;br /&gt; &lt;br /&gt;/*Step 2:Creating a database mail profile */&lt;br /&gt; EXECUTE msdb.dbo.sysmail_add_profile_sp&lt;br /&gt; @profile_name = 'TestProfile',&lt;br /&gt; @description = 'Test Profile for database mail'&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt;/*Step 3: adding database mail account to database profile created earlier*/&lt;br /&gt;EXECUTE msdb.dbo.sysmail_add_profileaccount_sp&lt;br /&gt; @profile_name = 'TestProfile',&lt;br /&gt; @account_name = 'Test1',&lt;br /&gt; @sequence_number = 1&lt;br /&gt; &lt;br /&gt;/*Step 4:To make the TestProfile we created a default public profile */&lt;br /&gt; EXECUTE msdb.dbo.sysmail_add_principalprofile_sp&lt;br /&gt; @profile_name = 'TestProfile',&lt;br /&gt; @principal_name = 'default',&lt;br /&gt; @is_default = 1 ;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-5846676849033994062?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/5846676849033994062/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=5846676849033994062&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5846676849033994062'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5846676849033994062'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/09/wmi-alert-for-deadlocking-no-need-to.html' title='WMI alert for deadlocking (no need to configure trace flags 1222) : For SQL 2005 and above only'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-8325007203469936280</id><published>2009-09-02T18:41:00.000+05:30</published><updated>2009-09-02T18:59:27.820+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='How to drop all the user databases in one GO'/><title type='text'>How to drop all the user databases in one GO</title><content type='html'>It was Saturday Morning and I had a task @ hand .&lt;br /&gt;One of my collegues wanted me to write a script to drop all the user databases at one go ..&lt;br /&gt;&lt;br /&gt;I was initially reluctant as I thought any DDL can not take variables .But then I tried with some other stuff which did not use variables with DMLs.&lt;br /&gt;&lt;br /&gt;Initially I came up with the script below :&lt;br /&gt;&lt;br /&gt;Create table drop_db(name sysname) &lt;br /&gt;Insert into drop_db select name from sysdatabases where dbid &gt;4 &lt;br /&gt;Select 'drop database ' + name from db_name&lt;br /&gt;&lt;br /&gt;Copy the output and execute.You canuse the same trick for other purposes as well .&lt;br /&gt;&lt;br /&gt;But then I wanted to give it some more try and came up with the final script .&lt;br /&gt;&lt;br /&gt;Drop table #db_name &lt;br /&gt;Go&lt;br /&gt;Create table #db_drop (name sysname,flag int identity (1,1) ) &lt;br /&gt;Insert into #db_drop select name from sysdatabases where dbid&gt;4 &lt;br /&gt;Declare @@flag1 int&lt;br /&gt;Select @@flag1 =max (flag) from #db_drop &lt;br /&gt;&lt;br /&gt;While @@flag1 &gt;0&lt;br /&gt;Begin &lt;br /&gt;Declare @string nvarchar (30)&lt;br /&gt;Declare @dbname sysname &lt;br /&gt;Select @dbname =name from #db_drop where flag=@@flag1&lt;br /&gt;Print @dbname + ' is being deleted'&lt;br /&gt;Set @string =' drop database ' + @dbname  &lt;br /&gt;Execute sp_executesql @string &lt;br /&gt;Set @@flag1 =@@flag1 +1&lt;br /&gt;End&lt;br /&gt;Drop table #db_drop&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-8325007203469936280?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/8325007203469936280/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=8325007203469936280&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/8325007203469936280'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/8325007203469936280'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/09/how-to-drop-all-user-databases-in-one.html' title='How to drop all the user databases in one GO'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-4815841227911960274</id><published>2009-06-17T12:27:00.000+05:30</published><updated>2011-04-27T20:01:08.563+05:30</updated><title type='text'>How to automate LogShipping setup On the large number of databases</title><content type='html'>&lt;strong&gt;Warning : Use it at your own risk after testing on DEV/TEST.Publisher has no responsibility whatsoever of the issues that you might face :D ....&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Well, I was given the task of setting up logshipping for more than 800 databases .&lt;br /&gt;I started scratching my head since there was no help available anywhere .&lt;br /&gt;Finally , I decided to create my own scripts .Below I have copied the scripts and also a resolution of the issue that I found very common on the internet .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Assumptions :&lt;/strong&gt;&lt;br /&gt;-&gt; this is for the fresh setup of logshipping and not for the setup where you have already set it up on some databses and now wan tto set it up on some more databases .&lt;br /&gt;-&gt; You need to first backup and restore the databases to the standby server in the standby mode or you can automate it .There are many scripts available on the internet.So i am not reinventing the wheel.&lt;br /&gt;-&gt; I will update this script at a later stage to take backups and restore it in standby mode on another server with move option .&lt;br /&gt;-&gt; This script is assuming that all the user databases on the server instance needs to be log shipped .So , you need to either manually delete the jobs that are going to be created or need to automate it.I am sure its not that difficult .something like tweaking sp_helpdb and creating a new SP wiht the dbname output (or just inserting the complete output in a temp table ).sp_helpdb will nto show you the databases that are offline .So you can take all the databases offfline that you do not want to be logshipped .Ofcourse its a bad idea but i just gave you the hint that its possible to have some adjustment that can allow you to logship few databases .&lt;br /&gt;-&gt; At many places you need to change the inputs like server/instance name , job/schedule name etc etc .In short whatever is fixed and in single quotes can be changed .Again it can be automated for sure .But I just dint take that pain.&lt;br /&gt;-&gt; You need to be in SQLCMD mode. on the Query menu select the SQLCMD mode .&lt;br /&gt;-&gt; You need to first run this script on the principal server and from there it will connect to the mirror using SQLCMD command :connect server\instance.&lt;br /&gt;-&gt; Instead of running this as a script you can also create a stored proc and execute it .&lt;br /&gt;-&gt; I have not added any kind of rolling back stuff so that if anything goes wrong it rolls back the changes .So you need to manually remove the logshipping using GUI in case any step fails .Its quite easy but generally there is no need to do this as it runs fine .&lt;br /&gt;-&gt; I have also created 3 jobs that are going to serially execute all the other jobs[backup/copy/restore] on both the servers .But all of them does not have the last step set as "quit with success" .You need to manually set that in 3 jobs. &lt;br /&gt;-&gt; wait for delay is optional .You can remove it if needed be .&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Check this first :&lt;br /&gt;---------------------&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Run these SPs first on secondary and then on Primary if your previous setup failed or had some issue wiping out the stuff:&lt;br /&gt;You can write a script to take the database names from sysdatabases and then fetch it to the variables (you will see how its done in the script many times).&lt;br /&gt;&lt;br /&gt;sp_delete_log_shipping_primary_database @database= '&lt;dbname&gt;'&lt;br /&gt;sp_delete_log_shipping_primary_secondary @primary_database='&lt;dbname&gt;',@secondary_server='abhay-test\SPIDER',@secondary_database ='&lt;dbname&gt;'&lt;br /&gt;sp_delete_log_shipping_secondary_database @secondary_database='&lt;dbname&gt;'&lt;br /&gt;sp_delete_log_shipping_secondary_primary @primary_database='&lt;dbname&gt;',@primary_server='abhay-test\Apollo'&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;check these tables on both primary and secondary in MSDB context .If you find any row that should not be there i.e. a row for a database which is no longer a part of logshipping but still exists , delete that row using where clause .if you feel that you first setup of logshipping failed and all the rows in the tables below are not needed delete all the rows .&lt;br /&gt;&lt;br /&gt;dbo.log_shipping_monitor_alert &lt;br /&gt;dbo.log_shipping_monitor_error_detail&lt;br /&gt;dbo.log_shipping_monitor_history_detail&lt;br /&gt;dbo.log_shipping_secondary_databases&lt;br /&gt;dbo.log_shipping_secondary&lt;br /&gt;dbo.log_shipping_secondaries&lt;br /&gt;dbo.log_shipping_primary_secondaries&lt;br /&gt;dbo.log_shipping_primary_databases&lt;br /&gt;dbo.log_shipping_primaries&lt;br /&gt;dbo.log_shipping_monitor_secondary&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;/* Start of the Script Primary is ORION and Secondary is SHERRY*/&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;:connect abhay\Orion &lt;--you can change it/*STEP 1 : This step will setup logshipping jobs on the principal instance*/use MSDBgoprint 'STEP 1:This step will setup logshipping jobs on the principal instance'gowaitfor delay '00:00:01'declare @var intDECLARE @dbname sysname ,@dbsid intDECLARE LSP_cursor CURSOR FORSELECT name,dbid FROM sys.sysdatabases where dbid &gt;4 --order by dbid desc&lt;br /&gt;OPEN LS_cursor&lt;br /&gt;FETCH NEXT FROM LSP_cursor INTO @dbname,@dbsid&lt;br /&gt;&lt;br /&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;&lt;br /&gt;BEGIN&lt;br /&gt;declare @database1 sysname&lt;br /&gt;declare @backup_job_name1 sysname&lt;br /&gt;declare @schedule_name1 sysname&lt;br /&gt;declare @primary_database1 sysname&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;begin&lt;br /&gt;set @database1 =@dbname&lt;br /&gt;set @backup_job_name1 =N'LSBackup_dbid_' + @dbname&lt;br /&gt;set @primary_database1 = @dbname&lt;br /&gt;&lt;br /&gt;Begin&lt;br /&gt;DECLARE @LS_BackupJobId AS uniqueidentifier &lt;br /&gt;DECLARE @LS_PrimaryId AS uniqueidentifier &lt;br /&gt;DECLARE @SP_Add_RetCode As int&lt;br /&gt;DECLARE @backup_job_name sysname &lt;br /&gt;DECLARE @backup_job_id AS uniqueidentifier&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;EXEC @SP_Add_RetCode = master.dbo.sp_add_log_shipping_primary_database &lt;br /&gt;@database = @database1 &lt;br /&gt;,@backup_directory = N'C:\Principal Mirror share' &lt;--you can change it,@backup_share = N'\\abhay\Principal Mirror share' &lt;--you can change it,@backup_job_name = @backup_job_name1 ,@backup_retention_period = 4320,@backup_compression = 2,@backup_threshold = 60 ,@threshold_alert_enabled = 1,@history_retention_period = 5760 ,@backup_job_id = @LS_BackupJobId OUTPUT ,@primary_id = @LS_PrimaryId OUTPUT ,@overwrite = 1IF (@@ERROR = 0 AND @SP_Add_RetCode = 0) BEGIN DECLARE @LS_BackUpScheduleUID As uniqueidentifier DECLARE @LS_BackUpScheduleID AS intEXEC msdb.dbo.sp_add_schedule @schedule_name =N'LSBackupSchedule_ORION_common'&lt;--you can change it,@enabled = 1 ,@freq_type = 4 ,@freq_interval = 1 ,@freq_subday_type = 4 ,@freq_subday_interval = 15 ,@freq_recurrence_factor = 0 ,@active_start_date = 20090507 ,@active_end_date = 99991231 ,@active_start_time = 0 ,@active_end_time = 235900 ,@schedule_uid = @LS_BackUpScheduleUID OUTPUT ,@schedule_id = @LS_BackUpScheduleID OUTPUT  EXEC msdb.dbo.sp_attach_schedule @job_id = @LS_BackupJobId ,@schedule_id = @LS_BackUpScheduleID  EXEC msdb.dbo.sp_update_job @job_id = @LS_BackupJobId ,@enabled = 0ENDset @LS_BackUpScheduleUID =nullset @LS_BackUpScheduleID =nullENDEXEC master.dbo.sp_add_log_shipping_alert_jobEXEC master.dbo.sp_add_log_shipping_primary_secondary @primary_database = @dbname,@secondary_server = N'ABHAY\Sherry' &lt;--you can change it,@secondary_database = @primary_database1 ,@overwrite = 1  FETCH NEXT FROM LS_cursor INTO @dbname,@dbsidset @LS_BackupJobId =null set @LS_PrimaryId =nullset @SP_Add_RetCode =nullset @backup_job_name =nullset @backup_job_id =nullset @database1 =nullset @backup_job_name1 =nullset @schedule_name1 =nullset @primary_database1 =nullENDendCLOSE LSP_cursorDEALLOCATE LS_cursorGOprint '****** End of STEP 1 ******' waitfor delay '00:00:01'/* STEP2: This will create a job that is going to execute all the logshipping backup jobs serially on principal instance*/print 'STEP 2:This step will create a job that is going to execute all the logshipping backup jobs serially on principal instance'gowaitfor delay '00:00:01'USE [msdb]GODECLARE @ReturnCode INTSELECT @ReturnCode = 0IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)BEGINEXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'ENDDECLARE @jobId BINARY(16)EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Serial Execution of logshipping backup ', @enabled=1, @notify_level_eventlog=0, @notify_level_email=0, @notify_level_netsend=0, @notify_level_page=0, @delete_level=0, @description=N'Serial Execution of log shipping backup jobs.', @category_name=N'[Uncategorized (Local)]', @owner_login_name=N'emids1\abhayc', @job_id = @jobId OUTPUT DECLARE @sec_dbname varchar(200), @command1 varchar(200)DECLARE bckp_cursor CURSOR FORselect secondary_database ,primary_id from dbo.log_shipping_primary_secondaries where secondary_database &lt;&gt; 'model'&lt;br /&gt;&lt;br /&gt;OPEN bckp_cursor&lt;br /&gt;FETCH NEXT FROM bckp_cursor INTO @sec_dbname, @command1&lt;br /&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;BEGIN&lt;br /&gt;&lt;br /&gt;DECLARE @command2 varchar (1000)&lt;br /&gt;Declare @sec_dbname1 varchar (1000)&lt;br /&gt;Set @command2=N'"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqllogship.exe" -Backup '+@command1+' -server ABHAY\Sherry' &lt;--you can change itSet @sec_dbname1= N'for '+ @sec_dbnameEXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=@sec_dbname1, @cmdexec_success_code=0, @on_success_action=3, @on_success_step_id=0, @on_fail_action=2, @on_fail_step_id=0, @retry_attempts=0, @retry_interval=0, @os_run_priority=0, @subsystem=N'CmdExec', @command=@command2,@flags=0FETCH NEXT FROM bckp_cursor INTO @sec_dbname, @command1 ENDCLOSE bckp_cursorDEALLOCATE bckp_cursorGOUSE msdb &lt;-- this is because many a times i have got the error that the job is not registered with the server .So need to add this step .EXEC sp_add_jobserver @job_name = 'Serial Execution of logshipping backup',@server_name = 'ABHAY\Orion'&lt;--you can change itgoprint '****** End of STEP 2 ******' waitfor delay '00:00:01'/* STEP 3: This step will create all the logshipping jobs on standby instance*/:connect abhay\Sherryprint 'STEP 3: This step will create all the logshipping jobs on standby instance'waitfor delay '00:00:01'Use MSDBGodeclare @var intDECLARE @dbname sysname ,@dbsid intDECLARE LSS_cursor CURSOR FORSELECT name,dbid FROM sys.sysdatabases where dbid &gt; 4 --order by dbid desc&lt;br /&gt;OPEN LS_cursor&lt;br /&gt;FETCH NEXT FROM LSS_cursor INTO @dbname,@dbsid&lt;br /&gt;&lt;br /&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;&lt;br /&gt;Begin&lt;br /&gt;&lt;br /&gt;declare @copy_job_name1 sysname&lt;br /&gt;declare @restore_job_name1 sysname&lt;br /&gt;declare @database1 sysname&lt;br /&gt;declare @schedule_name1 sysname&lt;br /&gt;declare @primary_database1 sysname&lt;br /&gt;&lt;br /&gt;begin&lt;br /&gt;set @database1 =@dbname&lt;br /&gt;set @copy_job_name1 =N'LScopy_dbid_' + @dbname&lt;br /&gt;set @primary_database1 = @dbname&lt;br /&gt;set @copy_job_name1=N'LSCopy_dbid_' + @dbname&lt;br /&gt;set @restore_job_name1=N'LSRestore_dbid_' + @dbname&lt;br /&gt;&lt;br /&gt;begin &lt;br /&gt;DECLARE @LS_Secondary__CopyJobId AS uniqueidentifier &lt;br /&gt;DECLARE @LS_Secondary__RestoreJobId AS uniqueidentifier &lt;br /&gt;DECLARE @LS_Secondary__SecondaryId AS uniqueidentifier &lt;br /&gt;DECLARE @LS_Add_RetCode As int&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;EXEC @LS_Add_RetCode = master.dbo.sp_add_log_shipping_secondary_primary &lt;br /&gt;@primary_server = N'ABHAY\Orion' &lt;--you can change it,@primary_database = @database1 ,@backup_source_directory = N'\\abhay\Principal Mirror share' &lt;--you can change it,@backup_destination_directory = N'E:\Mirroring test\backups' &lt;--you can change it,@copy_job_name = @copy_job_name1 ,@restore_job_name = @restore_job_name1 ,@file_retention_period = 4320 ,@overwrite = 1 ,@copy_job_id = @LS_Secondary__CopyJobId OUTPUT ,@restore_job_id = @LS_Secondary__RestoreJobId OUTPUT ,@secondary_id = @LS_Secondary__SecondaryId OUTPUTIF (@@ERROR = 0 AND @LS_Add_RetCode = 0) BEGINDECLARE @LS_SecondaryCopyJobScheduleUID As uniqueidentifier DECLARE @LS_SecondaryCopyJobScheduleID AS int EXEC msdb.dbo.sp_add_schedule @schedule_name =N'DefaultCopyJobSchedule_Sherry' &lt;--you can change it [using 1 schedule for all jobs],@enabled = 1 ,@freq_type = 4 ,@freq_interval = 1 ,@freq_subday_type = 4 ,@freq_subday_interval = 15 ,@freq_recurrence_factor = 0 ,@active_start_date = 20090511 ,@active_end_date = 99991231 ,@active_start_time = 0 ,@active_end_time = 235900 ,@schedule_uid = @LS_SecondaryCopyJobScheduleUID OUTPUT ,@schedule_id = @LS_SecondaryCopyJobScheduleID OUTPUTEXEC msdb.dbo.sp_attach_schedule @job_id = @LS_Secondary__CopyJobId ,@schedule_id = @LS_SecondaryCopyJobScheduleIDDECLARE @LS_SecondaryRestoreJobScheduleUID As uniqueidentifier DECLARE @LS_SecondaryRestoreJobScheduleID AS int EXEC msdb.dbo.sp_add_schedule @schedule_name =N'DefaultRestoreJobSchedule_Sherry' ,@enabled = 1 ,@freq_type = 4 ,@freq_interval = 1 ,@freq_subday_type = 4 ,@freq_subday_interval = 15 ,@freq_recurrence_factor = 0 ,@active_start_date = 20090511 ,@active_end_date = 99991231 ,@active_start_time = 0 ,@active_end_time = 235900 ,@schedule_uid = @LS_SecondaryRestoreJobScheduleUID OUTPUT ,@schedule_id = @LS_SecondaryRestoreJobScheduleID OUTPUTEXEC msdb.dbo.sp_attach_schedule @job_id = @LS_Secondary__RestoreJobId ,@schedule_id = @LS_SecondaryRestoreJobScheduleID END DECLARE @LS_Add_RetCode2 As int IF (@@ERROR = 0 AND @LS_Add_RetCode = 0) BEGINEXEC @LS_Add_RetCode2 = master.dbo.sp_add_log_shipping_secondary_database @secondary_database = @database1 ,@primary_server = N'ABHAY\Orion' ,@primary_database = @database1 ,@restore_delay = 0 ,@restore_mode = 1 ,@disconnect_users = 0 ,@restore_threshold = 45 ,@threshold_alert_enabled = 1 ,@history_retention_period = 5760 ,@overwrite = 1END IF (@@error = 0 AND @LS_Add_RetCode = 0) BEGINEXEC msdb.dbo.sp_update_job @job_id = @LS_Secondary__CopyJobId ,@enabled = 0 &lt;-- disabled by defaultEXEC msdb.dbo.sp_update_job @job_id = @LS_Secondary__RestoreJobId ,@enabled = 0 &lt;-- Disabled by defaultENDFETCH NEXT FROM LS_cursorINTO @dbname,@dbsid/*need to set the values to null else it will only take the last database values and will create logshippin gon only 1 database.*/set @LS_Secondary__CopyJobId =null set @LS_Secondary__RestoreJobId =nullset @copy_job_name1 =nullset @database1 =nullset @restore_job_name1 =nullset @schedule_name1 =nullset @primary_database1 =nullENDendendCLOSE LSS_cursorDEALLOCATE LSS_cursorGOprint '****** End of STEP 3 ******' waitfor delay '00:00:01'/* STEP 4: This step will create a job that is going to execute all the logshipping restore jobs serially on standby instance*/print 'STEP 4: This step will create a job that is going to execute all the logshipping restore jobs serially on standby instance'gowaitfor delay '00:00:01'USE [msdb]GODECLARE @ReturnCode INTSELECT @ReturnCode = 0IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)BEGINEXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'ENDDECLARE @jobId BINARY(16)EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Serial Execution Restore', @enabled=1, @notify_level_eventlog=0, @notify_level_email=0, @notify_level_netsend=0, @notify_level_page=0, @delete_level=0, @description=N'Serial Execution of log shipping Restore jobs.', @category_name=N'[Uncategorized (Local)]', @owner_login_name=N'emids1\abhayc', @job_id = @jobId OUTPUT DECLARE @sec_dbname varchar(200), @command1 varchar(200)DECLARE rest_cursor CURSOR FORselect primary_database ,secondary_id from dbo.log_shipping_secondary where primary_database &lt;&gt; 'model'&lt;br /&gt;&lt;br /&gt;OPEN cpy_rest_cursor&lt;br /&gt;FETCH NEXT FROM rest_cursor INTO @sec_dbname, @command1&lt;br /&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;BEGIN&lt;br /&gt;&lt;br /&gt;DECLARE @command2 varchar (1000)&lt;br /&gt;Declare @sec_dbname1 varchar (1000)&lt;br /&gt;Set @command2=N'"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqllogship.exe" -Restore '+@command1+' -server ABHAY\Sherry' &lt;--you can change itSet @sec_dbname1= N'for '+ @sec_dbnameEXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=@sec_dbname1, @cmdexec_success_code=0, @on_success_action=3, @on_success_step_id=0, @on_fail_action=2, @on_fail_step_id=0, @retry_attempts=0, @retry_interval=0, @os_run_priority=0, @subsystem=N'CmdExec', @command=@command2,@flags=0FETCH NEXT FROM rest_cursor INTO @sec_dbname, @command1ENDCLOSE rest_cursorDEALLOCATE rest_cursorGOUSE msdbEXEC sp_add_jobserver @job_name = 'Serial Execution Restore', @server_name = 'Abhay\Sherry'goprint '****** End of STEP 4 ******' waitfor delay '00:00:01'/* STEP 5: This step will create a job that is going to execute all the logshipping copy jobs serially on standby instance*/print 'STEP 5: This step will create a job that is going to execute all the logshipping copy jobs serially on standby instance'waitfor delay '00:00:01'USE [msdb]GODECLARE @ReturnCode INTSELECT @ReturnCode = 0IF NOT EXISTS (SELECT name FROM msdb.dbo.syscategories WHERE name=N'[Uncategorized (Local)]' AND category_class=1)BEGINEXEC @ReturnCode = msdb.dbo.sp_add_category @class=N'JOB', @type=N'LOCAL', @name=N'[Uncategorized (Local)]'ENDDECLARE @jobId BINARY(16)EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'Serial Execution Copy', @enabled=1, @notify_level_eventlog=0, @notify_level_email=0, @notify_level_netsend=0, @notify_level_page=0, @delete_level=0, @description=N'Serial Execution of log shipping Copy jobs.', @category_name=N'[Uncategorized (Local)]', @owner_login_name=N'emids1\abhayc', @job_id = @jobId OUTPUT DECLARE @sec_dbname varchar(200), @command1 varchar(200)DECLARE cpy_cursor CURSOR FORselect primary_database ,secondary_id from dbo.log_shipping_secondary where primary_database &lt;&gt; 'model'&lt;br /&gt;&lt;br /&gt;OPEN cpy_cursor&lt;br /&gt;FETCH NEXT FROM cpy_cursor INTO @sec_dbname, @command1&lt;br /&gt;WHILE @@FETCH_STATUS = 0&lt;br /&gt;BEGIN&lt;br /&gt;&lt;br /&gt;DECLARE @command2 varchar (1000)&lt;br /&gt;Declare @sec_dbname1 varchar (1000)&lt;br /&gt;Set @command2=N'"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqllogship.exe" -Copy '+@command1+' -server ABHAY\Sherry' &lt;--you can change itSet @sec_dbname1= N'for '+ @sec_dbnameEXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=@sec_dbname1, @cmdexec_success_code=0, @on_success_action=3, @on_success_step_id=0, @on_fail_action=2, @on_fail_step_id=0, @retry_attempts=0, @retry_interval=0, @os_run_priority=0, @subsystem=N'CmdExec', @command=@command2,@flags=0FETCH NEXT FROM cpy_cursor INTO @sec_dbname, @command1 ENDCLOSE cpy_cursorDEALLOCATE cpy_cursorGOUSE msdbEXEC sp_add_jobserver @job_name = 'Serial Execution Copy', @server_name = 'Abhay\Sherry'goprint '****** End of STEP 5 ******'    &lt;strong&gt;Issues I faced :&lt;br /&gt;----------------------&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Issue 1: &lt;/strong&gt;&lt;br /&gt;first issue that I faced was that the job was not registerd to the server .It was not every time but sometimes .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Solution : &lt;/strong&gt;&lt;br /&gt;So I explicitly add the step to register the job using "sp_add_jobserver" .&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;strong&gt;&lt;br /&gt;Issue 2 : &lt;/strong&gt;&lt;br /&gt;The second issue that I faced ate a lot of my time :) .Issue is the copy and restore jobs failing on the secondary server .&lt;br /&gt;&lt;strong&gt;*** Error: The specified agent_id 76D087E5-B8BB-47BE-886B-3EF9CCC3A7DE or agent_type 1 do not form a valid pair for log shipping monitoring processing.(.Net SqlClient Data Provider) ***&lt;/strong&gt;&lt;br /&gt;-&gt; this agent id is the database ID .Cross check in the copy job .And notice that its saying about log shipping monitoring processing . &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Solution :&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Notice what the error is trying to say :&lt;br /&gt;-&gt; agent_type 1 : is the copy job .0 is for backup and 2 is for restore &lt;br /&gt;-&gt; 76D087E5-B8BB-47BE-886B-3EF9CCC3A7DE: is the secondary database UID .unique for all the databases .&lt;br /&gt;-&gt; This issue has something to do with log shipping monitoring .&lt;br /&gt;&lt;br /&gt;So I decided to go through all the logshipping system tables .I found that dbo.log_shipping_secondary_databases and dbo.log_shipping_monitor_secondary have one row each for all the logshipped database.&lt;br /&gt;&lt;br /&gt;dbo.log_shipping_monitor_secondary : is going to keep the last backup and restore information of the log .the value changes with every copy and restore on the standby server.&lt;br /&gt;dbo.log_shipping_secondary_databases : is going to have the entry for all the secondaty databases and the job properties with the last restored date .&lt;br /&gt;&lt;br /&gt;I found that even after settign up the log shipping these 2 tables were not showing me the 2 entries .Further , i got 1 entry form the previous setup that was still existing .&lt;br /&gt;I cleaned up the table and inserted 2 rows each in both the tables :&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;insert into dbo.log_shipping_secondary_databases values ('Adventureworks','C569B95C-ADA3-466A-B814-E19756D42EBA',0,1,1,0,-1,-1,-1,NULL,NULL)&lt;br /&gt;insert into log_shipping_monitor_secondary values ('abhay\SHERRY','Adventureworks','C569B95C-ADA3-466A-B814-E19756D42EBA','abhay\ORION','Adventureworks',45,14421,1,NULL,null,NULL,null,null,NULL,null,5760)&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;insert into log_shipping_monitor_secondary values ('abhay\Sherry','OHM','76D087E5-B8BB-47BE-886B-3EF9CCC3A7DE','abhay\Orion','OHM',45,14421,1,NULL,null,NULL,null,null,NULL,null,5760) . Restart the agent ...it wont work &lt;br /&gt;insert into dbo.log_shipping_secondary_databases values ('OHM','76D087E5-B8BB-47BE-886B-3EF9CCC3A7DE',0,1,1,0,-1,-1,-1,NULL,NULL)&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;I ran the job again and the issue was resolved .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Issue 3:&lt;/strong&gt;&lt;br /&gt;You might face a situation where the backup copy and restore jobs are running fine but still the restore is not happening and skipping the log file .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;Solution :&lt;/strong&gt;&lt;br /&gt;this is because the restore is trying to find a previous log file that you you have manually deleted :) ..&lt;br /&gt;You need to backup the database again and restore it on the standby database again (recover the standby database first or drop it )&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Please let me know if you have any queries .You can post it here or mail me at hi_abhay78@yahoo.co.in&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-4815841227911960274?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/4815841227911960274/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=4815841227911960274&amp;isPopup=true' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4815841227911960274'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4815841227911960274'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/05/how-to-automate-logshipping-setup-on.html' title='How to automate LogShipping setup On the large number of databases'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-1658360737357726837</id><published>2009-05-19T12:57:00.000+05:30</published><updated>2009-05-19T12:59:12.476+05:30</updated><title type='text'>Useful tools from Sysinternals</title><content type='html'>I was searching a tool capable of showing the Server enviornment on the desktop ..&lt;br /&gt;Well its indeed BigInfo :) .You will find it on Sysinternal site .&lt;br /&gt;Infact there are a lot of other useful tools that you can use ..or simply download the complete suit ..&lt;br /&gt;Here you go ..&lt;br /&gt;&lt;br /&gt;http://technet.microsoft.com/en-us/sysinternals/bb897557.aspx &lt;br /&gt;Enjoy (",)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-1658360737357726837?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/1658360737357726837/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=1658360737357726837&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1658360737357726837'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1658360737357726837'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/05/useful-tools-from-sysinternals.html' title='Useful tools from Sysinternals'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-4731027984194872456</id><published>2009-05-18T13:40:00.000+05:30</published><updated>2009-05-18T13:45:29.705+05:30</updated><title type='text'>How to see the SSIS packages for the Named Instance (2005/2008) of SQL Server .</title><content type='html'>-&gt; Go to C:\Program Files\Microsoft SQL Server\100\DTS\Binn [this is SQL Server 2008   but the path would be same for 2005 as well .instead of 100 it will be 90].&lt;br /&gt;-&gt; Find the file MsDtsSrvr.ini.xml and open it in notepad .&lt;br /&gt;-&gt; You will see 10-12 XML format lines .&lt;br /&gt;-&gt; By default you will see : &lt;ServerName&gt;.&lt;/ServerName&gt; &lt;br /&gt;-&gt; Remove the DOT (.) and replace it with the server name \instance name .&lt;br /&gt;-&gt; Restart the integertion service from Services console .&lt;br /&gt;&lt;br /&gt;Hope this helps .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-4731027984194872456?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/4731027984194872456/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=4731027984194872456&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4731027984194872456'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4731027984194872456'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/05/how-to-see-ssis-packages-for-named.html' title='How to see the SSIS packages for the Named Instance (2005/2008) of SQL Server .'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-4715905516060786010</id><published>2009-04-27T15:46:00.000+05:30</published><updated>2009-04-27T15:55:43.118+05:30</updated><title type='text'>Manually Add Full Text Search Resources For A SQL 2005 Failover Cluster</title><content type='html'>Reciently, I Faced this issue where the customer did not install the FT search initially and later on they came for help since it was a cluster.so I thought to share it here .Others are most welcome to Edit or Add ..&lt;br /&gt;&lt;br /&gt;-&gt; First you need to check if FT search service is installed (in case its there and someone deleted the resource from cluadmin)...if its not there in services or configuration manager , install it through the setup .&lt;br /&gt;&lt;br /&gt;-&gt;In the Cluster Administrator, right-click on 'Resources' and choose New -&gt; Resource&lt;br /&gt;&lt;br /&gt;-&gt;In the New Resource dialog, choose 'Generic Service' for the type and give it a &lt;br /&gt;name like SQL FULLTEXT. Any name is fine. Choose the desired group for the resource.&lt;br /&gt;&lt;br /&gt;-&gt;In the next screen choose the nodes that the Full-text resource can run on.These should be the same as your SQL Server resource.&lt;br /&gt;&lt;br /&gt;-&gt;In the next screen don't do anything. Full-text search doesn't need any dependencies.&lt;br /&gt;&lt;br /&gt;-&gt;In the Generic Service Parameters screen type msftesql$&lt;Instance Name&gt; in the &lt;br /&gt;'Service Name' box, where &lt;Instance Name&gt; is the Virtual Server name for the SQL &lt;br /&gt;Server. You can verify this name by opening Services.msc (Start -&gt; Run -&gt; type &lt;br /&gt;'Services.msc' -&gt; OK) and right-clicking on the SQL ServerFulltext Search service &lt;br /&gt;and choosing properities. Us the Service Name in the properties dialog as the &lt;br /&gt;Service Name in the New Resource dialog.&lt;br /&gt;&lt;br /&gt;-&gt;In the 'Startup Parameters' box, enter the parameters shown in the service &lt;br /&gt;property dialog (Start -&gt; Run -&gt; type 'Services.msc' -&gt; OK -&gt; right-click on SQL &lt;br /&gt;ServerFulltext Search service -&gt; choose 'Properties) at the end of the path in the &lt;br /&gt;'Path to executable' box. For example: -s:MSSQL.2 -f:INST2&lt;br /&gt;&lt;br /&gt;-&gt; In the next screen don't do anything. Leave the 'Registry Replication' &lt;br /&gt;information blank.&lt;br /&gt;&lt;br /&gt;-&gt; Click finish. The Full-text resource should be visible in your SQL Server group &lt;br /&gt;in the Cluster Administrator.&lt;br /&gt;&lt;br /&gt;-&gt; Test by bringing the Full-text resource online and failing it over to the other &lt;br /&gt;node.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Regards &lt;br /&gt;Abhay&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-4715905516060786010?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/4715905516060786010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=4715905516060786010&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4715905516060786010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/4715905516060786010'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/04/manually-add-full-text-search-resources.html' title='Manually Add Full Text Search Resources For A SQL 2005 Failover Cluster'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-7378524805452163133</id><published>2009-04-10T16:48:00.000+05:30</published><updated>2009-04-10T16:51:39.083+05:30</updated><title type='text'>Perfmon Counter recommended values for SQL Server 2005</title><content type='html'>Below are the perfmon counter benchmarks that I generally refer to :&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;Memory &lt;br /&gt; Available Mbytes &lt;br /&gt; &gt; 100MB &lt;br /&gt; &lt;br /&gt;Paging File &lt;br /&gt; %Usage &lt;br /&gt; &lt; 70% &lt;br /&gt; &lt;br /&gt;Process (sqlservr) &lt;br /&gt; %Privileged Time &lt;br /&gt; &lt; 30% of %Processor Time (sqlservr) &lt;br /&gt; &lt;br /&gt;Processor &lt;br /&gt; %Privileged Time &lt;br /&gt; &lt; 30% of Total %Processor Time &lt;br /&gt; &lt;br /&gt;PhysicalDisk &lt;br /&gt; Avg. Disk Sec/Read &lt;br /&gt; &lt; 8ms &lt;br /&gt; &lt;br /&gt;PhysicalDisk &lt;br /&gt; Avg. Disk sec/Write &lt;br /&gt; &lt; 8ms (non cached) &lt; 1ms (cached) &lt;br /&gt; &lt;br /&gt;SQLServer:Access Methods &lt;br /&gt; Forwarded Records/sec &lt;br /&gt; &lt; 10 per 100 Batch Requests/Sec &lt;br /&gt; &lt;br /&gt;SQLServer:Access Methods &lt;br /&gt; FreeSpace Scans/sec &lt;br /&gt; &lt;10 per 100 Batch Requests/Sec &lt;br /&gt; &lt;br /&gt;SQLServer:Access Methods &lt;br /&gt; Full Scans / sec &lt;br /&gt; (Index Searches/sec)/(Full Scans/sec) &gt; 1000 &lt;br /&gt; &lt;br /&gt;SQLServer:Access Methods &lt;br /&gt; Workfiles Created/Sec &lt;br /&gt; &lt; 20 per 100 Batch Requests/Sec &lt;br /&gt; &lt;br /&gt;SQLServer:Access Methods &lt;br /&gt; Worktables Created/Sec &lt;br /&gt; &lt; 20 per 100 Batch Requests/Sec &lt;br /&gt; &lt;br /&gt;SQL Server:Buffer Manager &lt;br /&gt; Buffer Cache hit ratio &lt;br /&gt; &gt; 90% &lt;br /&gt; &lt;br /&gt;SQL Server:Buffer Manager &lt;br /&gt; Free list stalls/sec &lt;br /&gt; &lt; 2 &lt;br /&gt; &lt;br /&gt;SQL Server:Buffer Manager &lt;br /&gt; Lazy Writes/Sec &lt;br /&gt; &lt; 20 &lt;br /&gt; &lt;br /&gt;SQL Server:Buffer Manager &lt;br /&gt; Page Life Expectancy &lt;br /&gt; &gt; 300 &lt;br /&gt; &lt;br /&gt;SQLServer:Buffer Manager &lt;br /&gt; Page lookups/sec &lt;br /&gt; (Page lookups/sec) / (Batch Requests/sec) &lt; 100 &lt;br /&gt; &lt;br /&gt;SQL Server:Locks &lt;br /&gt; Lock Requests/sec &lt;br /&gt; (Lock Request/sec)/(Batch Requests/sec) &lt; 500 &lt;br /&gt; &lt;br /&gt;SQLServer:SQL Statistics &lt;br /&gt; SQL Compilations/sec &lt;br /&gt; &lt; 10% of the number of Batch Requests/Sec &lt;br /&gt; &lt;br /&gt;SQLServer:SQL Statistics &lt;br /&gt; SQL Re-Compilations/sec &lt;br /&gt; &lt; 10% of the number of SQL Compilations&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-7378524805452163133?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/7378524805452163133/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=7378524805452163133&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/7378524805452163133'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/7378524805452163133'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/04/perfmon-counter-recommended-values-for.html' title='Perfmon Counter recommended values for SQL Server 2005'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-8048756539706139360</id><published>2009-04-10T16:32:00.001+05:30</published><updated>2009-04-10T16:35:47.663+05:30</updated><title type='text'>How to find how Cache/Bpool is being used and what objects are using the cache/Bpool ..</title><content type='html'>1: To determine what plans are in the cache and how often they're used we can use   &lt;br /&gt;   sys.dm_os_memory_cache_counters dm view .&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;SELECT  TOP 6&lt;br /&gt; LEFT([name], 20) as [name],&lt;br /&gt; LEFT([type], 20) as [type],&lt;br /&gt; [single_pages_kb] + [multi_pages_kb] AS cache_kb,&lt;br /&gt; [entries_count]&lt;br /&gt;FROM sys.dm_os_memory_cache_counters &lt;br /&gt;order by single_pages_kb + multi_pages_kb DESC&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Here :&lt;br /&gt;&lt;br /&gt;CACHESTORE_OBJCP are compiled plans for stored procedures, functions and triggers. &lt;br /&gt;&lt;br /&gt;CACHESTORE_SQLCP are cached SQL statements or batches that aren't in stored procedures, functions and triggers.This includes any dynamic SQL or raw SELECT statements sent to the server. &lt;br /&gt;&lt;br /&gt;CACHESTORE_PHDR  These are algebrizer trees for views, constraints and defaults.  An algebrizer tree is the parsed SQL text that resolves the table and column names. &lt;br /&gt;&lt;br /&gt;You will find these counters in DBCC Memorystatus as well.Infact DBCC Memory Status uses this dmv.This will give us idea about which cache is getting filled up .&lt;br /&gt;&lt;br /&gt;Generally, you will find that CACHESTORE_SQLCP &gt; CACHESTORE_OBJCP(because we cannot frame everything in to SPs) , but if the ratio of one to another is very high then we can say that there are more adhoc plans being run then Stored procedures.&lt;br /&gt;&lt;br /&gt;You can also monitor the number of data pages in the plan cache using Performance Monitor (PerfMon) using SQLServer:Plan Cache object with the Cache Pages counter.There are instances for SQL Plans (CACHESTORE_SQLCP), Object Plans (CACHESTORE_OBJCP) and Bound Trees (CACHESTORE_PHDR). This will give you the same picture ..for e.g. under bound tree : multiply cache pages by 8. you will get the same output as in dbcc memorystatus and the dm we used above.&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;2 : After this to know the querry are being cached and used , we can use &lt;br /&gt;    sys.dm_exec_cached_plans and sys.dm_exec_sql_text dm views. &lt;br /&gt;&lt;br /&gt;select  TOP 50&lt;br /&gt; objtype,&lt;br /&gt;    usecounts, &lt;br /&gt; p.size_in_bytes/1024 'IN KB',&lt;br /&gt; LEFT([sql].[text], 100) as [text]&lt;br /&gt;from sys.dm_exec_cached_plans p&lt;br /&gt;outer apply sys.dm_exec_sql_text (p.plan_handle) sql&lt;br /&gt;ORDER BY usecounts DESC&lt;br /&gt;&lt;br /&gt;and then we can check the query plans(and size) for the one we have some doubt . &lt;br /&gt;&lt;br /&gt;3: To find what tables and indexes are in the buffer memory of your server you can use sys.dm_os_buffer_descriptors DMV.The query below can give us total currrent size of buffer pool .&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;select count(*) AS Buffered_Page_Count&lt;br /&gt; ,count(*) * 8192 / (1024 * 1024) as Buffer_Pool_MB&lt;br /&gt;from sys.dm_os_buffer_descriptors&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;After we have found the Bufferpool size , we can see which database is using more memory by runnig the query below .&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;SELECT LEFT(CASE database_id &lt;br /&gt;   WHEN 32767 THEN 'ResourceDb' &lt;br /&gt;   ELSE db_name(database_id) &lt;br /&gt;        END, 20) AS Database_Name,&lt;br /&gt; count(*)AS Buffered_Page_Count, &lt;br /&gt; count(*) * 8192 / (1024 * 1024) as Buffer_Pool_MB&lt;br /&gt;FROM sys.dm_os_buffer_descriptors&lt;br /&gt;GROUP BY db_name(database_id) ,database_id&lt;br /&gt;ORDER BY Buffered_Page_Count DESC&lt;br /&gt;&lt;br /&gt;And then we can go further at object level to see what all objects are consuming memory (and how much) .We can use the query below in each database we wish to :&lt;br /&gt;&lt;br /&gt;SELECT TOP 25 &lt;br /&gt; obj.[name],&lt;br /&gt; i.[name],&lt;br /&gt; i.[type_desc],&lt;br /&gt; count(*)AS Buffered_Page_Count ,&lt;br /&gt; count(*) * 8192 / (1024 * 1024) as Buffer_MB&lt;br /&gt;    -- ,obj.name ,obj.index_id, i.[name]&lt;br /&gt;FROM sys.dm_os_buffer_descriptors AS bd &lt;br /&gt;    INNER JOIN &lt;br /&gt;    (&lt;br /&gt;        SELECT object_name(object_id) AS name &lt;br /&gt;            ,index_id ,allocation_unit_id, object_id&lt;br /&gt;        FROM sys.allocation_units AS au&lt;br /&gt;            INNER JOIN sys.partitions AS p &lt;br /&gt;                ON au.container_id = p.hobt_id &lt;br /&gt;                    AND (au.type = 1 OR au.type = 3)&lt;br /&gt;        UNION ALL&lt;br /&gt;        SELECT object_name(object_id) AS name   &lt;br /&gt;            ,index_id, allocation_unit_id, object_id&lt;br /&gt;        FROM sys.allocation_units AS au&lt;br /&gt;            INNER JOIN sys.partitions AS p &lt;br /&gt;                ON au.container_id = p.hobt_id &lt;br /&gt;                    AND au.type = 2&lt;br /&gt;    ) AS obj &lt;br /&gt;        ON bd.allocation_unit_id = obj.allocation_unit_id&lt;br /&gt;LEFT JOIN sys.indexes i on i.object_id = obj.object_id AND i.index_id = obj.index_id&lt;br /&gt;WHERE database_id = db_id()&lt;br /&gt;GROUP BY obj.name, obj.index_id , i.[name],i.[type_desc]&lt;br /&gt;ORDER BY Buffered_Page_Count DESC&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-8048756539706139360?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/8048756539706139360/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=8048756539706139360&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/8048756539706139360'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/8048756539706139360'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/04/how-to-find-how-cachebpool-is-being.html' title='How to find how Cache/Bpool is being used and what objects are using the cache/Bpool ..'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-8346351183593012728</id><published>2009-01-06T13:04:00.000+05:30</published><updated>2009-01-06T13:12:09.464+05:30</updated><title type='text'>Setting CPU Priority level for a SQL Server (high/ low)</title><content type='html'>SQL Server by default runs at priority base 7 , which is normal .&lt;br /&gt;To raise it to 13 we can use Priority boost in sp_configure .&lt;br /&gt;&lt;br /&gt;But reciently , I got a question if we can set the CPU priority to lower than normal.There is no option for this inside SQL Server.&lt;br /&gt;&lt;br /&gt;So there was in inderect answer to this : use affinity mask , so that SQL is restricted to particular CPU/CPUs .But thats not the correct answer .&lt;br /&gt;&lt;br /&gt;So is there a way to do that via task manager .Well , it has the option but we cant as we get some access denied error &lt;br /&gt; &lt;br /&gt;What you can do is :&lt;br /&gt; &lt;br /&gt;1) Open the DOS window &gt;&gt;Start /Low "&lt;Path&gt;\Binn\sqlservr.exe"&lt;br /&gt;2) This will open another window .&lt;br /&gt;3) In that new window type : "C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Binn\sqlservr.exe"[path of sqlserver executable for an instance] -sMSSQLSERVER  &lt;--instance name [copy it from the services dialog box]&lt;br /&gt;4) connect to the management studio or OSQL/ISQL.&lt;br /&gt;5) cross check in task manager .You will see that SQL Server is running under low prority &lt;br /&gt;6) Now from the task manager you can change the priority ...not sure why :) ...&lt;br /&gt;&lt;br /&gt;Hope this helps .......&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-8346351183593012728?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/8346351183593012728/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=8346351183593012728&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/8346351183593012728'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/8346351183593012728'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2009/01/setting-cpu-priority-level-for-sql.html' title='Setting CPU Priority level for a SQL Server (high/ low)'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-2077039453395419222</id><published>2008-10-14T19:16:00.000+05:30</published><updated>2008-10-14T19:32:14.603+05:30</updated><title type='text'>To wihch database does the object belongs </title><content type='html'>You know the object name but you do not know to which database does it belongs :) ..&lt;br /&gt;&lt;br /&gt;Try msforeacdb &lt;make sure you press CTRL+T in QA &gt;:&lt;br /&gt;sp_msforeachdb 'use ?;print "?";select name from sys.sysobjects where name=''&lt;object name&gt;'''&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-2077039453395419222?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/2077039453395419222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=2077039453395419222&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/2077039453395419222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/2077039453395419222'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2008/10/to-wihch-database-does-object-belongs.html' title='To wihch database does the object belongs '/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-1925807557170399834</id><published>2008-10-14T19:05:00.000+05:30</published><updated>2008-10-14T19:06:53.751+05:30</updated><title type='text'>How to detach All user databases ?</title><content type='html'>SQL 2005&lt;br /&gt;&lt;br /&gt;===========&lt;br /&gt;&lt;br /&gt;select 'EXEC sp_detach_db @dbname = N'''+RTRIM ( name)+''','''+'true''' from sys.sysdatabases where dbid&gt;6 and name not like 'distribution'&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;SQL 2000&lt;br /&gt;&lt;br /&gt;==========&lt;br /&gt;&lt;br /&gt;select 'EXEC sp_detach_db @dbname = N'''+RTRIM ( name)+''','''+'true''' from sysdatabases where dbid&gt;4  and name not like 'distribution'&lt;br /&gt;&lt;br /&gt;hozzzaaat ..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-1925807557170399834?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/1925807557170399834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=1925807557170399834&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1925807557170399834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1925807557170399834'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2008/10/how-to-detach-all-user-databases.html' title='How to detach All user databases ?'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-6594874786207170218</id><published>2008-06-24T11:03:00.000+05:30</published><updated>2008-06-24T11:55:34.667+05:30</updated><title type='text'>ERROR 229: The EXECUTE permission was denied on the object 'xp_cmdshell', database 'mssqlsystemresource', schema 'sys'</title><content type='html'>I once got this error while experimenting :&lt;br /&gt;&lt;br /&gt;ERROR 229: The EXECUTE permission was denied on the object 'xp_cmdshell', database 'mssqlsystemresource', schema 'sys'.&lt;br /&gt;&lt;br /&gt;So seems like xp_cmdshell is an object in database 'mssqlsystemresource' and schema 'sys'. mssqlsystemresource cannot be accessed without DAC ...&lt;br /&gt;&lt;br /&gt;In the first go I could not understand much ..But then i tried to run the same query ( it was a BCP query ) using the windows domain account it was successful ..&lt;br /&gt;&lt;br /&gt;So it was clear that this is a permission issue on the sql login that I was using ..&lt;br /&gt;Then after long time searching BOL i found that we need to set the database trustworthy .&lt;br /&gt;&lt;br /&gt;ALTER DATABASE mydb SET TRUSTWORTHY ON ...and we were comfortable ..&lt;br /&gt;&lt;br /&gt;The other way is to create the xp_cmdshell proxy account to impersonate the non-sysadmin users to allow them to access resources outside the SQL Server.&lt;br /&gt;&lt;br /&gt;sp_xp_cmdshell_proxy_account [ NULL | { 'account_name' , 'password' } ]&lt;br /&gt;&lt;br /&gt;otherwise you can also use the GUI ..&lt;br /&gt;&lt;br /&gt;Hope this helps ..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-6594874786207170218?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/6594874786207170218/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=6594874786207170218&amp;isPopup=true' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/6594874786207170218'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/6594874786207170218'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2008/06/error-229-execute-permission-was-denied.html' title='ERROR 229: The EXECUTE permission was denied on the object &apos;xp_cmdshell&apos;, database &apos;mssqlsystemresource&apos;, schema &apos;sys&apos;'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-1559148286278156577</id><published>2008-06-24T11:00:00.000+05:30</published><updated>2008-06-24T11:03:05.807+05:30</updated><title type='text'>Script that will help in Identifying query causing TempDB growth</title><content type='html'>I am not creating any indexes assuming we know how to create them &lt;br /&gt;&lt;br /&gt;CREATE TABLE [dbo].[tempUsage](&lt;br /&gt;&lt;br /&gt;      [Date_Time] [datetime] NOT NULL,&lt;br /&gt;&lt;br /&gt;      [session_id] [smallint] NULL,&lt;br /&gt;&lt;br /&gt;      [sql_handle] [varbinary](64) NULL,&lt;br /&gt;&lt;br /&gt;      [SQL_Text] [varchar](8000) NULL,&lt;br /&gt;&lt;br /&gt;      [request_internal_objects_alloc_page_count] [bigint] NULL,&lt;br /&gt;&lt;br /&gt;      [request_internal_objects_dealloc_page_count] [bigint] NULL&lt;br /&gt;&lt;br /&gt;) ON [PRIMARY]&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;CREATE VIEW all_request_usage&lt;br /&gt;&lt;br /&gt;AS &lt;br /&gt;&lt;br /&gt;  SELECT session_id, request_id, &lt;br /&gt;&lt;br /&gt;      SUM(internal_objects_alloc_page_count) AS request_internal_objects_alloc_page_count,&lt;br /&gt;&lt;br /&gt;      SUM(internal_objects_dealloc_page_count)AS request_internal_objects_dealloc_page_count &lt;br /&gt;&lt;br /&gt;  FROM sys.dm_db_task_space_usage &lt;br /&gt;&lt;br /&gt;  GROUP BY session_id, request_id;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;CREATE VIEW all_query_usage&lt;br /&gt;&lt;br /&gt;AS&lt;br /&gt;&lt;br /&gt;  SELECT R1.session_id, R1.request_id, &lt;br /&gt;&lt;br /&gt;      R1.request_internal_objects_alloc_page_count, R1.request_internal_objects_dealloc_page_count,&lt;br /&gt;&lt;br /&gt;      R2.sql_handle, R2.statement_start_offset, R2.statement_end_offset, R2.plan_handle&lt;br /&gt;&lt;br /&gt;  FROM all_request_usage R1&lt;br /&gt;&lt;br /&gt;  INNER JOIN sys.dm_exec_requests R2 ON R1.session_id = R2.session_id and R1.request_id = R2.request_id;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Let’s run  the statement every minute to capture SQL Statement that is causing TempDB growth.&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;INSERT INTO tempUsage&lt;br /&gt;&lt;br /&gt;SELECT &lt;br /&gt;&lt;br /&gt;      GetDate() As Date_Time,&lt;br /&gt;&lt;br /&gt;      R1.session_id, &lt;br /&gt;&lt;br /&gt;      R1.sql_handle, &lt;br /&gt;&lt;br /&gt;      Cast ( R2.text As Varchar(8000)) SQL_Text,&lt;br /&gt;&lt;br /&gt;      R1.request_internal_objects_alloc_page_count,&lt;br /&gt;&lt;br /&gt;      R1.request_internal_objects_dealloc_page_count&lt;br /&gt;&lt;br /&gt;FROM all_query_usage AS R1&lt;br /&gt;&lt;br /&gt;OUTER APPLY sys.dm_exec_sql_text(R1.sql_handle) AS R2&lt;br /&gt;&lt;br /&gt;where R1.request_internal_objects_alloc_page_count &lt;&gt; 0;&lt;br /&gt;&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-1559148286278156577?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/1559148286278156577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=1559148286278156577&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1559148286278156577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1559148286278156577'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2008/06/script-that-will-help-in-identifying.html' title='Script that will help in Identifying query causing TempDB growth'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-649408762486382346</id><published>2008-06-12T20:29:00.000+05:30</published><updated>2008-06-12T20:36:25.736+05:30</updated><title type='text'>Installing Replication bits on a cluster after upgrading to SP2</title><content type='html'>Reciently we faced an issue where SQL Server was on SP2 ( clustered Enviornment) and we were not able to install replication ..This is fairly simple on a standalone machine but not on cluster ..&lt;br /&gt;&lt;br /&gt;If you try to achieve it through ADD/Remove (appwiz.cpl) program you may get this error : &lt;strong&gt;The Installer has encountered an unexpected error. The Error code is 2819 .ControlProductclash1 on dialog Product clash needs a property linked to it .&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The solution is to use the commandline setup ..we tried several combinations untill this was successful :&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;start /wait setup.exe /qb VS=TSQL31 INSTANCENAME=TSQL31 ADDLOCAL=SQL_Replication&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now , Replication is installed but its on RTM :) ...you still need to apply SP2 ..&lt;br /&gt;Moreover , any CU after SP2 will fail as Replication bits are on RTM ...&lt;br /&gt;&lt;br /&gt;use the same command with hotfix name instead of &lt;strong&gt; setup.exe &lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-649408762486382346?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/649408762486382346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=649408762486382346&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/649408762486382346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/649408762486382346'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2008/06/installing-replication-bits-on-cluster.html' title='Installing Replication bits on a cluster after upgrading to SP2'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-2499167983843889600</id><published>2008-06-12T20:20:00.000+05:30</published><updated>2008-06-12T20:26:08.878+05:30</updated><title type='text'>Can we detach the databses with Replication ON ..</title><content type='html'>The answer is no ........we cannot detach the database which is participating in replicaion ..&lt;br /&gt;&lt;br /&gt;Consider a scenario where you have hundereds of databases replicated and you fall short of disk :D ...&lt;br /&gt;&lt;br /&gt;Disabling/removing Replication will be costly and time consuming ...&lt;br /&gt;But we can follow the simple steps below and everything will be fine ...&lt;br /&gt;&lt;br /&gt;1.Run ALTER DATABASE database_name SET OFFLINE.&lt;br /&gt;2.Move the file to the new location.&lt;br /&gt;3.Run ALTER DATABASE database_name MODIFY FILE ( NAME = logical_name, FILENAME = 'new_path/os_file_name'.&lt;br /&gt;4.            Run ALTER DATABASE database_name SET ONLINE.&lt;br /&gt;&lt;br /&gt;Trust me ...you are done :) ..&lt;br /&gt;&lt;br /&gt;Comments are welcome as always ..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-2499167983843889600?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/2499167983843889600/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=2499167983843889600&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/2499167983843889600'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/2499167983843889600'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2008/06/can-we-detach-databses-with-replication.html' title='Can we detach the databses with Replication ON ..'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-7856058072526638009</id><published>2008-02-17T03:08:00.000+05:30</published><updated>2008-02-17T07:54:29.493+05:30</updated><title type='text'>Understanding Memory issues through Perfmon:Page faults</title><content type='html'>I have been using Perfmon almost daily, but never took pain to learn how to use it efficiently until I came across a situation …In this part we will discuss using perfmon to see memory bottleneck.&lt;br /&gt;Before we proceed forward let us go through few definitions so that the rest of the stuff is easily understood.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Virtual memory&lt;/strong&gt;: Its actually virtual …and from here the concept of paging comes in to picture .On a 32 bit machine its 2 gigs for user process by default ….So, if your RAM is 512 MB, the remaining stuff (I mean greater that 512 MB) that’s going to come from Virtual memory will page out to disk .SO operations worth 2 gigs will happen in VAS (VM) and as a storage RAM will be used and the moment RAM limit is exceeded …..Paging/Swapping .&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Page&lt;/strong&gt;: Committed data in VAS is written to Page tables .From there it goes to RAM or Pagefile .This data is written in to pages (in bytes) and its size is processor dependent. this page is fitted in to page frame in RAM…it is essential that , that frame must be filled with zeros before a page from disk is inserted into page frame .zeroing is essential as the page before zeroing may have information from any other process ..So when we restart Windows this zeroing activity takes place and complete by the virtual memory manager before the Windows comes up..And if there is some problem during zeroing then………….. :D …we will discuss some other time …&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Page file&lt;/strong&gt;: a space in the HDD to be used to save committed memory objects.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Reserved memory&lt;/strong&gt;: the memory quota given to a process by the VM manager .So the process first has to consume this before the next quota is allocated …&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Committed memory&lt;/strong&gt;: The chunk from reserved memory that is actually being used by the process. Remember that whenever memory is committed the same amount of space is created on the pagefile so that if needed it can be flushed to disk.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Working Set&lt;/strong&gt;: Physical memory assigned to a process by VM manager (or say OS).It will be always less than &lt;strong&gt;Private Bytes&lt;/strong&gt;. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Page Fault &lt;/strong&gt;: When the page needed is not found in the working set of the process but its with in the RAM (may be in some cache) its called as Soft page fault .But when the page is not at all found in the RAM , its paged out and called as Hard page fault.&lt;br /&gt;&lt;br /&gt;So now, it’s sure that whenever there is a memory issue there will be high (hard) Page fault rate...If there is a constant high hard page fault rate it means that there is some data not found in the RAM for the working set of that process .So , it has to be fetched from the disk (which is going to be costly).And the hard page faults cause Paging .So is paging harmful ….No (we cannot avoid it ), but the excess of it is a signal that something is going wrong .Generally I have seen that keeping the page file to be equal to 1.5 times of RAM is ok ..Not bad.&lt;br /&gt;&lt;br /&gt;In case of memory issue the counters that we need to see in Perfmon are &lt;strong&gt;Memory&lt;/strong&gt; and &lt;strong&gt;Process&lt;/strong&gt;...&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The Sub counters for memory counter are&lt;/strong&gt;: Page Faults/sec, Page Reads/sec, Page Writes/sec, Pages Input/sec, Pages Output/sec, Available bytes and nonpaged pool bytes.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The Sub counters for Process counter are&lt;/strong&gt;: Page Faults/sec, working set, Private Bytes and Page File Bytes&lt;br /&gt;&lt;br /&gt;So, % Soft page faults = ((Page fault/sec - Pages input/sec) x 100)/Page faults/sec&lt;br /&gt;&lt;br /&gt;Now, if there are more hard page faults, there should be more pages output/sec (no of pages sent to disk to make room for the pages coming form disk due to hard page fault) since there is a limited working set and hence there has to be some space for the pages coming from the disk (hard page faults) ...Pages read/sec and pages input/sec should be almost similar but can be a bit different …So these counters can tell you the system story..One more counter that I forgot to mention is Available Bytes .Its the no. of bytes left for the process to allocate. To see how much SQL Server shares you can see Page Faults/sec and proportionate it with Total Page faults. Generally, hard page fault of 10% to 15% should be tolerated …Before, we totally blame memory let’s check the Disk performance as well...&lt;br /&gt;&lt;br /&gt;Subtract &lt;strong&gt;Memory&lt;/strong&gt;:Page reads/sec from &lt;strong&gt;logical disk&lt;/strong&gt;:disk reads/sec .If the output is small (+ or -) then the memory is the bottleneck because this actually means that all the disk reading is done to find the faulting pages .Also if disk output/sec is high then you can check by finding the difference of disk output/sec and Disk write bytes/sec ÷ 4096 ßintel and fine its percentage in total Disk write bytes/sec&lt;br /&gt;&lt;br /&gt;Similarly, you can then correlate it to SQL Server as well …..Once you are sure that memory is the bottleneck then we can proceed with the troubleshooting steps...&lt;br /&gt;Next time we will try to dig into memory issues including memory leaks and also perfmon counters specific to SQL Server …&lt;br /&gt;&lt;br /&gt;As always, your comments are welcome...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-7856058072526638009?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/7856058072526638009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=7856058072526638009&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/7856058072526638009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/7856058072526638009'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2008/02/understanding-memory-issues-through.html' title='Understanding Memory issues through Perfmon:Page faults'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-1169365111928374518</id><published>2008-02-13T06:30:00.000+05:30</published><updated>2008-02-17T08:04:19.459+05:30</updated><title type='text'>Shall We use /PAE and /3GB switches together ..my views</title><content type='html'>&lt;span style="font-family:verdana;font-size:85%;"&gt;Physical Address Extension (PAE) refers to a feature of x86 and x86-64 processors that allows the OS to see more than regular 4 gigs of physical RAM on a 32-bit machine.To do that we need to specify /PAE switch in the boot.ini file and reboot the machine so that this setting takes effect.&lt;br /&gt;&lt;br /&gt;So when you enable PAE ,the physical address size is increased from 32 bits to 36 bits which is equal to 64 GB. Note that the 32-bit size of virtual address is never changed, and it remains 4 GB.The OS uses PTE ( Page Table Entries) to map this 4 GB address space onto the 64 GB of total memory.Now any APP which needs access to more than 4 GiB of memory,has to have some special mechanism and on MS Windows this mechanism is called Address Windowing Extensions (AWE), while on Unix-like systems a variety of tricks are used, such as using mmap() to map regions of a file into and out of the address space as neededbut not yet adopted as a standard.&lt;br /&gt;&lt;br /&gt;AWE is an MS API that allows the apps to access more physical memory than available in VAS ..The  process through which it maps the VAS to physical memory is called as Windowing ...Not all the applications are AWE enabled ..but SQL Server is ..However , for doing that we need to have the locked pages in memory privilege enabled .One more benefit of using AWE in SQL Server is that the memory being allocated using AWE will not be written in Page files ..So,AWE can prevent Windows from swapping sensitive data from RAM to pagefile.&lt;br /&gt;&lt;br /&gt;Now , I am pretty sure that we all know /3GB setting but just wanted to convey that with this setting the physical memory limit on Windows Server 2003 is 16 GB only ..So even if you have more than 16GB RAM you cannot see/use it :D...thats because it trims the PTE table rows ..&lt;br /&gt;&lt;br /&gt;Now comes the real question ....Should we use /PAE and /3GB switch together .....well one negative factor i have already mentioned above. Secondly just for 1 GB I dont feel it would be worth .....Its set on my machine and i have no issues :)..&lt;br /&gt;&lt;br /&gt;However , I have seen a few cases where these 2 combinations creates situations like Blue screen or black screen on machine upon boot up .....that is something because the OS goes for a toss while going through ZEROING activity ..But i think this stuff still needs some good research ...So, I do not say dont use it , but surely test it first .&lt;br /&gt;&lt;br /&gt;So , summary is that I am not totally against it but i wont prefer it ....&lt;br /&gt;Your choice :D .......&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-1169365111928374518?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/1169365111928374518/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=1169365111928374518&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1169365111928374518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/1169365111928374518'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2008/02/shall-we-use-pae-and-3gb-switches.html' title='Shall We use /PAE and /3GB switches together ..my views'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-3696492786521088640</id><published>2008-02-12T06:55:00.000+05:30</published><updated>2008-02-12T07:00:01.218+05:30</updated><title type='text'>What all objects are consuming memory (and how much)</title><content type='html'>To determine what plans are in the cache and how often they're used we can use sys.dm_os_memory_cache_counters dm view .&lt;br /&gt;&lt;br /&gt;SELECT  TOP 6 LEFT([name], 20) as [name], LEFT([type], 20) as [type], [single_pages_kb] + [multi_pages_kb] AS cache_kb, [entries_count]FROM sys.dm_os_memory_cache_counters order by single_pages_kb + multi_pages_kb DESC&lt;br /&gt;&lt;br /&gt;here :&lt;br /&gt;CACHESTORE_OBJCP are compiled plans for stored procedures, functions and triggers. CACHESTORE_SQLCP are cached SQL statements or batches that aren't in stored procedures, functions and triggers.  This includes any dynamic SQL or raw SELECT statements sent to the server. CACHESTORE_PHDR  These are algebrizer trees for views, constraints and defaults.  An algebrizer tree is the parsed SQL text that resolves the table and column names.&lt;br /&gt;(you will find these counters in DBCC Memorystatus as well.Infact DBCC Memory Status uses this dm)&lt;br /&gt;&lt;br /&gt;Generally you will find that CACHESTORE_SQLCP &gt; CACHESTORE_OBJCP , but if the ratio of one to another is very high then we can say that there are more adhoc plans being run then Stored procedures.That is the reason the sal statements are going in to  Plan cache.&lt;br /&gt;You can also monitor the number of data pages in the plan cache using Performance Monitor (PerfMon) using SQLServer:Plan Cache object with the Cache Pages counter.  There are instances for SQL Plans (CACHESTORE_SQLCP), Object Plans (CACHESTORE_OBJCP) and Bound Trees (CACHESTORE_PHDR). This will give you the same picture ..for e.g. under bound tree : multiply cache pages by 8. you will get the same output as in dbcc memorystatus and the dm we used above.&lt;br /&gt;&lt;br /&gt;After this we can use sys.dm_exec_cached_plans and sys.dm_exec_sql_text dm views to find the queries :&lt;br /&gt;select  TOP 100 objtype,    usecounts,  p.size_in_bytes/1024 'IN KB', LEFT([sql].[text], 100) as [text]from sys.dm_exec_cached_plans pouter apply sys.dm_exec_sql_text (p.plan_handle) sqlORDER BY usecounts DESC&lt;br /&gt;&lt;br /&gt;And then we can check the query plans(and size) for the one we have some doubt .&lt;br /&gt;&lt;br /&gt;Now , SQL Server memory is primarily used to store data (buffer) and query plans (cache). We will try to find what tables and indexes are in the buffer memory of your server you can use sys.dm_os_buffer_descriptors DMV.Further , the query below can give us total currrent size of buffer pool .&lt;br /&gt;&lt;br /&gt;select count(*) AS Buffered_Page_Count ,count(*) * 8192 / (1024 * 1024) as Buffer_Pool_MBfrom sys.dm_os_buffer_descriptors&lt;br /&gt;&lt;br /&gt;After we have found the Bufferpool size , we can see which database is using more memory by runnig the query below :&lt;br /&gt;&lt;br /&gt;SELECT LEFT(CASE database_id    WHEN 32767 THEN 'ResourceDb'    ELSE db_name(database_id)         END, 20) AS Database_Name, count(*)AS Buffered_Page_Count,  count(*) * 8192 / (1024 * 1024) as Buffer_Pool_MBFROM sys.dm_os_buffer_descriptorsGROUP BY db_name(database_id) ,database_idORDER BY Buffered_Page_Count DESC&lt;br /&gt;&lt;br /&gt;And then we can go further at object level to see what all objects are consuming memory (and how much) .We can use the query below in each database we wish to :&lt;br /&gt;&lt;br /&gt;SELECT TOP 25  obj.[name], i.[name], i.[type_desc], count(*)AS Buffered_Page_Count , count(*) * 8192 / (1024 * 1024) as Buffer_MB    -- ,obj.name ,obj.index_id, i.[name]FROM sys.dm_os_buffer_descriptors AS bd     INNER JOIN     (        SELECT object_name(object_id) AS name             ,index_id ,allocation_unit_id, object_id        FROM sys.allocation_units AS au            INNER JOIN sys.partitions AS p                 ON au.container_id = p.hobt_id                     AND (au.type = 1 OR au.type = 3)        UNION ALL        SELECT object_name(object_id) AS name               ,index_id, allocation_unit_id, object_id        FROM sys.allocation_units AS au            INNER JOIN sys.partitions AS p                 ON au.container_id = p.hobt_id                     AND au.type = 2    ) AS obj         ON bd.allocation_unit_id = obj.allocation_unit_idLEFT JOIN sys.indexes i on i.object_id = obj.object_id AND i.index_id = obj.index_idWHERE database_id = db_id()GROUP BY obj.name, obj.index_id , i.[name],i.[type_desc]ORDER BY Buffered_Page_Count DESC&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-3696492786521088640?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/3696492786521088640/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=3696492786521088640&amp;isPopup=true' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/3696492786521088640'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/3696492786521088640'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2008/02/what-all-objects-are-consuming-memory.html' title='What all objects are consuming memory (and how much)'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-5265859461951922705</id><published>2008-02-12T06:14:00.000+05:30</published><updated>2008-02-12T06:15:49.332+05:30</updated><title type='text'>Auto Parameterization in SQL Server</title><content type='html'>Let us look at how and when SQL Server can parameterize dynamic SQL to reuse the query plan.Its through Parsing and compiling that the query plans get in to memory and then may or may not be reused.&lt;br /&gt;&lt;br /&gt;Before executing a batch of SQL statements, SQL Server creates an execution plan (or query plan) for those statements.  This is also referred to as compiling the SQL statements.  One of the benefits of stored procedures is that SQL Serve will reuse compiled query plans.&lt;br /&gt;&lt;br /&gt;Here is the example :&lt;br /&gt;DBCC FREEPROCCACHEGO&lt;br /&gt;set showplan_all on&lt;br /&gt;SELECT *FROM Sales.SalesOrderHeaderWHERE SalesOrderID = 56000GO&lt;br /&gt;select  stats.execution_count AS exec_count,  p.size_in_bytes as [size],  [sql].[text] as [plan_text]from sys.dm_exec_cached_plans pouter apply sys.dm_exec_sql_text (p.plan_handle) sqljoin sys.dm_exec_query_stats stats ON stats.plan_handle = p.plan_handleGO&lt;br /&gt;&lt;br /&gt;Using the above mentioned DMV's we can find the number of times this plan has been executed, how big the plan is in bytes and the text of the plan.&lt;br /&gt;&lt;br /&gt;Notice that the integer 56000 has been replaced by a variable ([@1])in the text of the query plan.  Also notice that the list of parameters (only one parameter in this case) has been inserted at the beginning of the query plan.  This is called "Simple Parameterization" (It was called "Auto Parameterization" in SQL Server 2000).  If we run it twice we'd see the execution count increase to two but there would still only be a single plan.&lt;br /&gt;SQL Server can also parameterize queries if they aren't identical.&lt;br /&gt;&lt;br /&gt;lets check this :&lt;br /&gt;&lt;br /&gt;DBCC FREEPROCCACHEGO&lt;br /&gt;SELECT *FROM Sales.SalesOrderHeaderWHERE SalesOrderID = 56000GO&lt;br /&gt;SELECT * FROM Sales.SalesOrderHeader WHERE SalesOrderID = 56001GO&lt;br /&gt;select *from Sales.SalesOrderHeaderwhere SalesOrderID = 56002GO&lt;br /&gt;select  stats.execution_count AS exec_count,  p.size_in_bytes as [size],  [sql].[text] as [plan_text]from sys.dm_exec_cached_plans pouter apply sys.dm_exec_sql_text (p.plan_handle) sqljoin sys.dm_exec_query_stats stats ON stats.plan_handle = p.plan_handleGO&lt;br /&gt;&lt;br /&gt;Now let's look at something different.&lt;br /&gt;&lt;br /&gt;DBCC FREEPROCCACHEGO&lt;br /&gt;SELECT *FROM Sales.SalesOrderHeaderWHERE SalesOrderID = 56000GO&lt;br /&gt;SELECT * FROM AdventureWorks.Sales.SalesOrderHeader WHERE SalesOrderID = 56001GO&lt;br /&gt;declare @i intset @i = 56004SELECT *FROM Sales.SalesOrderHeaderWHERE SalesOrderID = @iGO&lt;br /&gt;select  stats.execution_count AS exec_count,  p.size_in_bytes as [size],  [sql].[text] as [plan_text]from sys.dm_exec_cached_plans pouter apply sys.dm_exec_sql_text (p.plan_handle) sqljoin sys.dm_exec_query_stats stats ON stats.plan_handle = p.plan_handleGO&lt;br /&gt;&lt;br /&gt;So,even slight changes in the text of the plan prevent SQL Server from reusing the query plans.If you want SQL Server to parameterize your SQL statements you have three options: stored procedures, sp_executesql or Forced Parameterization.  Stored procedures almost always have a query plan created and reused.&lt;br /&gt;Lets try without sp_executesql first&lt;br /&gt;---------------------------------------------&lt;br /&gt;DBCC FREEPROCCACHEGO&lt;br /&gt;SELECT  SUM(LineTotal) AS LineTotalFROM Sales.SalesOrderHeader HJOIN Sales.SalesOrderDetail D ON D.SalesOrderID = H.SalesOrderIDWHERE H.SalesOrderID = 56000GO&lt;br /&gt;SELECT  SUM(LineTotal) AS LineTotalFROM Sales.SalesOrderHeader HJOIN Sales.SalesOrderDetail D ON D.SalesOrderID = H.SalesOrderIDWHERE H.SalesOrderID = 56001GO&lt;br /&gt;select  stats.execution_count AS exec_count,  p.size_in_bytes as [size],  LEFT([sql].[text], 80) as [plan_text]from sys.dm_exec_cached_plans pouter apply sys.dm_exec_sql_text (p.plan_handle) sqljoin sys.dm_exec_query_stats stats ON stats.plan_handle = p.plan_handleGO&lt;br /&gt;&lt;br /&gt;Now we will use sp_executesql&lt;br /&gt;------------------------------------------&lt;br /&gt;Now we will use sp_executesql .&lt;br /&gt;DBCC FREEPROCCACHEGO&lt;br /&gt;EXEC sp_executesql N'SELECT  SUM(LineTotal) AS LineTotalFROM Sales.SalesOrderHeader HJOIN Sales.SalesOrderDetail D ON D.SalesOrderID = H.SalesOrderIDWHERE H.SalesOrderID = @SalesOrderID', &lt;a href="http://in.f87.mail.yahoo.com/ym/Compose?To=N" target="_blank" rel="nofollow" ymailto="mailto:N'@SalesOrderID"&gt;N'@SalesOrderID&lt;/a&gt; INT', 56000GO&lt;br /&gt;EXEC sp_executesql N'SELECT  SUM(LineTotal) AS LineTotalFROM Sales.SalesOrderHeader HJOIN Sales.SalesOrderDetail D ON D.SalesOrderID = H.SalesOrderIDWHERE H.SalesOrderID = @SalesOrderID', &lt;a href="http://in.f87.mail.yahoo.com/ym/Compose?To=N" target="_blank" rel="nofollow" ymailto="mailto:N'@SalesOrderID"&gt;N'@SalesOrderID&lt;/a&gt; INT', 56005GO&lt;br /&gt;select  stats.execution_count AS exec_count,  LEFT([sql].[text], 80) as [plan_text]from sys.dm_exec_cached_plans pouter apply sys.dm_exec_sql_text (p.plan_handle) sqljoin sys.dm_exec_query_stats stats ON stats.plan_handle = p.plan_handleGO&lt;br /&gt;See the difference :D&lt;br /&gt;You can set the parameterization at databse level by :&lt;br /&gt;ALTER DATABASE adventureworks set PARAMETERIZATION SIMPLE.&lt;br /&gt;&lt;br /&gt;Awaiting your comments :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8436612531636428647-5265859461951922705?l=ms-abhay.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ms-abhay.blogspot.com/feeds/5265859461951922705/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8436612531636428647&amp;postID=5265859461951922705&amp;isPopup=true' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5265859461951922705'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8436612531636428647/posts/default/5265859461951922705'/><link rel='alternate' type='text/html' href='http://ms-abhay.blogspot.com/2008/02/auto-parameterization-in-sql-server.html' title='Auto Parameterization in SQL Server'/><author><name>Abhay</name><uri>http://www.blogger.com/profile/01331184161430889120</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://bp0.blogger.com/_SqLnRbOtgHE/R6zEBz6vn5I/AAAAAAAAAD8/KkPvkvlrP-I/S220/untitled.bmp'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8436612531636428647.post-14293694943669767</id><published>2008-02-12T05:05:00.000+05:30</published><updated>2008-02-12T06:01:46.698+05:30</updated><title type='text'>Cannot open user default database. Login failed.</title><content type='html'>Well , there can be many different scenarios but I am pretty sure those will be simple to drill down ...&lt;br /&gt;&lt;br /&gt;In my case the user had a group and there were 6 users in that group&lt;br /&gt;The user created a login for that group in SQL Server and whenever the users wer etrying to login through SSMS they were getting the error below :&lt;br /&gt;&lt;br /&gt;Msg 4064, Level 11, State 1, Server ServerName, Line 1&lt;br /&gt;Cannot open user default database. Login failed.&lt;br /&gt;&lt;br /&gt;out of 6 users only 4 were having this problem .So we changed the default database for the login to master.It still gives the same error.Then we then created a new login for one of the users from that group seperately and its default database was set to master .we logged in using that login  successfully .that ws strange.We then deleted that login and again tried to login again via SSMS using same login thta we deleted .Ideally it should have given us an error something like "login failed for the user ....18456" but It was still giving us the same error .&lt;br /&gt;                Cannot open user default database. 
