<?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>Next Generation IT Consultant</title>
	<atom:link href="http://blogs.itcng.pl/janusz_marchewa/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.itcng.pl/janusz_marchewa</link>
	<description>My thoughts on SQL Server, SharePoint, .NET...</description>
	<lastBuildDate>Wed, 05 May 2010 14:52:11 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>XML to the rescue &#8211; parsing text formulas</title>
		<link>http://blogs.itcng.pl/janusz_marchewa/2010/05/05/xml-to-the-rescue-parsing-text-formulas/</link>
		<comments>http://blogs.itcng.pl/janusz_marchewa/2010/05/05/xml-to-the-rescue-parsing-text-formulas/#comments</comments>
		<pubDate>Wed, 05 May 2010 14:52:11 +0000</pubDate>
		<dc:creator>Janusz Marchewa</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[sql server 2008]]></category>
		<category><![CDATA[t-sql]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blogs.itcng.pl/janusz_marchewa/?p=53</guid>
		<description><![CDATA[My last project (the one that prevented me from blogging in April) involved parsing some text formulas defined by business users. A typical formula would look like this: 1234.56+6789.100-5468. . Dots in this formula are not decimal separators &#8211; they separate accounts and subaccounts (financial stuff). Anyway, I had to extract those account/subaccount numbers, get [...]]]></description>
			<content:encoded><![CDATA[<p>My last project (the one that prevented me from blogging in April) involved parsing some text formulas defined by business users. A typical formula would look like this: <code>1234.56+6789.100-5468.</code> . Dots in this formula are not decimal separators &#8211; they separate accounts and subaccounts (financial stuff). Anyway, I had to extract those account/subaccount numbers, get their current balances and evaluate the formula. The most straightforward solution would be a loop, where the formula would be parsed &#8211; one character at a time.</p>
<p>But I have come up with another one &#8211; add some XML tags here and there, convert the formula to XML and extract relational data from it. Sounds good enough? Let&#8217;s see the code:
</pre>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">FUNCTION</span> dbo.<span style="color: #202020;">parse_formula</span><span style="color: #808080;">&#40;</span>
	@p_formula <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">RETURNS</span> @tbl_formula_elements <span style="color: #0000FF;">TABLE</span> <span style="color: #808080;">&#40;</span>
		<span style="color: #FF00FF;">SIGN</span> <span style="color: #0000FF;">CHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span>,
		account <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">8</span><span style="color: #808080;">&#41;</span>,
		subaccount <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">20</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #0000FF;">DECLARE</span> @formula <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">MAX</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #0000FF;">CASE</span>
		<span style="color: #0000FF;">WHEN</span> <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>@p_formula, <span style="color: #000;">1</span><span style="color: #808080;">&#41;</span>  <span style="color: #FF0000;">'-'</span>
			<span style="color: #0000FF;">THEN</span> <span style="color: #FF0000;">'+'</span>
		<span style="color: #0000FF;">ELSE</span>
			<span style="color: #FF0000;">''</span>
	<span style="color: #0000FF;">END</span> <span style="color: #808080;">+</span> @p_formula;
&nbsp;
	<span style="color: #0000FF;">SET</span> @formula <span style="color: #808080;">=</span> <span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span>
			@formula,
			<span style="color: #FF0000;">'+'</span>, 
			<span style="color: #FF0000;">'&lt;/Subaccount&gt;&lt;/FormulaElement&gt;&lt;FormulaElement&gt;&lt;Sign&gt;+&lt;/Sign&gt;&lt;Account&gt;'</span>
	<span style="color: #808080;">&#41;</span>;
&nbsp;
	<span style="color: #0000FF;">SET</span> @formula <span style="color: #808080;">=</span> <span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span>
		@formula,
		<span style="color: #FF0000;">'-'</span>, 
		<span style="color: #FF0000;">'&lt;/Subaccount&gt;&lt;/FormulaElement&gt;&lt;FormulaElement&gt;&lt;Sign&gt;-&lt;/Sign&gt;&lt;Account&gt;'</span>
	<span style="color: #808080;">&#41;</span>;
&nbsp;
	<span style="color: #0000FF;">SET</span> @formula <span style="color: #808080;">=</span> <span style="color: #FF00FF;">REPLACE</span><span style="color: #808080;">&#40;</span>
		@formula,
		<span style="color: #FF0000;">'.'</span>, 
		<span style="color: #FF0000;">'&lt;/Account&gt;&lt;Subaccount&gt;'</span>
	<span style="color: #808080;">&#41;</span>;
&nbsp;
	<span style="color: #0000FF;">DECLARE</span> @formula_elements XML <span style="color: #808080;">=</span> <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span>
		XML,
		<span style="color: #FF0000;">'&lt;Formula&gt;'</span> 
			<span style="color: #808080;">+</span> <span style="color: #0000FF;">RIGHT</span><span style="color: #808080;">&#40;</span>@formula, <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>@formula<span style="color: #808080;">&#41;</span> <span style="color: #808080;">-</span> <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'&lt;/Subaccount&gt;&lt;/FormulaElement&gt;'</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
			<span style="color: #808080;">+</span> <span style="color: #FF0000;">'&lt;/Subaccount&gt;&lt;/FormulaElement&gt;&lt;/Formula&gt;'</span>
	<span style="color: #808080;">&#41;</span>;
&nbsp;
	<span style="color: #0000FF;">INSERT</span> @tbl_formula_elements
	<span style="color: #0000FF;">SELECT</span> 
		FormulaElements.<span style="color: #202020;">cols</span>.<span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Sign[1]'</span>, <span style="color: #FF0000;">'char(1)'</span><span style="color: #808080;">&#41;</span>,
		FormulaElements.<span style="color: #202020;">cols</span>.<span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Account[1]'</span>, <span style="color: #FF0000;">'varchar(8)'</span><span style="color: #808080;">&#41;</span>,
		FormulaElements.<span style="color: #202020;">cols</span>.<span style="color: #0000FF;">VALUE</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'Subaccount[1]'</span>, <span style="color: #FF0000;">'varchar(20)'</span><span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">FROM</span>
		@formula_elements.<span style="color: #202020;">nodes</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'/Formula/FormulaElement'</span><span style="color: #808080;">&#41;</span> FormulaElements <span style="color: #808080;">&#40;</span>cols<span style="color: #808080;">&#41;</span>;
&nbsp;
	<span style="color: #0000FF;">RETURN</span>;
<span style="color: #0000FF;">END</span>;</pre></div></div>

<p>This TVF first checks whether the formula begins with a <code>-</code> and puts a <code>+</code> at the start if it does not. Then it adds some XML tags so that the resulting XML consists of a single <code>Formula</code> element, which consists of one or many <code>FormulaElement</code> elements. Each <code>FormulaElement</code> contains a single <code>Sign</code> element, a single <code>Account</code> element and a single <code>Subaccount</code> element. </p>
<p>When the XML string is ready, the TVF converts it to the native <code>XML</code> type and puts the formula elements in the result table. The formula is ready for evaluation. Let's invoke the TVF:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> 
	<span style="color: #FF00FF;">SIGN</span>,
	account,
	subaccount
<span style="color: #0000FF;">FROM</span>
	dbo.<span style="color: #202020;">parse_formula</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'1234.56+6789.100-5468.'</span><span style="color: #808080;">&#41;</span></pre></div></div>

<pre>
sign account  subaccount
---- -------- --------------------
+    1234     56
+    6789     100
-    5468
(3 row(s) affected)
</pre>
<p>How to evaluate a formula transformed to a table like this one? Join this table with the current account balances, multiply them by -1 where the sign is <code>-</code> and sum the results.</p>
<p>Those of you who fear XML - now you have another lethal weapon in your SQL Server arsenal (probably <code>FOR XML PATH('')</code> was the first one <img src='http://blogs.itcng.pl/janusz_marchewa/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ).</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.itcng.pl/janusz_marchewa/2010/05/05/xml-to-the-rescue-parsing-text-formulas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>4Developers 2010 &#8211; my source code samples</title>
		<link>http://blogs.itcng.pl/janusz_marchewa/2010/03/31/4developers-2010-my-source-code-samples/</link>
		<comments>http://blogs.itcng.pl/janusz_marchewa/2010/03/31/4developers-2010-my-source-code-samples/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 10:32:57 +0000</pubDate>
		<dc:creator>Janusz Marchewa</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[4developers 2010]]></category>

		<guid isPermaLink="false">http://blogs.itcng.pl/janusz_marchewa/?p=48</guid>
		<description><![CDATA[4Developers 2010 is over, so it&#8217;s time to share my source code samples used during the presentation. You can download them here. The messages and labels are in Polish, but the whole source code uses English names, so hopefully non-Polish speakers will also find their way through the code  
]]></description>
			<content:encoded><![CDATA[<p>4Developers 2010 is over, so it&#8217;s time to share my source code samples used during the presentation. You can download them <a href='http://blogs.itcng.pl/janusz_marchewa/2010/03/31/4developers-2010-my-source-code-samples/jm_4dev2010_samples/' rel='attachment wp-att-47'>here</a>. The messages and labels are in Polish, but the whole source code uses English names, so hopefully non-Polish speakers will also find their way through the code <img src='http://blogs.itcng.pl/janusz_marchewa/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.itcng.pl/janusz_marchewa/2010/03/31/4developers-2010-my-source-code-samples/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>4Developers 2010</title>
		<link>http://blogs.itcng.pl/janusz_marchewa/2010/03/25/4developers-2010/</link>
		<comments>http://blogs.itcng.pl/janusz_marchewa/2010/03/25/4developers-2010/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 19:13:07 +0000</pubDate>
		<dc:creator>Janusz Marchewa</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[4developers 2010]]></category>

		<guid isPermaLink="false">http://blogs.itcng.pl/janusz_marchewa/?p=45</guid>
		<description><![CDATA[Tomorrow I will be speaking at the 4Developers Conference in Poznan. I will be talking about using SSIS, SSAS and SSRS in .NET applications to solve various business problems with minimum effort. Lots of interesting content, only 45 minutes AND it&#8217;s the last session before lunch time &#8211; now that&#8217;s what I call a challenge [...]]]></description>
			<content:encoded><![CDATA[<p>Tomorrow I will be speaking at the <a href="http://2010.4developers.org.pl/net-c-agenda/lang-pref/en/">4Developers Conference in Poznan</a>. I will be talking about using SSIS, SSAS and SSRS in .NET applications to solve various business problems with minimum effort. Lots of interesting content, only 45 minutes AND it&#8217;s the last session before lunch time &#8211; now that&#8217;s what I call a challenge <img src='http://blogs.itcng.pl/janusz_marchewa/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I will upload my source code samples shortly after the conference. I&#8217;m also planning some blog posts on this topic &#8211; hopefully quite soon. It won&#8217;t be easy, because currently I have some really time-consuming projects on the run, but stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.itcng.pl/janusz_marchewa/2010/03/25/4developers-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Business Contact Manager: MSSMLBIZ instance starts automatically even if start mode is set to Manual</title>
		<link>http://blogs.itcng.pl/janusz_marchewa/2010/02/19/business-contact-manager-mssmlbiz-instance-starts-automatically-even-if-start-mode-is-set-to-manual/</link>
		<comments>http://blogs.itcng.pl/janusz_marchewa/2010/02/19/business-contact-manager-mssmlbiz-instance-starts-automatically-even-if-start-mode-is-set-to-manual/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 11:03:26 +0000</pubDate>
		<dc:creator>Janusz Marchewa</dc:creator>
				<category><![CDATA[Office]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[bcm]]></category>
		<category><![CDATA[office 2007]]></category>

		<guid isPermaLink="false">http://blogs.itcng.pl/janusz_marchewa/?p=42</guid>
		<description><![CDATA[Are you an Outlook 2007 with Business Contact Manager user? If you are, you might have experienced that the local SQL Server 2005 Express instance (named MSSMLBIZ) starts by default when your OS starts up. I found this to be quite annoying, because I don&#8217;t use BCM all the time. BCM will start the MSSMLBIZ [...]]]></description>
			<content:encoded><![CDATA[<p>Are you an <a href="http://office.microsoft.com/en-us/contactmanager/default.aspx">Outlook 2007 with Business Contact Manager</a> user? If you are, you might have experienced that the local SQL Server 2005 Express instance (named MSSMLBIZ) starts by default when your OS starts up. I found this to be quite annoying, because I don&#8217;t use BCM all the time. BCM will start the MSSMLBIZ instance if it&#8217;s stopped and the user navigates to a view where BCM data is required. That behaviour is completely sufficient and it seems pointless to start MSSMLBIZ at boot time. So, how to handle this issue?</p>
<p>Surprisingly, setting the start mode of MSSMLBIZ to Manual in SQL Server Configuration Manager does not change anything. After looking in the event log I realized that BCM comes with another service that handles SQL Server startup. The service is called <em>Business Contact Manager SQL Server Startup Service</em> (BcmSqlStartupSvc.exe). When you disable the automatic startup of this service, the OS boot time will return to normal and you will only experience a slight delay when you navigate to BCM data in Outlook, because from now on this will be the startup moment for MSSMLBIZ. </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.itcng.pl/janusz_marchewa/2010/02/19/business-contact-manager-mssmlbiz-instance-starts-automatically-even-if-start-mode-is-set-to-manual/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>T-SQL Tuesday #002: Houston, we&#8217;ve had a non-breaking space here</title>
		<link>http://blogs.itcng.pl/janusz_marchewa/2010/01/12/t-sql-tuesday-002-houston-weve-had-a-non-breaking-space-here/</link>
		<comments>http://blogs.itcng.pl/janusz_marchewa/2010/01/12/t-sql-tuesday-002-houston-weve-had-a-non-breaking-space-here/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 19:59:52 +0000</pubDate>
		<dc:creator>Janusz Marchewa</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[sql server 2008]]></category>
		<category><![CDATA[tsql2sday]]></category>

		<guid isPermaLink="false">http://blogs.itcng.pl/janusz_marchewa/?p=37</guid>
		<description><![CDATA[This month I&#8217;m participating in T-SQL Tuesday for the first time. T-SQL Tuesday is a really great idea and I hope to participate regularly.
The topic for this month is a puzzling situation. My puzzle is loosely related to T-SQL, but that&#8217;s where I came across it. A few months ago I was working on a [...]]]></description>
			<content:encoded><![CDATA[<p>This month I&#8217;m participating in <a href="http://sqlblog.com/blogs/adam_machanic/archive/2010/01/04/invitation-for-t-sql-tuesday-002-a-puzzling-situation.aspx">T-SQL Tuesday</a> for the first time. T-SQL Tuesday is a really great idea and I hope to participate regularly.</p>
<p>The topic for this month is a puzzling situation. My puzzle is loosely related to T-SQL, but that&#8217;s where I came across it. A few months ago I was working on a data integration project that involved extracting data from many different Excel files and loading a SQL Server database. The data format was far from perfect, so I had to load those Excel files into some staging tables and run some T-SQL code before loading the destination database. </p>
<p>For example, all phone numbers had to consist of 10 digits (with a leading zero). All hyphens, spaces, braces had to be removed. Quite an easy task &#8211; just a few <code>REPLACE</code>s and I could move on. But I could not &#8211; some of the updated records still had spaces in the phone numbers. I did a triple check of my <code>REPLACE</code> functions and I was sure that the code should work fine. </p>
<p>Then I came up with a new idea: I copied the character that looked like a space from the query results and executed:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SELECT</span> <span style="color: #FF00FF;">ASCII</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">' '</span><span style="color: #808080;">&#41;</span></pre></div></div>

<p>The result was: 160. Not 32. So the space wasn&#8217;t just an ordinary space. It turned out to be a non-breaking space. Seems obvious, but how many of us know that the ASCII table contains a non-breaking space? </p>
<p>It is also worth noticing that the <code>TRIM</code> function does not remove non-breaking spaces. Surprising, isn&#8217;t it?</p>
<p>Another puzzling situation I had to deal with was a case where a stored procedure randomly timed out when executed from a custom application, but when executed from SSMS &#8211; it always completed in just a few seconds. I <a href="http://blogs.itcng.pl/janusz_marchewa/2009/12/18/hey-the-stored-procedure-times-out-in-my-application-but-it-completes-in-a-few-seconds-when-executed-in-ssms/">blogged</a> about it last month.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.itcng.pl/janusz_marchewa/2010/01/12/t-sql-tuesday-002-houston-weve-had-a-non-breaking-space-here/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hey, the stored procedure times out in my application, but it completes in a few seconds when executed in SSMS!</title>
		<link>http://blogs.itcng.pl/janusz_marchewa/2009/12/18/hey-the-stored-procedure-times-out-in-my-application-but-it-completes-in-a-few-seconds-when-executed-in-ssms/</link>
		<comments>http://blogs.itcng.pl/janusz_marchewa/2009/12/18/hey-the-stored-procedure-times-out-in-my-application-but-it-completes-in-a-few-seconds-when-executed-in-ssms/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 21:49:45 +0000</pubDate>
		<dc:creator>Janusz Marchewa</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[sql server 2008]]></category>
		<category><![CDATA[ssms]]></category>
		<category><![CDATA[t-sql]]></category>

		<guid isPermaLink="false">http://blogs.itcng.pl/janusz_marchewa/?p=22</guid>
		<description><![CDATA[One of our customers had problems with his custom application. One of the stored procedures caused random timeouts in this application, but in SSMS the stored procedure always completed in just a few seconds. After attaching SQL Server Profiler it turned out that different execution plans were used for SSMS and the application, but the [...]]]></description>
			<content:encoded><![CDATA[<p>One of our customers had problems with his custom application. One of the stored procedures caused random timeouts in this application, but in SSMS the stored procedure always completed in just a few seconds. After attaching SQL Server Profiler it turned out that different execution plans were used for SSMS and the application, but the parameter values were exactly the same. The customer had already checked that recompiling the stored procedure or restarting the whole server did help for a while.</p>
<p>There are two cases to consider here:</p>
<ol>
<li>The stored procedure is causing timeouts, so it should probably be optimized</li>
<li>The stored procedure always executes quickly in SSMS, so is doesn&#8217;t seem to be an optimization problem</li>
</ol>
<p>Let&#8217;s illustrate that with a quick example. For the purpose of this post I&#8217;ve prepared a stored procedure that retrieves some data about the products and sales orders from AdventureWorks2008:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">USE</span> AdventureWorks2008;
GO
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">PROCEDURE</span> dbo.<span style="color: #202020;">GetOrderedProducts</span><span style="color: #808080;">&#40;</span>
	@ProductName dbo.<span style="color: #202020;">Name</span>,
	@ProductNumber <span style="color: #0000FF;">NVARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">25</span><span style="color: #808080;">&#41;</span>,
	@ProductDaysToManufacture <span style="color: #0000FF;">INT</span>,
	@ProductCategoryName dbo.<span style="color: #202020;">Name</span>,
	@ProductSubcategoryName dbo.<span style="color: #202020;">Name</span>,
	@OnlineOrderFlag dbo.<span style="color: #202020;">Flag</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #0000FF;">SELECT</span>
		ProductName <span style="color: #808080;">=</span> p.<span style="color: #202020;">Name</span>, 
		p.<span style="color: #202020;">ProductNumber</span>,
		p.<span style="color: #202020;">DaysToManufacture</span>,
		ProductSubcategoryName <span style="color: #808080;">=</span> ps.<span style="color: #202020;">Name</span>,
		ProductCategoryName <span style="color: #808080;">=</span> pc.<span style="color: #202020;">Name</span>,
		sod.<span style="color: #202020;">CarrierTrackingNumber</span>,
		sod.<span style="color: #202020;">OrderQty</span>,
		sod.<span style="color: #202020;">UnitPrice</span>,
		soh.<span style="color: #202020;">OrderDate</span>,
		soh.<span style="color: #202020;">DueDate</span>,
		soh.<span style="color: #202020;">ShipDate</span>,
		soh.<span style="color: #202020;">OnlineOrderFlag</span>,
		soh.<span style="color: #202020;">SalesOrderNumber</span>,
		soh.<span style="color: #202020;">SubTotal</span>,
		soh.<span style="color: #202020;">TaxAmt</span>,
		soh.<span style="color: #202020;">Freight</span>
	<span style="color: #0000FF;">FROM</span>
		Sales.<span style="color: #202020;">SalesOrderHeader</span> soh
		<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> Sales.<span style="color: #202020;">SalesOrderDetail</span> sod <span style="color: #0000FF;">ON</span> soh.<span style="color: #202020;">SalesOrderID</span> <span style="color: #808080;">=</span> sod.<span style="color: #202020;">SalesOrderID</span>
		<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> Production.<span style="color: #202020;">Product</span> p <span style="color: #0000FF;">ON</span> sod.<span style="color: #202020;">ProductID</span> <span style="color: #808080;">=</span> p.<span style="color: #202020;">ProductID</span>
		<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> Production.<span style="color: #202020;">ProductSubcategory</span> ps <span style="color: #0000FF;">ON</span> p.<span style="color: #202020;">ProductSubcategoryID</span> <span style="color: #808080;">=</span> ps.<span style="color: #202020;">ProductSubcategoryID</span>
		<span style="color: #0000FF;">INNER</span> <span style="color: #808080;">JOIN</span> Production.<span style="color: #202020;">ProductCategory</span> pc <span style="color: #0000FF;">ON</span> ps.<span style="color: #202020;">ProductCategoryID</span> <span style="color: #808080;">=</span> pc.<span style="color: #202020;">ProductCategoryID</span>
	<span style="color: #0000FF;">WHERE</span>
		<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span>p.<span style="color: #202020;">Name</span> <span style="color: #808080;">LIKE</span> @ProductName<span style="color: #808080;">&#41;</span> <span style="color: #808080;">OR</span> <span style="color: #808080;">&#40;</span>@ProductName <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
		<span style="color: #808080;">AND</span> <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span>p.<span style="color: #202020;">ProductNumber</span> <span style="color: #808080;">LIKE</span> @ProductNumber<span style="color: #808080;">&#41;</span> <span style="color: #808080;">OR</span> <span style="color: #808080;">&#40;</span>@ProductNumber <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
		<span style="color: #808080;">AND</span> <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span>p.<span style="color: #202020;">DaysToManufacture</span> <span style="color: #808080;">=</span> @ProductDaysToManufacture<span style="color: #808080;">&#41;</span> <span style="color: #808080;">OR</span> <span style="color: #808080;">&#40;</span>@ProductDaysToManufacture <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
		<span style="color: #808080;">AND</span> <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span>pc.<span style="color: #202020;">Name</span> <span style="color: #808080;">LIKE</span> @ProductCategoryName<span style="color: #808080;">&#41;</span> <span style="color: #808080;">OR</span> <span style="color: #808080;">&#40;</span>@ProductCategoryName <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
		<span style="color: #808080;">AND</span> <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span>ps.<span style="color: #202020;">Name</span> <span style="color: #808080;">LIKE</span> @ProductSubcategoryName<span style="color: #808080;">&#41;</span> <span style="color: #808080;">OR</span> <span style="color: #808080;">&#40;</span>@ProductSubcategoryName <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>
		<span style="color: #808080;">AND</span> <span style="color: #808080;">&#40;</span><span style="color: #808080;">&#40;</span>soh.<span style="color: #202020;">OnlineOrderFlag</span> <span style="color: #808080;">=</span> @OnlineOrderFlag<span style="color: #808080;">&#41;</span> <span style="color: #808080;">OR</span> <span style="color: #808080;">&#40;</span>@OnlineOrderFlag <span style="color: #0000FF;">IS</span> <span style="color: #808080;">NULL</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">&#41;</span>;
<span style="color: #0000FF;">END</span>;</pre></div></div>

<p>Now, let&#8217;s execute this procedure for a particular product and limit the orders to those that were not made online:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">USE</span> AdventureWorks2008;
GO
<span style="color: #0000FF;">EXEC</span> dbo.<span style="color: #202020;">GetOrderedProducts</span> <span style="color: #808080;">NULL</span>, <span style="color: #FF0000;">'BK-T44U-46'</span>, <span style="color: #808080;">NULL</span>, <span style="color: #FF0000;">'Bikes'</span>, <span style="color: #FF0000;">'Touring Bikes'</span>, <span style="color: #000;">0</span>;</pre></div></div>

<p>That execution will output just a fraction (186 rows) of the whole result set (121317 rows). Our next step &#8211; let&#8217;s retrieve the whole result set:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">USE</span> AdventureWorks2008;
GO
<span style="color: #0000FF;">EXEC</span> dbo.<span style="color: #202020;">GetOrderedProducts</span> <span style="color: #808080;">NULL</span>, <span style="color: #808080;">NULL</span>, <span style="color: #808080;">NULL</span>, <span style="color: #808080;">NULL</span>, <span style="color: #808080;">NULL</span>, <span style="color: #808080;">NULL</span>;</pre></div></div>

<p>It took about 10 seconds to retrieve the whole result set on my laptop. Normally it should take about 3 seconds. What&#8217;s going on? Actually, this happens because of <em>parameter sniffing</em>. </p>
<p>When the stored procedure is compiled (or recompiled), the query optimizer tries to generate an efficient query plan for the current parameter values (and that&#8217;s parameter sniffing &#8211; you can read more about it and other related issues in an excellent TechNet <a href="http://technet.microsoft.com/en-us/library/cc966425.aspx#XSLTsection133121120120">article</a>). That query plan is cached and subsequent executions of this procedure will likely try to use the same query plan (but there are cases where another query plan will be generated and used &#8211; procedure recompilation, for example).</p>
<p>Sounds good? Well, not exactly. That specific stored procedure will surely receive varying parameter values, so the initial query plan might not be the best one for other parameter values. We can quickly see the actual cached execution plan being used by querying some DMVs:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">USE</span> master;
GO
<span style="color: #0000FF;">SELECT</span> 
	UseCounts,
	RefCounts, 
	Cacheobjtype, 
	Objtype, 
	DatabaseName <span style="color: #808080;">=</span> IS<span style="color: #808080;">NULL</span><span style="color: #808080;">&#40;</span><span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span>dest.<span style="color: #202020;">dbid</span><span style="color: #808080;">&#41;</span>, <span style="color: #FF0000;">'ResourceDB'</span><span style="color: #808080;">&#41;</span>, 
	<span style="color: #808080;">&#91;</span><span style="color: #0000FF;">SQL</span><span style="color: #808080;">&#93;</span> <span style="color: #808080;">=</span> <span style="color: #808080;">&#91;</span><span style="color: #0000FF;">TEXT</span><span style="color: #808080;">&#93;</span>,
	QueryPlan <span style="color: #808080;">=</span> query_plan 
<span style="color: #0000FF;">FROM</span> sys.<span style="color: #202020;">dm_exec_cached_plans</span> 
	<span style="color: #808080;">CROSS</span> APPLY sys.<span style="color: #202020;">dm_exec_sql_text</span><span style="color: #808080;">&#40;</span>plan_handle<span style="color: #808080;">&#41;</span> dest
	<span style="color: #808080;">CROSS</span> APPLY sys.<span style="color: #202020;">dm_exec_query_plan</span><span style="color: #808080;">&#40;</span>plan_handle<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">WHERE</span> 
	<span style="color: #FF00FF;">DB_NAME</span><span style="color: #808080;">&#40;</span>dest.<span style="color: #202020;">dbid</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">'AdventureWorks2008'</span>
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span> 
	UseCounts <span style="color: #0000FF;">DESC</span>;</pre></div></div>

<p>Querying <a href="http://msdn.microsoft.com/en-us/library/ms187404.aspx"><code>dm_exec_cached_plans</code></a> will show us a list of all cached execution plans. After joining the results with <a href="http://msdn.microsoft.com/en-us/library/ms181929.aspx"><code>dm_exec_sql_text</code></a> and <a href="http://msdn.microsoft.com/en-us/library/ms189747.aspx"><code>dm_exec_query_plan</code></a> we receive additional valuable information &#8211; the SQL batch text and the graphical query plan.</p>
<p>When we display the query plan that is currently cached, we will notice a Nested Loops operation with an Estimated Number of Rows = 456. That is an efficient operation when the table being iterated is small and the table being scanned is properly indexed. That might be true for the first execution of our procedure, but not for the second, when we want to retrieve the whole result set. </p>
<p>Now, let&#8217;s mark this procedure for recompilation:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">USE</span> AdventureWorks2008;
GO
<span style="color: #0000FF;">EXEC</span> <span style="color: #AF0000;">SP_RECOMPILE</span> N<span style="color: #FF0000;">'dbo.GetOrderedProducts'</span>;</pre></div></div>

<p>And execute the procedure again:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">USE</span> AdventureWorks2008;
GO
<span style="color: #0000FF;">EXEC</span> dbo.<span style="color: #202020;">GetOrderedProducts</span> <span style="color: #808080;">NULL</span>, <span style="color: #808080;">NULL</span>, <span style="color: #808080;">NULL</span>, <span style="color: #808080;">NULL</span>, <span style="color: #808080;">NULL</span>, <span style="color: #808080;">NULL</span>;</pre></div></div>

<p>Now the execution completes in about 3 seconds. After querying the DMVs again we will find out that the execution plan has changed &#8211; instead of a Nested Loops operation we now have a Hash Match operation with an Estimated Number of Rows = 39909. If you need a more detailed analysis of both query plans, another <a href="http://www.simple-talk.com/sql/performance/graphical-execution-plans-for-simple-sql-queries/">article</a> (by Grant Fritchey) might come in handy.</p>
<p>How to deal with similar issues related to parameter sniffing? The recommended solution is to add the <code>WITH RECOMPILE</code> clause to our stored procedure. We won&#8217;t take advantage of caching query plans, but at least the query optimizer will try to generate an efficient execution plan for each set of parameter values that is supplied to the procedure. </p>
<p>What about the problem mentioned in the post title? Well, one of the possible reasons for recompilation is a change in the <code>SET</code> options. Your application connects to SQL Server by using an appropriate provider (OLE DB, ODBC or others). That provider sets six database options by default:</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">SET</span> ANSI_<span style="color: #808080;">NULL</span>S <span style="color: #0000FF;">ON</span>
<span style="color: #0000FF;">SET</span> ANSI_PADD<span style="color: #808080;">IN</span>G <span style="color: #0000FF;">ON</span>
<span style="color: #0000FF;">SET</span> ANSI_WARN<span style="color: #808080;">IN</span>GS <span style="color: #0000FF;">ON</span>
<span style="color: #0000FF;">SET</span> CONCAT_<span style="color: #808080;">NULL</span>_YIELDS_<span style="color: #808080;">NULL</span> <span style="color: #0000FF;">ON</span>
<span style="color: #0000FF;">SET</span> NUMERIC_ROUNDAB<span style="color: #808080;">OR</span>T <span style="color: #0000FF;">OFF</span>
<span style="color: #0000FF;">SET</span> QUOTED_IDENTIFIER <span style="color: #0000FF;">ON</span></pre></div></div>

<p>But there is another option (<code>ARITHABORT</code>) which is not set by default. The setting to use is determined from the default database options (for AdventureWorks2008 it will be ON by default, but for a new database it is OFF by default). That might result in a different <code>ARITHABORT</code> setting in your application and in SSMS, because in SSMS ARITHABORT is ON by default for each query window (Tools-&gt;Options-&gt;Query Execution-&gt;SQL Server-&gt;Advanced):</p>
<p><img src="http://blogs.itcng.pl/janusz_marchewa/files/2009/12/ssms_arithabort.PNG" alt="ssms_arithabort" title="ssms_arithabort" width="756" height="334" class="aligncenter size-full wp-image-25" /></p>
<p>When those settings differ between your app and SSMS, your stored procedure could time out in the application and execute quickly in SSMS (or vice versa). When you check out the DMVs, two plans for this procedure will be cached &#8211; one for each <code>ARITHABORT</code> setting. And that explains the difference in execution times.  </p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.itcng.pl/janusz_marchewa/2009/12/18/hey-the-stored-procedure-times-out-in-my-application-but-it-completes-in-a-few-seconds-when-executed-in-ssms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows 7/Vista and Reporting Services 2008 &#8211; HTTP 404 or no connection</title>
		<link>http://blogs.itcng.pl/janusz_marchewa/2009/12/12/windows-7vista-and-reporting-services-2008-http-404-or-no-connection/</link>
		<comments>http://blogs.itcng.pl/janusz_marchewa/2009/12/12/windows-7vista-and-reporting-services-2008-http-404-or-no-connection/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 21:35:13 +0000</pubDate>
		<dc:creator>Janusz Marchewa</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[reporting services 2008]]></category>
		<category><![CDATA[sql server 2008]]></category>
		<category><![CDATA[windows 7]]></category>
		<category><![CDATA[windows vista]]></category>

		<guid isPermaLink="false">http://blogs.itcng.pl/janusz_marchewa/?p=14</guid>
		<description><![CDATA[This issue might occur when Reporting Services is using the default port (80 or 443) to run Report Server and Report Manager on your workstation. I&#8217;ve reproduced this issue on Windows 7 and Vista, but Windows XP is probably also affected by the issue. 
What&#8217;s the big deal? You install SSRS on your workstation, everything [...]]]></description>
			<content:encoded><![CDATA[<p>This issue might occur when Reporting Services is using the default port (80 or 443) to run Report Server and Report Manager on your workstation. I&#8217;ve reproduced this issue on Windows 7 and Vista, but Windows XP is probably also affected by the issue. </p>
<p>What&#8217;s the big deal? You install SSRS on your workstation, everything goes fine, the service starts, but the URLs for Report Server and Report Manager just don&#8217;t work (either throwing a HTTP 404 or just refusing to connect). You might also encounter the issue a few days (weeks/months etc.) after the initial installation. </p>
<p>We need to investigate the issue. The SSRS logs will come in handy (their default location is: <em>C:\Program Files\Microsoft SQL Server\MSRS10.[INSTANCE_NAME]\Reporting Services\LogFiles</em>). You should look for something similar to:</p>

<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;">rshost<span style="color: #66cc66;">!</span>rshost<span style="color: #66cc66;">!</span><span style="color: #cc66cc;">1120</span><span style="color: #66cc66;">!</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2009</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">22</span><span style="color: #FF1010; font-weight: bold;">:21:33:: e ERROR: Failed to register url=http://+:80/ReportServer/ for endpoint 2, error=20.</span>
rshost<span style="color: #66cc66;">!</span>rshost<span style="color: #66cc66;">!</span><span style="color: #cc66cc;">1120</span><span style="color: #66cc66;">!</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2009</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">22</span><span style="color: #FF1010; font-weight: bold;">:21:33:: w WARN: Endpoint 2 is enabled but no url is registered for vdir=/ReportServer, pdir=c:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportServer.</span>
servicecontroller<span style="color: #66cc66;">!</span>DefaultDomain<span style="color: #66cc66;">!</span><span style="color: #cc66cc;">1200</span><span style="color: #66cc66;">!</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2009</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">22</span><span style="color: #FF1010; font-weight: bold;">:21:33:: e ERROR: Error creating HTTP endpoint. System.IO.FileLoadException: The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)</span>
   at Microsoft.ReportingServices.HostingInterfaces.IRsUnmanagedCallback.CreateHttpEndpoint<span style="color: #66cc66;">&#40;</span>RsAppDomainType application, <span style="color: #0080FF; font-weight: bold;">String</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> urlPrefixes, Int32 cPrefixes, <span style="color: #0080FF; font-weight: bold;">String</span> virtualDirectory, <span style="color: #0080FF; font-weight: bold;">String</span> <span style="color: #0000FF;">filePath</span>, Int32 authType, Int32 logonMethod, <span style="color: #0080FF; font-weight: bold;">String</span> authDomain, <span style="color: #0080FF; font-weight: bold;">String</span> authRealm, Boolean authPersist, Boolean enabled<span style="color: #66cc66;">&#41;</span>
   at Microsoft.ReportingServices.Library.ServiceAppDomainController.SetWebConfiguration<span style="color: #66cc66;">&#40;</span>RunningApplication rsApplication, Boolean enabled, <span style="color: #0080FF; font-weight: bold;">String</span> folder<span style="color: #66cc66;">&#41;</span>
rshost<span style="color: #66cc66;">!</span>rshost<span style="color: #66cc66;">!</span>ca4<span style="color: #66cc66;">!</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2009</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">22</span><span style="color: #FF1010; font-weight: bold;">:21:33:: e ERROR: Failed to register url=http://+:80/Reports/ for endpoint 3, error=20.</span>
rshost<span style="color: #66cc66;">!</span>rshost<span style="color: #66cc66;">!</span>ca4<span style="color: #66cc66;">!</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2009</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">22</span><span style="color: #FF1010; font-weight: bold;">:21:33:: w WARN: Endpoint 3 is enabled but no url is registered for vdir=/Reports, pdir=c:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportManager.</span>
servicecontroller<span style="color: #66cc66;">!</span>DefaultDomain<span style="color: #66cc66;">!</span><span style="color: #cc66cc;">1200</span><span style="color: #66cc66;">!</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">12</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2009</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">22</span><span style="color: #FF1010; font-weight: bold;">:21:33:: e ERROR: Error creating HTTP endpoint. System.IO.FileLoadException: The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)</span>
   at Microsoft.ReportingServices.HostingInterfaces.IRsUnmanagedCallback.CreateHttpEndpoint<span style="color: #66cc66;">&#40;</span>RsAppDomainType application, <span style="color: #0080FF; font-weight: bold;">String</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> urlPrefixes, Int32 cPrefixes, <span style="color: #0080FF; font-weight: bold;">String</span> virtualDirectory, <span style="color: #0080FF; font-weight: bold;">String</span> <span style="color: #0000FF;">filePath</span>, Int32 authType, Int32 logonMethod, <span style="color: #0080FF; font-weight: bold;">String</span> authDomain, <span style="color: #0080FF; font-weight: bold;">String</span> authRealm, Boolean authPersist, Boolean enabled<span style="color: #66cc66;">&#41;</span>
   at Microsoft.ReportingServices.Library.ServiceAppDomainController.SetWebConfiguration<span style="color: #66cc66;">&#40;</span>RunningApplication rsApplication, Boolean enabled, <span style="color: #0080FF; font-weight: bold;">String</span> folder<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Changing the port in Reporting Services Configuration Manager to an unused port (like 8080, but that might not be true on your workstation) resolves the issue. So we have another service blocking the default port. </p>
<p>Now we need to find the culprit. A quick <em>netstat</em> will show the PID of the blocking process:</p>

<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;">netstat <span style="color: #66cc66;">-</span>ano <span style="color: #66cc66;">-</span>p tcp
&nbsp;
Active Connections
&nbsp;
  Proto  Local Address          Foreign Address             State           PID
  ...
  TCP    0.0.0.0<span style="color: #FF1010; font-weight: bold;">:80             0.0.0.0:0                   LISTENING       5340</span>
  ...</pre></div></div>

<p>Now we can find out more about the offending process (PID 5340 in this example). Task Manager can be used (after checking PID on View-&gt;Select Columns) or we can use <em>tasklist</em> here:</p>

<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;">tasklist <span style="color: #66cc66;">/</span>FI <span style="color: #ff0000;">&quot;PID eq 5340&quot;</span>
&nbsp;
Image Name                     PID Session Name        Session<span style="color: #66cc66;">#</span>    Mem Usage
========================= ======== ================ =========== ============
Skype.exe                     <span style="color: #cc66cc;">5340</span> Console                    <span style="color: #cc66cc;">1</span>     <span style="color: #cc66cc;">66</span> <span style="color: #cc66cc;">488</span> K</pre></div></div>

<p>Surprised? Well, I didn&#8217;t expect Skype here. But under Tools-&gt;Options-&gt;Advanced-&gt;Connection you can find the source of our problem:</p>
<p><img class="size-full wp-image-15" title="skype_80_443" src="http://blogs.itcng.pl/janusz_marchewa/files/2009/12/skype_80_443.PNG" alt="This is the problematic option that blocks SSRS from creating HTTP endpoints" width="326" height="31" /></p>
<p>Clearing this option and restarting SSRS also resolves the whole issue. Even if it&#8217;s not Skype, the idea remains the same &#8211; close the offending process, change the port it&#8217;s listening on or change the ports for Report Server and Report Manager.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.itcng.pl/janusz_marchewa/2009/12/12/windows-7vista-and-reporting-services-2008-http-404-or-no-connection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SharePoint 2010 standalone, SQL Server and no sysadmin privileges</title>
		<link>http://blogs.itcng.pl/janusz_marchewa/2009/12/10/sharepoint-2010-standalone-sql-server-and-no-sysadmin-privileges/</link>
		<comments>http://blogs.itcng.pl/janusz_marchewa/2009/12/10/sharepoint-2010-standalone-sql-server-and-no-sysadmin-privileges/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 23:09:37 +0000</pubDate>
		<dc:creator>Janusz Marchewa</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[sharepoint 2010]]></category>
		<category><![CDATA[sql server 2008]]></category>

		<guid isPermaLink="false">http://blogs.itcng.pl/janusz_marchewa/?p=8</guid>
		<description><![CDATA[Good news for developers &#8211; SharePoint 2010 can be installed on your workstations running Windows 7 or Vista x64. There is a good MSDN article describing the installation process &#8211; everything went smoothly on my Windows 7 Ultimate x64.
When WSS 3.0 or MOSS 2007 was installed in standalone mode, it used Windows Internal Database as [...]]]></description>
			<content:encoded><![CDATA[<p>Good news for developers &#8211; SharePoint 2010 can be installed on your workstations running Windows 7 or Vista x64. There is a good MSDN <a href="http://msdn.microsoft.com/en-us/library/ee554869%28office.14%29.aspx">article</a> describing the installation process &#8211; everything went smoothly on my Windows 7 Ultimate x64.</p>
<p>When WSS 3.0 or MOSS 2007 was installed in standalone mode, it used Windows Internal Database as its backend. For SharePoint 2010 this is no longer true &#8211; the installer puts up a named instance (with SHAREPOINT as the instance ID) of SQL Server 2008 Express. This is a fully functional Express instance, but there is still at least one gotcha &#8211; the user that installed SharePoint 2010 has no administrative privileges to this SQL Server instance. What if you really need those privileges?</p>
<p>Fortunately, there is a way (or maybe even multiple ways) to get the privileges you want. It&#8217;s fairly simple &#8211; SQL Server needs to be restarted in single-user mode, so that any member of the Windows Administrators group can login to SQL Server with sysadmin privileges. That administrator grants the required privileges to users, logs out and restarts SQL Server in normal mode.</p>
<p>I have written a simple batch script that accepts two parameters &#8211; the computer name and the user that needs to have sysadmin privileges. Here it is:</p>

<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;">net stop mssql<span style="color: #0000ff;">$sharepoint</span>
net start mssql<span style="color: #0000ff;">$sharepoint</span> <span style="color: #66cc66;">/</span>m <span style="color: #ff0000;">&quot;sqlcmd&quot;</span>
sqlcmd <span style="color: #66cc66;">-</span>E <span style="color: #66cc66;">-</span>S <span style="color: #66cc66;">%</span>1\SHAREPOINT <span style="color: #66cc66;">-</span>Q <span style="color: #ff0000;">&quot;CREATE LOGIN [%1\%2] FROM WINDOWS; EXEC master..sp_addsrvrolemember @loginame = N'%1\%2', @rolename = N'sysadmin';&quot;</span>
net stop mssql<span style="color: #0000ff;">$sharepoint</span>
net start mssql<span style="color: #0000ff;">$sharepoint</span>
iisreset</pre></div></div>

<p>For example, to grant privileges to user JanuszM working on a computer named ITCNG, the following syntax would do the trick (provided that the above script is saved to a file named sp2010_grant_sysadmin.bat):</p>

<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;">sp2010_grant_sysadmin.bat ITCNG JanuszM</pre></div></div>

<p>If you&#8217;re wondering why I&#8217;m using <em>/m &#8220;sqlcmd&#8221;</em> instead of just <em>/m</em>, the answer is simple &#8211; because it&#8217;s single-user mode and only one user can connect to SQL Server. Restricting the connections to sqlcmd almost guarantees that no other running service will acquire that connection and our user will be able to connect and perform the required grants.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.itcng.pl/janusz_marchewa/2009/12/10/sharepoint-2010-standalone-sql-server-and-no-sysadmin-privileges/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SharePoint 2010 Beta available for download</title>
		<link>http://blogs.itcng.pl/janusz_marchewa/2009/11/19/sharepoint-2010-beta-available-for-download/</link>
		<comments>http://blogs.itcng.pl/janusz_marchewa/2009/11/19/sharepoint-2010-beta-available-for-download/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 18:30:24 +0000</pubDate>
		<dc:creator>Janusz Marchewa</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[sharepoint foundation 2010]]></category>
		<category><![CDATA[sharepoint server 2010]]></category>

		<guid isPermaLink="false">http://blogs.itcng.pl/janusz_marchewa/?p=6</guid>
		<description><![CDATA[Here they come &#8211; the beta versions of SharePoint Foundation (former WSS) and SharePoint Server 2010 are now publicly available. Some useful links:

SharePoint Foundation 2010 (Windows SharePoint Services 2010 Beta)
Microsoft SharePoint Server Enterprise 2010 Beta
Microsoft SharePoint Server for Internet Sites Enterprise 2010 Beta
SharePoint 2010 Reference: Software Development Kit

]]></description>
			<content:encoded><![CDATA[<p>Here they come &#8211; the beta versions of SharePoint Foundation (former WSS) and SharePoint Server 2010 are now publicly available. Some useful links:</p>
<ul>
<li><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=906c9f5a-6505-4eba-bf24-95e423ac1703">SharePoint Foundation 2010 (Windows SharePoint Services 2010 Beta)</a></li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=77c30c6c-47fc-416d-88e7-8122534b3f37">Microsoft SharePoint Server Enterprise 2010 Beta</a></li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=580fc452-4948-44ab-9995-a0599271ad48">Microsoft SharePoint Server for Internet Sites Enterprise 2010 Beta</a></li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=f0c9daf3-4c54-45ed-9bde-7b4d83a8f26f">SharePoint 2010 Reference: Software Development Kit</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blogs.itcng.pl/janusz_marchewa/2009/11/19/sharepoint-2010-beta-available-for-download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server 2008 R2 November CTP available for download</title>
		<link>http://blogs.itcng.pl/janusz_marchewa/2009/11/11/sql-server-2008-r2-november-ctp-available-for-download/</link>
		<comments>http://blogs.itcng.pl/janusz_marchewa/2009/11/11/sql-server-2008-r2-november-ctp-available-for-download/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 20:09:52 +0000</pubDate>
		<dc:creator>Janusz Marchewa</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[sql server 2008 r2]]></category>

		<guid isPermaLink="false">http://blogs.itcng.pl/janusz_marchewa/?p=3</guid>
		<description><![CDATA[The R2 November CTP can now be downloaded from: http://www.microsoft.com/sqlserver/2008/en/us/R2Downloads.aspx.
Other R2 November CTP downloads available from Microsoft Download Center:

SQL Server 2008 R2 Books Online Community Technology Preview November 2009
What&#8217;s New in SQL Server 2008 R2 November Community Technology Preview (CTP)
Microsoft SQL Server 2008 R2 November Community Technology Preview End User License Agreements
Microsoft SQL Server 2008 [...]]]></description>
			<content:encoded><![CDATA[<p>The R2 November CTP can now be downloaded from: <a href="http://www.microsoft.com/sqlserver/2008/en/us/R2Downloads.aspx">http://www.microsoft.com/sqlserver/2008/en/us/R2Downloads.aspx</a>.</p>
<p>Other R2 November CTP downloads available from Microsoft Download Center:</p>
<ul>
<li><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=c18bad82-0e5f-4e82-812b-5b23e5d52b9c">SQL Server 2008 R2 Books Online Community Technology Preview November 2009</a></li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=89550298-d564-40c5-b586-30dc3f909f6f">What&#8217;s New in SQL Server 2008 R2 November Community Technology Preview (CTP)</a></li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=80bb26aa-3fbd-483b-ac36-006d496ee58a">Microsoft SQL Server 2008 R2 November Community Technology Preview End User License Agreements</a></li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=c772467d-e45b-43e1-9208-2c7b663d7ad1">Microsoft SQL Server 2008 R2 November Community Technology Preview &#8211; Express Edition</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blogs.itcng.pl/janusz_marchewa/2009/11/11/sql-server-2008-r2-november-ctp-available-for-download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

