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

<channel>
	<title>Vicky Harp</title>
	<atom:link href="http://vickyharp.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://vickyharp.com</link>
	<description>A SQL Server developer living the multi-threaded life</description>
	<lastBuildDate>Tue, 09 Jan 2018 18:14:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.5.3</generator>
<site xmlns="com-wordpress:feed-additions:1">32767945</site>	<item>
		<title>SSWUG SQL 2016 Temporal Tables Presentation</title>
		<link>https://vickyharp.com/2016/04/sswug-sql-2016-temporal-tables-presentation/</link>
					<comments>https://vickyharp.com/2016/04/sswug-sql-2016-temporal-tables-presentation/#respond</comments>
		
		<dc:creator><![CDATA[Vicky]]></dc:creator>
		<pubDate>Fri, 29 Apr 2016 16:44:15 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[Speaking Events]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SSWUG]]></category>
		<category><![CDATA[Temporal Tables]]></category>
		<guid isPermaLink="false">http://vickyharp.wpengine.com/?p=490</guid>

					<description><![CDATA[I had the pleasure of presenting at the SSWUG Spring 2016 Virtual Conference today on the topic of SQL 2016 Temporal Tables. Thank you to all who attended! Here are the slides and demo scripts for that presentation.]]></description>
										<content:encoded><![CDATA[<p>I had the pleasure of presenting at the <a href="http://www.sswug.org" target="_blank">SSWUG </a>Spring 2016 Virtual Conference today on the topic of SQL 2016 Temporal Tables. Thank you to all who attended! <a href="http://vickyharp.wpengine.com/wp-content/uploads/2016/04/SSWUG-Temporal-Tables-Demos.zip">Here </a>are the slides and demo scripts for that presentation.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vickyharp.com/2016/04/sswug-sql-2016-temporal-tables-presentation/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">490</post-id>	</item>
		<item>
		<title>Tomato, Tomato &#8211; Assumptions about Regionalization</title>
		<link>https://vickyharp.com/2014/07/tomato-tomato-assumptions-about-regionalization/</link>
					<comments>https://vickyharp.com/2014/07/tomato-tomato-assumptions-about-regionalization/#respond</comments>
		
		<dc:creator><![CDATA[Vicky]]></dc:creator>
		<pubDate>Wed, 09 Jul 2014 00:18:00 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Edge Cases]]></category>
		<category><![CDATA[QA]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[T-SQL]]></category>
		<guid isPermaLink="false">http://vickyharp.wpengine.com/?p=466</guid>

					<description><![CDATA[This month&#8217;s TSQL Tuesday prompt is on the topic of assumptions. I&#8217;d like to take a brief moment and talk about one of the more insidious and pervasive sources of bugs in TSQL application code I&#8217;ve seen over the years. Let&#8217;s say I present you with a date: 08/12/2014 Quick! What month am I talking about?&#160; <a href="https://vickyharp.com/2014/07/tomato-tomato-assumptions-about-regionalization/" title="Read more Tomato, Tomato &#8211; Assumptions about Regionalization">Read more &#187;</a>]]></description>
										<content:encoded><![CDATA[<p><a href="http://devnambi.com/2014/tsql-tuesday-summary/"><img loading="lazy" class=" alignleft" alt="" src="https://i0.wp.com/devnambi.com/images/TSQL2sDay150x150.jpg?resize=150%2C150" width="150" height="150" data-recalc-dims="1" /></a></p>
<p>This month&#8217;s <a href="http://devnambi.com/2014/tsql-tuesday-summary/" target="_blank">TSQL Tuesday prompt</a> is on the topic of assumptions. I&#8217;d like to take a brief moment and talk about one of the more insidious and pervasive sources of bugs in TSQL application code I&#8217;ve seen over the years.</p>
<p>Let&#8217;s say I present you with a date: 08/12/2014</p>
<p>Quick! What month am I talking about?</p>
<p>If you answered August 12, 2014, you might be correct. If you answered December 8, 2014, you might also be correct. If you sneakily answered &#8220;It depends!&#8221; then, well, you&#8217;ve picked up on where I am going with this.</p>
<p>I very frequently see coders assuming that their local timezone, region, collation, and language are somehow universal, leading to coding practices which limit the geographical reach of their software. Here are some of the most common things which I see overlooked:</p>
<ul>
<li><strong>Regional date format</strong> &#8211; Keep in mind that mm/dd/yyyy and dd/mm/yyyy cannot be easily distinguished until the 13th of any given month. Usage varies <a href="http://en.wikipedia.org/wiki/Date_format_by_country" target="_blank">around the world</a> and even within countries. Use yyyymmdd instead!</li>
<li><strong>Regional number formatting</strong> &#8211; Though this a larger problem in app code than in TSQL code, you still see the issue sometimes. A decimal may be represented as 3.14 or 3,14 depending on local settings. There are <a href="http://en.wikipedia.org/wiki/Decimal_mark#Examples_of_use" target="_blank">more variations</a> than you might expect.</li>
<li><strong>Time zones</strong> &#8211; You would hope it could go without saying that not all users will necessarily be located in the same time zone, but applications have issues with this all the time. Time zones are also not static and are affected by Daylight Savings Time windows which can shift or be cancelled outright. Storing data in UTC time and applying offsets in the presentation layer can usually solve this problem. And don&#8217;t forget &#8211; <a href="http://www.timeanddate.com/library/abbreviations/timezones/na/nst.html" target="_blank">not all time zones</a> are on even hour boundaries!</li>
<li><strong>Collation settings</strong> &#8211; Honestly, the thing I see the most often is the assumption of a case insensitive collation. This problem bit me so many times in my early days working on SQL Diagnostic Manager that I switched my entire development environment to case sensitive many years ago. I also put Korean, Russian, Japanese, and Binary collations into my test environments. It&#8217;s better to write your code to handle these issues early on than to play whack-a-mole with collation conflict errors later on.</li>
</ul>
<p>You may feel safe with these assumptions in quick little scripts now and then, but remember, the moment you put a script up on your blog, it has gone out to an international audience who may have different settings from you. You may think to yourself that all of your company&#8217;s servers are located two floors away and are all of the same predictable region, collation, and language settings &#8211; but then you attend a quarterly kick of meeting and find out you&#8217;ve merged with a company on another continent and, by the way, you&#8217;re now responsible for their servers too!</p>
<p>Save yourself some heartache and add a nice sparkle of professionalism to your code by writing it to be region and language agnostic. You&#8217;ll be a better coder for it.</p>
<p><strong>Edit:</strong> Special thanks to Rob Farley (<a href="http://sqlblog.com/blogs/rob_farley/" target="_blank">b</a> | <a href="https://twitter.com/rob_farley" target="_blank">t</a>) for pointing out an inaccuracy in the above! There is a difference between yyyymmdd and yyyy-mm-dd and it&#8217;s important to use the former.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vickyharp.com/2014/07/tomato-tomato-assumptions-about-regionalization/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">466</post-id>	</item>
		<item>
		<title>Killing Sessions with External Wait Types</title>
		<link>https://vickyharp.com/2013/12/killing-sessions-with-external-wait-types/</link>
					<comments>https://vickyharp.com/2013/12/killing-sessions-with-external-wait-types/#comments</comments>
		
		<dc:creator><![CDATA[Vicky]]></dc:creator>
		<pubDate>Wed, 11 Dec 2013 06:22:14 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Extended Stored Procedures]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Waits]]></category>
		<guid isPermaLink="false">http://vickyharp.wpengine.com/?p=434</guid>

					<description><![CDATA[This afternoon I was asked a question that comes up once or twice a year by email. I answered as usual, and only later realized that the topic was a reasonably good match for this month’s TSQL Tuesday topic. I thought I might share the question, and the answer, with a larger audience this time.&#160; <a href="https://vickyharp.com/2013/12/killing-sessions-with-external-wait-types/" title="Read more Killing Sessions with External Wait Types">Read more &#187;</a>]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" class="alignleft" src="https://i1.wp.com/www.sqlsoldier.com/wp/wp-content/uploads/2010/07/TSQL2sDay150x150.jpg?resize=150%2C150" alt="" width="150" height="150" data-recalc-dims="1" />This afternoon I was asked a question that comes up once or twice a year by email. I answered as usual, and only later realized that the topic was a reasonably good match for <a href="http://www.sqlsoldier.com/wp/sqlserver/tsqltuesday49topiciswaitforit" target="_blank" rel="noopener">this month’s TSQL Tuesday topic</a>. I thought I might share the question, and the answer, with a larger audience this time.</p>
<p>Every once in a while I’ll receive a question about a monitoring batch whose spid has gotten hung, and attempts to kill the session simply leave the spid in a rollback state for hours or days on end. Almost invariably these sessions are presenting with an external wait type – usually either MSQL_XP or one of the PREEMPTIVE_OS_* wait types. The usual suspects are calls to xp_fixeddrives and other extended stored procedures backed by xpstar.dll and the sp_oa* procedures that support OLE Automation.</p>
<p>Here is an example of a query which will cause the problem. (Note that enablement of xp_cmdshell is a security hazard and thus this code should only be attempted on a test machine)</p>
<pre class="brush: sql; title: ; notranslate">
exec xp_cmdshell 'powershell -command &quot;sleep 100&quot;'
</pre>
<p>When executed, this command will execute for exactly 100 seconds. Executing the following code will yield some information about what the session is doing.</p>
<pre class="brush: sql; title: ; notranslate">
select
session_id,
wait_type,
command
from sys.dm_exec_requests
where session_id = &lt;session_id&gt;
</pre>
<table>
<tbody>
<tr>
<td>session_id</td>
<td>wait_type</td>
<td>command</td>
</tr>
<tr>
<td>62</td>
<td>PREEMPTIVE_OS_PIPEOPS</td>
<td>EXECUTE</td>
</tr>
</tbody>
</table>
<p>If the session running xp_cmdshell is killed, the session will move to a killed/rollback state, but retain the same wait type.</p>
<table>
<tbody>
<tr>
<td>session_id</td>
<td>wait_type</td>
<td>command</td>
</tr>
<tr>
<td>62</td>
<td>PREEMPTIVE_OS_PIPEOPS</td>
<td>KILLED/ROLLBACK</td>
</tr>
</tbody>
</table>
<p>It will remain in this state until the 100 seconds elapse.</p>
<p>Now, this is all well and good for a session that will die after 100 seconds, but what about a session which is truly and intractably hung? Or what if it was a 10,000 second wait? Is there anything to be done?</p>
<p>Well, it depends. In this specific case, yes. The xp_cmdshell extended stored procedure is running its command out of process to SQL Server. In fact, you can see the life of the session using <a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx" target="_blank" rel="noopener">Sysinternals ProcMon</a>. Here I&#8217;ve reduced the wait to 1 second just to capture it in a neat window.</p>
<div id="attachment_436" style="width: 1291px" class="wp-caption aligncenter"><a href="https://i1.wp.com/vickyharp.wpengine.com/wp-content/uploads/2013/12/procmon-sleep-command.png" target="_blank" rel="noopener"><img aria-describedby="caption-attachment-436" data-attachment-id="436" data-permalink="https://vickyharp.com/2013/12/killing-sessions-with-external-wait-types/procmon-sleep-command/" data-orig-file="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/procmon-sleep-command.png?fit=1281%2C154&amp;ssl=1" data-orig-size="1281,154" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="procmon sleep command" data-image-description="" data-medium-file="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/procmon-sleep-command.png?fit=300%2C36&amp;ssl=1" data-large-file="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/procmon-sleep-command.png?fit=670%2C80&amp;ssl=1" loading="lazy" class="size-full wp-image-436" src="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/procmon-sleep-command.png?resize=670%2C81&#038;ssl=1" alt="procmon sleep command" width="670" height="81" srcset="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/procmon-sleep-command.png?w=1281&amp;ssl=1 1281w, https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/procmon-sleep-command.png?resize=300%2C36&amp;ssl=1 300w, https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/procmon-sleep-command.png?resize=1024%2C123&amp;ssl=1 1024w" sizes="(max-width: 670px) 100vw, 670px" data-recalc-dims="1" /></a><p id="caption-attachment-436" class="wp-caption-text">Click to enlarge</p></div>
<p>SQLServer creates the cmd.exe process and passes it the command, which in turn calls powershell. Each of these processes is a full fledged process visible in Process Explorer.</p>
<p style="text-align: center;"><a href="https://i2.wp.com/vickyharp.wpengine.com/wp-content/uploads/2013/12/process-explorer-sleep-command.png" target="_blank" rel="noopener"><img data-attachment-id="438" data-permalink="https://vickyharp.com/2013/12/killing-sessions-with-external-wait-types/process-explorer-sleep-command/" data-orig-file="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/process-explorer-sleep-command.png?fit=764%2C73&amp;ssl=1" data-orig-size="764,73" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="process explorer sleep command" data-image-description="" data-medium-file="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/process-explorer-sleep-command.png?fit=300%2C28&amp;ssl=1" data-large-file="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/process-explorer-sleep-command.png?fit=670%2C64&amp;ssl=1" loading="lazy" class="aligncenter size-full wp-image-438" src="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/process-explorer-sleep-command.png?resize=670%2C64&#038;ssl=1" alt="click to enlarge" width="670" height="64" srcset="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/process-explorer-sleep-command.png?w=764&amp;ssl=1 764w, https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/process-explorer-sleep-command.png?resize=300%2C28&amp;ssl=1 300w" sizes="(max-width: 670px) 100vw, 670px" data-recalc-dims="1" /></a></p>
<p style="text-align: left;">So in this particular case, if the sleep command was for 10,000 seconds, after the session kill failed, it would be possible to end the session by killing powershell.exe using <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" target="_blank" rel="noopener">Process Explorer</a> &#8211; and that does indeed work.</p>
<p style="text-align: left;">However, there are other external waits which cannot be killed in this way, and these are generally a bit more gnarly to work with. For example, on my machine, it takes about 7 second for the following command to run:</p>
<pre class="brush: sql; title: ; notranslate">xp_dirtree 'c:\windows'</pre>
<p style="text-align: left;">And if I watch it in procmon, I can see that it is SQL Server&#8217;s own process which is walking the directory tree.</p>
<div id="attachment_440" style="width: 1195px" class="wp-caption aligncenter"><a href="https://i1.wp.com/vickyharp.wpengine.com/wp-content/uploads/2013/12/procmon-xpdirtree-command.png" target="_blank" rel="noopener"><img aria-describedby="caption-attachment-440" data-attachment-id="440" data-permalink="https://vickyharp.com/2013/12/killing-sessions-with-external-wait-types/procmon-xpdirtree-command/" data-orig-file="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/procmon-xpdirtree-command.png?fit=1185%2C408&amp;ssl=1" data-orig-size="1185,408" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="procmon xpdirtree command" data-image-description="" data-medium-file="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/procmon-xpdirtree-command.png?fit=300%2C103&amp;ssl=1" data-large-file="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/procmon-xpdirtree-command.png?fit=670%2C230&amp;ssl=1" loading="lazy" class="size-full wp-image-440" src="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/procmon-xpdirtree-command.png?resize=670%2C231&#038;ssl=1" alt="procmon xpdirtree command" width="670" height="231" srcset="https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/procmon-xpdirtree-command.png?w=1185&amp;ssl=1 1185w, https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/procmon-xpdirtree-command.png?resize=300%2C103&amp;ssl=1 300w, https://i1.wp.com/vickyharp.com/wp-content/uploads/2013/12/procmon-xpdirtree-command.png?resize=1024%2C352&amp;ssl=1 1024w" sizes="(max-width: 670px) 100vw, 670px" data-recalc-dims="1" /></a><p id="caption-attachment-440" class="wp-caption-text">click to enlarge</p></div>
<p>Now, this command is having no trouble, and I can kill it quite easily. But as you can see, there&#8217;s no process other than SQL Server itself involved.</p>
<p>What I usually see is that either xp_fixeddrives, xp_readerrorlogs, xp_enumerrorlogs, or one of the OLE Automation stored procedures gets snagged up while running in process to SQL Server. There&#8217;s nothing to kill other than SQL Server itself in this case, and the process generally has to remain a zombie until the underlying problem is solved and/or the SQL Server service is cycled.</p>
<p>In the case of OLE Automation stored procedures specifically, it is possible to run these commands out-of-process to SQL Server just as in the example with xp_cmdshell above. Sometimes this can be done simply by setting the <a href="http://technet.microsoft.com/en-us/library/ms189763.aspx" target="_blank" rel="noopener">context flag of sp_OACreate</a>. In other cases, it may be necessary to fiddle with registry settings to change the threading model of the assembly being loaded from &#8220;Apartment&#8221; to &#8220;Both&#8221; &#8211; something which, it goes without saying, is best tried in a test environment first.</p>
<p>So, that&#8217;s my experience with stuck spids and external wait types. If you&#8217;re lucky, when you get stuck with one of these, it&#8217;s an out of process wait. If you&#8217;re not&#8230; well, you may be waiting for a while longer.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vickyharp.com/2013/12/killing-sessions-with-external-wait-types/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">434</post-id>	</item>
		<item>
		<title>Care and Feeding of Your System Databases Webcast</title>
		<link>https://vickyharp.com/2013/08/care-and-feeding-of-your-system-databases-webcast/</link>
					<comments>https://vickyharp.com/2013/08/care-and-feeding-of-your-system-databases-webcast/#respond</comments>
		
		<dc:creator><![CDATA[Vicky]]></dc:creator>
		<pubDate>Fri, 30 Aug 2013 22:25:23 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[Speaking Events]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[System Databases]]></category>
		<category><![CDATA[tempdb]]></category>
		<category><![CDATA[Webcast]]></category>
		<guid isPermaLink="false">http://vickyharp.wpengine.com/?p=417</guid>

					<description><![CDATA[Over the summer it&#8217;s been my privilege to speak on the subject of Care and Feeding of Your System Databases at the CACTUSS SQL Server user groups in Austin as well as at SQLSaturday #222 in Sacramento. With the assistance of Idera and MSSQLTips.com, that presentation is also available online for viewing. Here is the&#160; <a href="https://vickyharp.com/2013/08/care-and-feeding-of-your-system-databases-webcast/" title="Read more Care and Feeding of Your System Databases Webcast">Read more &#187;</a>]]></description>
										<content:encoded><![CDATA[<p>Over the summer it&#8217;s been my privilege to speak on the subject of Care and Feeding of Your System Databases at the CACTUSS SQL Server user groups in Austin as well as at <a title="SQLSaturday #222" href="http://www.sqlsaturday.com/222/">SQLSaturday #222</a> in Sacramento. With the assistance of <a title="Idera" href="http://www.idera.com">Idera </a>and <a title="MSSQLTIPS" href="http://www.mssqltips.com/">MSSQLTips.com</a>, that presentation is also available online for viewing. Here is the abstract:</p>
<blockquote cite="http://www.mssqltips.com/webcast2.asp?id=213"><p>Master, model, msdb, tempdb. You see them on all of your servers, but what do you really know about them?</p>
<p>
If you ever wanted to learn about the SQL Server system databases, their purpose, and the maintenance and configuration required to keep your server running its best, then this session is for you!</p>
<p>
Learn best practices and techniques, including how to restore master and how to configure tempdb to reduce contention. You&#8217;ll leave with a better understanding of these shared resources and how they affect your database applications.</p></blockquote>
<p>You can view the webcast <a title="Care and Feeding Of Your System Databases" href="http://bit.ly/17lYhHD">here</a>. Please feel free to <a title="Contact Me" href="http://vickyharp.wpengine.com/contact-me/">contact me</a> with any questions!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vickyharp.com/2013/08/care-and-feeding-of-your-system-databases-webcast/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">417</post-id>	</item>
		<item>
		<title>Slides Available for CACTUSS System Databases Presentation</title>
		<link>https://vickyharp.com/2013/05/slides-available-for-cactuss-system-databases-presentation/</link>
					<comments>https://vickyharp.com/2013/05/slides-available-for-cactuss-system-databases-presentation/#respond</comments>
		
		<dc:creator><![CDATA[Vicky]]></dc:creator>
		<pubDate>Thu, 23 May 2013 14:04:57 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[CACTUSS]]></category>
		<category><![CDATA[PASS]]></category>
		<category><![CDATA[Slides]]></category>
		<category><![CDATA[Speaking Events]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[System Databases]]></category>
		<guid isPermaLink="false">http://vickyharp.wpengine.com/?p=394</guid>

					<description><![CDATA[Thanks to everyone who came out to hear me present at CACTUSS this week, I had a lot of fun.  As promised, here are the slides and demos for my Care and Feeding of Your System Databases presentation. Feel free to contact me if you have any questions!]]></description>
										<content:encoded><![CDATA[<p>Thanks to everyone who came out to hear me present at <a title="CACTUSS" href="http://cactuss.org/">CACTUSS </a>this week, I had a lot of fun.  As promised, <a href="http://vickyharp.wpengine.com/wp-content/uploads/2013/05/Care-and-Feeding-of-Your-System-Databases-V-Harp.zip">here</a> are the slides and demos for my Care and Feeding of Your System Databases presentation.</p>
<p>Feel free to <a title="Contact Me" href="http://vickyharp.wpengine.com/contact-me/">contact me</a> if you have any questions!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vickyharp.com/2013/05/slides-available-for-cactuss-system-databases-presentation/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">394</post-id>	</item>
		<item>
		<title>SQL Server bug: Incorrect values in sys.dm_db_session_space_usage for deferred drops</title>
		<link>https://vickyharp.com/2013/05/sql-server-bug-incorrect-values-in-sys-dm_db_session_space_usage-for-deferred-drops/</link>
					<comments>https://vickyharp.com/2013/05/sql-server-bug-incorrect-values-in-sys-dm_db_session_space_usage-for-deferred-drops/#comments</comments>
		
		<dc:creator><![CDATA[Vicky]]></dc:creator>
		<pubDate>Tue, 21 May 2013 15:00:18 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[DMVs]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[tempdb]]></category>
		<guid isPermaLink="false">http://vickyharp.wpengine.com/?p=376</guid>

					<description><![CDATA[For the past few months I have been chasing down an issue which has been plaguing my attempts at tempdb monitoring, and in just the last week I&#8217;ve received news that it is indeed a confirmed bug in SQL Server.  I&#8217;m sharing what I&#8217;ve found here for the benefit of the SQL community. One of&#160; <a href="https://vickyharp.com/2013/05/sql-server-bug-incorrect-values-in-sys-dm_db_session_space_usage-for-deferred-drops/" title="Read more SQL Server bug: Incorrect values in sys.dm_db_session_space_usage for deferred drops">Read more &#187;</a>]]></description>
										<content:encoded><![CDATA[<p>For the past few months I have been chasing down an issue which has been plaguing my attempts at tempdb monitoring, and in just the last week I&#8217;ve received news that it is indeed a confirmed bug in SQL Server.  I&#8217;m sharing what I&#8217;ve found here for the benefit of the SQL community.</p>
<p>One of the features I worked on for SQL diagnostic manager was our tempdb monitoring feature, whereby users can track and alert on a number of tempdb-specific metrics.  Among the items collected are the tempdb page allocation and deallocation values from sys.dm_db_session_space_usage and sys.dm_db_task_space_usage &#8211; specifically, the following columns:</p>
<ul>
<li>user_objects_alloc_page_count</li>
<li>user_objects_dealloc_page_count</li>
<li>internal_objects_alloc_page_count</li>
<li>internal_objects_dealloc_page_count</li>
</ul>
<p>The details of how to use these values in troubleshooting are covered in this <a title="Troubleshooting Insufficient Space in tempdb" href="http://msdn.microsoft.com/en-us/library/ms176029(v=sql.105).aspx">Troubleshooting Insufficient Disk Space in tempdb</a> article by Microsoft.  In brief, these values are intended to track the number of pages allocated or deallocated by a task or session, which can allow the practitioner to identify sessions which are using excessive amounts of space in tempdb or which are churning through a large number of pages over their lifetime.</p>
<p>We were periodically seeing cases where the apparent space used by a session &#8211; as calculated by subtracting the deallocation count from the allocation count for a session &#8211; was well in excess of the total size of tempdb.  I worked closely with Robert Davis (<a title="SQLSoldier blog" href="http://www.sqlsoldier.com/wp/">b</a>|<a title="SQLSoldier Twitter" href="https://twitter.com/SQLSoldier">t</a>) to identify whether this was a bug in the product or a misunderstanding of the contents of the DMV, but he confirmed our logic and believed it was probably a bug.  In deeper testing I was able to reproduce the issue very consistently using simple batches.  I&#8217;d like to walk you through the process.</p>
<p>In this example, a temp table is being created and then rows are being added.  I&#8217;ve noted the line where a &#8220;go 10&#8221; is used &#8211; this causes the script to fill the temp table with 10 rows before dropping it. The script waits 10 seconds, then checks the allocation and deallocation counts from sys.dm_db_session_space_usage and sys.dm_db_task_space_usage.</p>
<pre class="brush: sql; title: ; notranslate">

set nocount on

create table #BigTempTable(a nchar(4000) default 'a')
go

insert into #BigTempTable default values

-- Note this value
go 10

drop table #BigTempTable

go

waitfor delay '00:00:10'

select
      'Session Space',
      ssu.session_id,
      sessionUserPagesAlloc = sum(ssu.user_objects_alloc_page_count),
      sessionUserPagesDealloc = sum(ssu.user_objects_dealloc_page_count),
      taskUserPagesAlloc = sum(tsu.user_objects_alloc_page_count),
      taskUserPagesDealloc = sum(tsu.user_objects_dealloc_page_count),
      sessionInternalPagesAlloc = sum(ssu.internal_objects_alloc_page_count),
      sessionInternalPagesDealloc = sum(ssu.internal_objects_dealloc_page_count),
      taskInternalPagesAlloc = sum(tsu.internal_objects_alloc_page_count),
      taskInternalPagesDealloc = sum(tsu.internal_objects_dealloc_page_count)
from
      tempdb.sys.dm_db_session_space_usage ssu
      left join tempdb.sys.dm_db_task_space_usage tsu
      on ssu.session_id = tsu.session_id
where
	ssu.session_id = @@spid
group by
      ssu.session_id

</pre>
<p>When run as above, with go 10, the DMV data returns exactly what is expected (I have switched rows and columns below for easy readability).</p>
<table width="196" border="0" cellspacing="0" cellpadding="0">
<colgroup>
<col width="124" />
<col width="72" /> </colgroup>
<tbody>
<tr>
<td width="124" height="20">session_id</td>
<td align="right" width="72">52</td>
</tr>
<tr>
<td height="20">sessionUserPagesAlloc</td>
<td align="right">16</td>
</tr>
<tr>
<td height="20">sessionUserPagesDealloc</td>
<td align="right">16</td>
</tr>
<tr>
<td height="20">taskUserPagesAlloc</td>
<td align="right">0</td>
</tr>
<tr>
<td height="20">taskUserPagesDealloc</td>
<td align="right">0</td>
</tr>
<tr>
<td height="20">sessionInternalPagesAlloc</td>
<td align="right">0</td>
</tr>
<tr>
<td height="20">sessionInternalPagesDealloc</td>
<td align="right">0</td>
</tr>
<tr>
<td height="20">taskInternalPagesAlloc</td>
<td align="right">0</td>
</tr>
<tr>
<td height="20">taskInternalPagesDealloc</td>
<td align="right">0</td>
</tr>
</tbody>
</table>
<p>Each of the 10 loops adds 1 row to the temp table, and at that row size each row is 1 page.  The first 8 pages come from mixed extents, and pages 9 and 10 come from a second extent, for a total of 16 pages allocated to the table.  Upon dropping the table, all of that space is deallocated, so we see both an allocation and a deallocation of 16 pages.</p>
<p>If I reset the connection so I have a fresh spid and change the &#8220;go 10&#8221; to &#8220;go 5000,&#8221; however, the returned data begins looking a bit suspect.</p>
<table width="128" border="0" cellspacing="0" cellpadding="0">
<colgroup>
<col span="2" width="64" /> </colgroup>
<tbody>
<tr>
<td width="64" height="20">session_id</td>
<td align="right" width="64">68</td>
</tr>
<tr>
<td height="20">sessionUserPagesAlloc</td>
<td align="right">5000</td>
</tr>
<tr>
<td height="20">sessionUserPagesDealloc</td>
<td align="right">0</td>
</tr>
<tr>
<td height="20">taskUserPagesAlloc</td>
<td align="right">0</td>
</tr>
<tr>
<td height="20">taskUserPagesDealloc</td>
<td align="right">0</td>
</tr>
<tr>
<td height="20">sessionInternalPagesAlloc</td>
<td align="right">0</td>
</tr>
<tr>
<td height="20">sessionInternalPagesDealloc</td>
<td align="right">0</td>
</tr>
<tr>
<td height="20">taskInternalPagesAlloc</td>
<td align="right">0</td>
</tr>
<tr>
<td height="20">taskInternalPagesDealloc</td>
<td align="right">0</td>
</tr>
</tbody>
</table>
<p>At 5000 rows, this data divides up nicely into 625 extents, so exactly 5000 pages are allocated.  However, no pages are marked as deallocated even though the object was dropped.</p>
<p>If I remove the &#8220;where ssu.session_id = @@spid&#8221; clause and look at the space utilization of all sessions, I find that the deallocation value is apparently being credited to a system spid &#8211; in this case, spid 26:</p>
<p><a href="https://i0.wp.com/vickyharp.wpengine.com/wp-content/uploads/2013/05/tempdb-system-spid-deallocation.png"><img data-attachment-id="383" data-permalink="https://vickyharp.com/2013/05/sql-server-bug-incorrect-values-in-sys-dm_db_session_space_usage-for-deferred-drops/tempdb-system-spid-deallocation/" data-orig-file="https://i2.wp.com/vickyharp.com/wp-content/uploads/2013/05/tempdb-system-spid-deallocation.png?fit=715%2C371&amp;ssl=1" data-orig-size="715,371" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="tempdb system spid deallocation" data-image-description="&lt;p&gt;Shows that deallocations from spid 68 are apparently being tracked on system spid 26&lt;/p&gt;
" data-medium-file="https://i2.wp.com/vickyharp.com/wp-content/uploads/2013/05/tempdb-system-spid-deallocation.png?fit=300%2C155&amp;ssl=1" data-large-file="https://i2.wp.com/vickyharp.com/wp-content/uploads/2013/05/tempdb-system-spid-deallocation.png?fit=670%2C348&amp;ssl=1" loading="lazy" class="aligncenter size-full wp-image-383" alt="This image shows that deallocations from spid 68 are apparently being tracked on system spid 26" src="https://i2.wp.com/vickyharp.com/wp-content/uploads/2013/05/tempdb-system-spid-deallocation.png?resize=670%2C348&#038;ssl=1" width="670" height="348" srcset="https://i2.wp.com/vickyharp.com/wp-content/uploads/2013/05/tempdb-system-spid-deallocation.png?w=715&amp;ssl=1 715w, https://i2.wp.com/vickyharp.com/wp-content/uploads/2013/05/tempdb-system-spid-deallocation.png?resize=300%2C155&amp;ssl=1 300w" sizes="(max-width: 670px) 100vw, 670px" data-recalc-dims="1" /></a></p>
<p>So this is the cause of the incorrect values for session space used.  These two contrived examples show a small and a large temp table, and show that at a certain point the deallocated pages are being credited to a system spid.  In practice, however, workloads have a mix of small and large temporary objects, so the deallocation value is often non-zero but still incorrect.</p>
<p>When we first observed this problem Robert mentioned that he thought it was probably an issue to do with deferred drops in tempdb.  In the last week I&#8217;ve heard back from Microsoft, who have confirmed this.  Specifically, the problem is that deferred drops of over 128 extents are not incrementing the user_objects_dealloc_page_count in sys.dm_db_session_space_usage.  Hop on over to <a href="http://www.sqlsoldier.com/wp/sqlserver/bugsysdm_db_session_space_usagereportingextremelyhightempdballocations">this post</a> on Robert&#8217;s blog, where he describes this issue and the concept of deferred drops in great detail.</p>
<p>Just wanted to share these findings with the community.  To my reading, these DMVs remain useful to give overall impressions of how much space is being used by sessions and can be used to identify the sessions which are using tempdb most heavily over time.  While this bug is in place, however, it is not possible to state that subtracting deallocations from allocations will yield current usage for a specific session.</p>
<p>Many thanks to the folks at SQLClinic at PASS Summit, to the CSS escalation team at Microsoft, and to Robert Davis for helping identify this issue.  Don&#8217;t miss <a href="http://www.sqlsoldier.com/wp/sqlserver/bugsysdm_db_session_space_usagereportingextremelyhightempdballocations">Robert&#8217;s post</a>, which has some important details about how deferred drops work.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vickyharp.com/2013/05/sql-server-bug-incorrect-values-in-sys-dm_db_session_space_usage-for-deferred-drops/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">376</post-id>	</item>
		<item>
		<title>Speaking at CACTUSS User Groups in Austin next week</title>
		<link>https://vickyharp.com/2013/05/speaking-at-cactuss-user-groups-in-austin-next-week/</link>
					<comments>https://vickyharp.com/2013/05/speaking-at-cactuss-user-groups-in-austin-next-week/#respond</comments>
		
		<dc:creator><![CDATA[Vicky]]></dc:creator>
		<pubDate>Thu, 16 May 2013 16:41:49 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[PASS]]></category>
		<category><![CDATA[Speaking Events]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[System Databases]]></category>
		<guid isPermaLink="false">http://vickyharp.wpengine.com/?p=369</guid>

					<description><![CDATA[After taking a break from speaking for a while, I&#8217;m happy to announce that I&#8217;ll be presenting at the CACTUSS Central and CACTUSS North meetings in Austin, TX on May 20 and May 21, respectively.  I&#8217;ll be bringing a new presentation, &#8220;Care and Feeding of Your System Databases.&#8221;  We&#8217;ll go over the SQL Server system&#160; <a href="https://vickyharp.com/2013/05/speaking-at-cactuss-user-groups-in-austin-next-week/" title="Read more Speaking at CACTUSS User Groups in Austin next week">Read more &#187;</a>]]></description>
										<content:encoded><![CDATA[<p>After taking a break from speaking for a while, I&#8217;m happy to announce that I&#8217;ll be presenting at the <a title="CACTUSS" href="http://cactuss.org/">CACTUSS</a> Central and CACTUSS North meetings in Austin, TX on May 20 and May 21, respectively.  I&#8217;ll be bringing a new presentation, &#8220;Care and Feeding of Your System Databases.&#8221;  We&#8217;ll go over the SQL Server system databases, what they&#8217;re used for, configuration and maintenance best practices and antipractices, and a few troubleshooting scenarios.</p>
<p>If you&#8217;ve got questions you&#8217;d like answered feel free to <a title="Contact Me" href="http://vickyharp.wpengine.com/contact-me/">drop me a line</a> ahead of time and I&#8217;ll try to cover them in the presentation &#8211; otherwise, hope to see you there!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vickyharp.com/2013/05/speaking-at-cactuss-user-groups-in-austin-next-week/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">369</post-id>	</item>
		<item>
		<title>Obfuscated T-SQL Holiday Cards</title>
		<link>https://vickyharp.com/2012/12/obfuscated-t-sql-holiday-cards/</link>
					<comments>https://vickyharp.com/2012/12/obfuscated-t-sql-holiday-cards/#comments</comments>
		
		<dc:creator><![CDATA[Vicky]]></dc:creator>
		<pubDate>Sat, 22 Dec 2012 16:25:27 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Christmas]]></category>
		<category><![CDATA[Holiday]]></category>
		<category><![CDATA[Obfuscation]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[T-SQL]]></category>
		<guid isPermaLink="false">http://vickyharp.wpengine.com/?p=290</guid>

					<description><![CDATA[As a student I was always a great fan of the International Obfuscated C Code Contest.  If you&#8217;re not familiar with obfuscation contests, they&#8217;re basically a two part brain teaser for coders.  The first part, and the one I find really satisfying, is to write code to do some task in a completely non-obvious way&#160; <a href="https://vickyharp.com/2012/12/obfuscated-t-sql-holiday-cards/" title="Read more Obfuscated T-SQL Holiday Cards">Read more &#187;</a>]]></description>
										<content:encoded><![CDATA[<p>As a student I was always a great fan of the <a title="IOCCC" href="http://www.ioccc.org/">International Obfuscated C Code Contest</a>.  If you&#8217;re not familiar with obfuscation contests, they&#8217;re basically a two part brain teaser for coders.  The first part, and the one I find really satisfying, is to write code to do some task in a completely non-obvious way such that it is very tricky to work out what the end result will be.  The second part is to take someone else&#8217;s obfuscated code and try to work out what they&#8217;re doing and how.  There&#8217;s probably a joke in there about code maintainability, but at their best, code obfuscation puzzles have taught me a lot about the languages I work in.</p>
<p>For the past two years I have taken a stab at an obfuscated T-SQL code holiday greeting card.  The code displays poorly on mobile devices and some browsers, so I&#8217;ve posted images here (the source, posted again below, is <a href="http://vickyharp.wpengine.com/wp-content/uploads/2012/12/TSQL-Holiday-Cards.zip">here</a>).  Here is this year&#8217;s card:</p>
<p><a href="https://i0.wp.com/vickyharp.wpengine.com/wp-content/uploads/2012/12/holidaycard2012.png"><img data-attachment-id="296" data-permalink="https://vickyharp.com/2012/12/obfuscated-t-sql-holiday-cards/holidaycard2012/" data-orig-file="https://i1.wp.com/vickyharp.com/wp-content/uploads/2012/12/holidaycard2012.png?fit=695%2C884&amp;ssl=1" data-orig-size="695,884" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="Holiday Card 2012" data-image-description="" data-medium-file="https://i1.wp.com/vickyharp.com/wp-content/uploads/2012/12/holidaycard2012.png?fit=235%2C300&amp;ssl=1" data-large-file="https://i1.wp.com/vickyharp.com/wp-content/uploads/2012/12/holidaycard2012.png?fit=670%2C852&amp;ssl=1" loading="lazy" class="aligncenter size-full wp-image-296" title="Holiday Card 2012" src="https://i1.wp.com/vickyharp.com/wp-content/uploads/2012/12/holidaycard2012.png?resize=670%2C852&#038;ssl=1" alt="" width="670" height="852" srcset="https://i1.wp.com/vickyharp.com/wp-content/uploads/2012/12/holidaycard2012.png?w=695&amp;ssl=1 695w, https://i1.wp.com/vickyharp.com/wp-content/uploads/2012/12/holidaycard2012.png?resize=235%2C300&amp;ssl=1 235w" sizes="(max-width: 670px) 100vw, 670px" data-recalc-dims="1" /></a></p>
<p>&nbsp;</p>
<p>And here&#8217;s last year&#8217;s:</p>
<p>&nbsp;</p>
<p><a href="https://i1.wp.com/vickyharp.wpengine.com/wp-content/uploads/2012/12/holidaycard2011.png"><img data-attachment-id="299" data-permalink="https://vickyharp.com/2012/12/obfuscated-t-sql-holiday-cards/holidaycard2011/" data-orig-file="https://i2.wp.com/vickyharp.com/wp-content/uploads/2012/12/holidaycard2011.png?fit=656%2C923&amp;ssl=1" data-orig-size="656,923" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}" data-image-title="Obfuscated TSQL Holiday Card 2011" data-image-description="" data-medium-file="https://i2.wp.com/vickyharp.com/wp-content/uploads/2012/12/holidaycard2011.png?fit=213%2C300&amp;ssl=1" data-large-file="https://i2.wp.com/vickyharp.com/wp-content/uploads/2012/12/holidaycard2011.png?fit=656%2C923&amp;ssl=1" loading="lazy" class="aligncenter size-full wp-image-299" title="Obfuscated TSQL Holiday Card 2011" src="https://i2.wp.com/vickyharp.com/wp-content/uploads/2012/12/holidaycard2011.png?resize=656%2C923&#038;ssl=1" alt="" width="656" height="923" srcset="https://i2.wp.com/vickyharp.com/wp-content/uploads/2012/12/holidaycard2011.png?w=656&amp;ssl=1 656w, https://i2.wp.com/vickyharp.com/wp-content/uploads/2012/12/holidaycard2011.png?resize=213%2C300&amp;ssl=1 213w" sizes="(max-width: 656px) 100vw, 656px" data-recalc-dims="1" /></a></p>
<p>&nbsp;</p>
<p>I won&#8217;t spoil the fun by posting their output, but if you&#8217;d like to give them a try, you can download the source code to both <a title="Obfuscated TSQL Holiday Cards" href="http://vickyharp.wpengine.com/wp-content/uploads/2012/12/TSQL-Holiday-Cards.zip">here</a>.</p>
<p>Hope you enjoy them, and have a wonderful holiday and a happy and prosperous new year!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vickyharp.com/2012/12/obfuscated-t-sql-holiday-cards/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">290</post-id>	</item>
		<item>
		<title>Troubleshooting &#8220;A severe error occurred on the current command.&#8221;</title>
		<link>https://vickyharp.com/2012/03/troubleshooting-a-severe-error-occurred-on-the-current-command/</link>
					<comments>https://vickyharp.com/2012/03/troubleshooting-a-severe-error-occurred-on-the-current-command/#comments</comments>
		
		<dc:creator><![CDATA[Vicky]]></dc:creator>
		<pubDate>Wed, 21 Mar 2012 16:00:08 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Edge Cases]]></category>
		<category><![CDATA[Errors]]></category>
		<category><![CDATA[Extended Stored Procedures]]></category>
		<category><![CDATA[Runtime Error]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<guid isPermaLink="false">http://vickyharp.wpengine.com/?p=206</guid>

					<description><![CDATA[I thought it might be useful to start a semi-regular series of entries on troubleshooting for the SQL Server developer. Google has come to my rescue lo, these many times: this is my way of returning the favor. For this first entry I thought I&#8217;d tackle one of the more mysterious-looking runtime errors I see&#160; <a href="https://vickyharp.com/2012/03/troubleshooting-a-severe-error-occurred-on-the-current-command/" title="Read more Troubleshooting &#8220;A severe error occurred on the current command.&#8221;">Read more &#187;</a>]]></description>
										<content:encoded><![CDATA[<p>I thought it might be useful to start a semi-regular series of entries on troubleshooting for the SQL Server developer. Google has come to my rescue lo, these many times: this is my way of returning the favor. For this first entry I thought I&#8217;d tackle one of the more mysterious-looking runtime errors I see from time to time.</p>
<p>It usually goes about like this &#8211; code that has been running fine for ages, or which works fine for everyone else in the universe, suddenly starts bailing out with a runtime error. The error, when located, looks like this:</p>
<p><span style="color: #ff0000;">Msg 0, Level 11, State 0, Line 0</span><br />
<span style="color: #ff0000;">A severe error occurred on the current command. The results, if any, should be discarded.</span></p>
<p>It&#8217;s really a frightful-looking message, and worse, double-clicking on the message in SSMS does not jump your cursor to the source of the error. Well great.</p>
<p>This is where your mileage may vary, but for me, I generally see this error crop up in code which follows this pattern:</p>
<ul>
<li>The batch is utilizing an extended stored procedure</li>
<li> The output of the extended stored procedure is being insert into a table</li>
</ul>
<p>By way of example, here&#8217;s a snippet of code that will reliably cause the error:</p>
<pre class="brush: sql; title: ; notranslate">

create table #ErrorLog
(LogDate datetime,
ProcessInfo nvarchar(50),
LogText nvarchar(500))

insert into #ErrorLog
 exec xp_readerrorlog 'authentication mode'

drop table #ErrorLog
</pre>
<p>In this case the output of xp_readerrorlog is being insert into a temporary table. However, if you&#8217;re familiar with xp_readerrorlog you&#8217;ll recognize that there&#8217;s something not quite right going on here. If you take the outer insert out of the equation and run the procedure by itsef, the error message becomes clearer:</p>
<pre class="brush: sql; title: ; notranslate">
exec xp_readerrorlog 'authentication mode'

</pre>
<p>The output in this case is:</p>
<p><span style="color: #ff0000;">Msg 22004, Level 12, State 1, Line 0</span><br />
<span style="color: #ff0000;">Error executing extended stored procedure: Invalid Parameter Type</span></p>
<p>Yes, indeed, &#8216;authentication mode&#8217; is not a valid parameter value here: the procedure is expecting an integer. That&#8217;s much clearer than &#8220;a severe error.&#8221;  Fixing that bug solves the issue.</p>
<pre class="brush: sql; title: ; notranslate">

create table #ErrorLog
(LogDate datetime,
ProcessInfo nvarchar(50),
LogText nvarchar(500))

insert into #ErrorLog
 exec xp_readerrorlog 1,1,'authentication mode'

drop table #ErrorLog

</pre>
<p>This is of course a contrived example and this code would never have worked, but often in production these errors are more subtle. I have seen the inner exception be an overflow, a permissions problem, or even outright corruption, and often it&#8217;s not as clear-cut and perfectly reproducible as this example. For instance, the stored procedure in the outer batch may be a regular system or user procedure which in turn calls an extended stored procedure, but only with certain codepaths.  You may really need to peel the onion on this one.</p>
<p>Certainly I don&#8217;t believe this is the only error case that can lead to this particular message, but for what it&#8217;s worth, in my experience looking for the XSP has generally put me on the right path toward quashing the bug.  If you have any other experience with this error, please let me know either through my <a title="Contact Me" href="http://vickyharp.wpengine.com/contact-me/">contact page</a> or through the comments.</p>
<p>Happy debugging!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vickyharp.com/2012/03/troubleshooting-a-severe-error-occurred-on-the-current-command/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">206</post-id>	</item>
		<item>
		<title>Speaking at SQLSaturday #111 in Atlanta on April 14</title>
		<link>https://vickyharp.com/2012/03/speaking-at-sqlsaturday-111-in-atlanta-on-april-14/</link>
					<comments>https://vickyharp.com/2012/03/speaking-at-sqlsaturday-111-in-atlanta-on-april-14/#respond</comments>
		
		<dc:creator><![CDATA[Vicky]]></dc:creator>
		<pubDate>Wed, 14 Mar 2012 16:15:09 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Expressions]]></category>
		<category><![CDATA[Free Events]]></category>
		<category><![CDATA[PASS]]></category>
		<category><![CDATA[Speaking Events]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Saturday]]></category>
		<category><![CDATA[T-SQL]]></category>
		<guid isPermaLink="false">http://vickyharp.wpengine.com/?p=195</guid>

					<description><![CDATA[A month from today on April 14, 2012 I&#8217;ll be speaking at SQLSaturday #111 in Atlanta, GA (or, more precisely, in Alpharetta, GA).  This will be my first trip to Georgia and I&#8217;m delighted to be able to present alongside some of the biggest names in the SQL Server community.  It&#8217;s a great honor to be&#160; <a href="https://vickyharp.com/2012/03/speaking-at-sqlsaturday-111-in-atlanta-on-april-14/" title="Read more Speaking at SQLSaturday #111 in Atlanta on April 14">Read more &#187;</a>]]></description>
										<content:encoded><![CDATA[<p>A month from today on April 14, 2012 I&#8217;ll be speaking at <a title="SQLSaturday #111 - Atlanta, GA" href="http://sqlsaturday.com/111/eventhome.aspx" target="_blank">SQLSaturday #111</a> in Atlanta, GA (or, more precisely, in Alpharetta, GA).  This will be my first trip to Georgia and I&#8217;m delighted to be able to present alongside some of the biggest names in the SQL Server community.  It&#8217;s a great honor to be chosen and I am so looking forward to the event.</p>
<p>For this SQLSaturday I&#8217;ll be giving my presentation <a title="Introduction to Common Table Expressions at SQLSaturday #111" href="http://sqlsaturday.com/viewsession.aspx?sat=111&amp;sessionid=6168" target="_blank">Introduction to Common Table Expressions</a>.  In this example-heavy session I offer an introduction to T-SQL common table expression syntax and cover the basics of recursive expressions, with an eye toward when and how this style of coding can improve maintainability.  I&#8217;ll also touch upon when it makes sense to use recursive CTEs (spoilers: not very often).</p>
<p>I look forward to meeting many of you at SQLSaturday #111.  You can see this and all of my upcoming and past SQL Server events <a title="SQL Server Events" href="http://vickyharp.wpengine.com/sql-server-events/">here</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://vickyharp.com/2012/03/speaking-at-sqlsaturday-111-in-atlanta-on-april-14/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">195</post-id>	</item>
	</channel>
</rss>
