<?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>programming.torensma.net</title>
	<atom:link href="http://programming.torensma.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://programming.torensma.net</link>
	<description>Code Snippets</description>
	<lastBuildDate>Thu, 02 Sep 2010 12:43:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Find text inside stored procedures</title>
		<link>http://programming.torensma.net/2010/08/find-text-inside-stored-procedures/</link>
		<comments>http://programming.torensma.net/2010/08/find-text-inside-stored-procedures/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 11:55:37 +0000</pubDate>
		<dc:creator>Elmer</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[microsoft sql server]]></category>

		<guid isPermaLink="false">http://programming.torensma.net/?p=563</guid>
		<description><![CDATA[The following snippet allows you to find all stored procedures containing a specific word or words. I found it to be very helpful to find all references to a table I needed to remove from my database. I order not to break functionality I scanned all procs for references and changed or removed them. Here [...]]]></description>
			<content:encoded><![CDATA[<p>The following snippet allows you to find all stored procedures containing a specific word or words. I found it to be very helpful to find all references to a table I needed to remove from my database. I order not to break functionality I scanned all procs for references and changed or removed them. Here is the code:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT *<br />
FROM INFORMATION_SCHEMA.ROUTINES<br />
WHERE ROUTINE_DEFINITION LIKE '%hello%'<br />
AND ROUTINE_TYPE='PROCEDURE'</div></div>
<p>And here&#8217;s a slightly less efficient alternative. It uses SQL-Server 2008&#8242;s <a href="http://msdn.microsoft.com/en-us/library/ms176090.aspx" target="_blank">OBJECT_DEFINITION()</a> function:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SELECT Name<br />
FROM sys.procedures<br />
WHERE OBJECT_DEFINITION(object_id) LIKE '%firstname%'</div></div>
]]></content:encoded>
			<wfw:commentRss>http://programming.torensma.net/2010/08/find-text-inside-stored-procedures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find most expensive queries in Microsoft SQL server</title>
		<link>http://programming.torensma.net/2010/07/find-most-expensive-queries-in-microsoft-sql-server/</link>
		<comments>http://programming.torensma.net/2010/07/find-most-expensive-queries-in-microsoft-sql-server/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 08:17:27 +0000</pubDate>
		<dc:creator>Elmer</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[performance tuning]]></category>
		<category><![CDATA[sql-server]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://programming.torensma.net/?p=555</guid>
		<description><![CDATA[A colleague of mine found this little gem of a query (sorry, don&#8217;t know the original author). It finds the 20 most expensive queries executed on a SQL server instance, sorted by execution time. CPU load is also returned by the query. Here it is: SELECT TOP 20 qs.sql_handle, qs.execution_count, qs.total_worker_time AS Total_CPU, total_CPU_inSeconds = --Converted from microseconds qs.total_worker_time/1000000, average_CPU_inSeconds = --Converted from microseconds &#40;qs.total_worker_time/1000000&#41;/ qs.execution_count, [...]]]></description>
			<content:encoded><![CDATA[<p>A colleague of mine found this little gem of a query (sorry, don&#8217;t know the original author). It finds the 20 most expensive queries executed on a SQL server instance, sorted by execution time. CPU load is also returned by the query. Here it is:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> TOP <span style="color: #cc66cc;">20</span><br />
qs<span style="color: #66cc66;">.</span>sql_handle<span style="color: #66cc66;">,</span><br />
qs<span style="color: #66cc66;">.</span>execution_count<span style="color: #66cc66;">,</span><br />
qs<span style="color: #66cc66;">.</span>total_worker_time <span style="color: #993333; font-weight: bold;">AS</span> Total_CPU<span style="color: #66cc66;">,</span><br />
total_CPU_inSeconds <span style="color: #66cc66;">=</span> <span style="color: #808080; font-style: italic;">--Converted from microseconds</span><br />
qs<span style="color: #66cc66;">.</span>total_worker_time<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1000000</span><span style="color: #66cc66;">,</span><br />
average_CPU_inSeconds <span style="color: #66cc66;">=</span> <span style="color: #808080; font-style: italic;">--Converted from microseconds</span><br />
<span style="color: #66cc66;">&#40;</span>qs<span style="color: #66cc66;">.</span>total_worker_time<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1000000</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">/</span> qs<span style="color: #66cc66;">.</span>execution_count<span style="color: #66cc66;">,</span><br />
qs<span style="color: #66cc66;">.</span>total_elapsed_time<span style="color: #66cc66;">,</span><br />
total_elapsed_time_inSeconds <span style="color: #66cc66;">=</span> <span style="color: #808080; font-style: italic;">--Converted from microseconds</span><br />
qs<span style="color: #66cc66;">.</span>total_elapsed_time<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1000000</span><span style="color: #66cc66;">,</span><br />
st<span style="color: #66cc66;">.</span>text<span style="color: #66cc66;">,</span><br />
qp<span style="color: #66cc66;">.</span>query_plan<br />
<span style="color: #993333; font-weight: bold;">FROM</span><br />
sys<span style="color: #66cc66;">.</span>dm_exec_query_stats <span style="color: #993333; font-weight: bold;">AS</span> qs<br />
<span style="color: #993333; font-weight: bold;">CROSS</span> APPLYsys<span style="color: #66cc66;">.</span>dm_exec_sql_text<span style="color: #66cc66;">&#40;</span>qs<span style="color: #66cc66;">.</span>sql_handle<span style="color: #66cc66;">&#41;</span> ASst<br />
<span style="color: #993333; font-weight: bold;">CROSS</span> apply sys<span style="color: #66cc66;">.</span>dm_exec_query_plan<span style="color: #66cc66;">&#40;</span>qs<span style="color: #66cc66;">.</span>plan_handle<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> qp<br />
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> qs<span style="color: #66cc66;">.</span>total_worker_time <span style="color: #993333; font-weight: bold;">DESC</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://programming.torensma.net/2010/07/find-most-expensive-queries-in-microsoft-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some nice programming quotes I came across&#8230;</title>
		<link>http://programming.torensma.net/2010/07/some-nice-programming-quotes-i-came-across/</link>
		<comments>http://programming.torensma.net/2010/07/some-nice-programming-quotes-i-came-across/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 11:18:19 +0000</pubDate>
		<dc:creator>Elmer</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WTF]]></category>
		<category><![CDATA[funny]]></category>
		<category><![CDATA[quotes]]></category>

		<guid isPermaLink="false">http://programming.torensma.net/?p=547</guid>
		<description><![CDATA[Walking on water and developing software from a specification are easy if both are frozen. &#8211; Edward V. Berard Hofstadter&#8217;s Law: It always takes longer than you expect, even when you take into account Hofstadter&#8217;s Law. Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li>Walking on water and developing software from a specification are easy if both are frozen.<br />
&#8211; Edward V. Berard</li>
<li>Hofstadter&#8217;s Law:<br />
It always takes longer than you expect, even when you take into account Hofstadter&#8217;s Law.</li>
<li>Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.<br />
&#8211; Brian Kernighan</li>
<li>Some people, when confronted with a problem, think &#8220;I know, I’ll use regular expressions.&#8221; Now they have two problems.<br />
&#8211; Jamie Zawinski</li>
<li>Linux is only free if your time has no value.<br />
&#8211; Jamie Zawinski</li>
<li>It works on my machine.<br />
&#8211; Anonymous</li>
<li>It worked yesterday.<br />
&#8211; Anonymous</li>
<li>If debugging is the process of removing software bugs, then programming must be the process of putting them in.<br />
&#8211; Edsger Dijkstra</li>
<li>A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila.<br />
&#8211; Mitch Ratcliffe</li>
<li>Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.<br />
&#8211; Antoine de Saint Exupéry</li>
<li>Perl &#8211; The only language that looks the same before and after RSA encryption.<br />
&#8211; Keith Bostic</li>
<li>The trouble with programmers is that you can never tell what a programmer is doing until it&#8217;s too late.<br />
&#8211; Seymour Cray</li>
<li>Measuring programming progress by lines of code is like measuring aircraft building progress by weight.<br />
&#8211; Bill Gates</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://programming.torensma.net/2010/07/some-nice-programming-quotes-i-came-across/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>10 Free Tools to Load/Stress Test Your Web Applications</title>
		<link>http://programming.torensma.net/2010/07/10-free-tools-to-loadstress-test-your-web-applications/</link>
		<comments>http://programming.torensma.net/2010/07/10-free-tools-to-loadstress-test-your-web-applications/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 14:15:34 +0000</pubDate>
		<dc:creator>Elmer</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[load test]]></category>
		<category><![CDATA[stress test]]></category>

		<guid isPermaLink="false">http://programming.torensma.net/?p=543</guid>
		<description><![CDATA[Follow the link&#8230; http://www.devcurry.com/2010/07/10-free-tools-to-loadstress-test-your.html]]></description>
			<content:encoded><![CDATA[<p>Follow the link&#8230;</p>
<p><a href="http://www.devcurry.com/2010/07/10-free-tools-to-loadstress-test-your.html">http://www.devcurry.com/2010/07/10-free-tools-to-loadstress-test-your.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://programming.torensma.net/2010/07/10-free-tools-to-loadstress-test-your-web-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script failed for Trigger &#8216;Trigger-name&#8217;. (Microsoft.SqlServer.Smo))</title>
		<link>http://programming.torensma.net/2010/05/script-failed-for-trigger-trigger-name-microsoft-sqlserver-smo/</link>
		<comments>http://programming.torensma.net/2010/05/script-failed-for-trigger-trigger-name-microsoft-sqlserver-smo/#comments</comments>
		<pubDate>Tue, 11 May 2010 08:54:23 +0000</pubDate>
		<dc:creator>Elmer</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[microsoft sql server]]></category>

		<guid isPermaLink="false">http://programming.torensma.net/?p=531</guid>
		<description><![CDATA[It&#8217;s a documented bug in SQL server that causes above error message. The error is triggered by nested comment blocks, like this example: /* some comments /* nested comments*/ some more comments */ All very well, it&#8217;s a documented bug so it shouldn&#8217;t be a problem. Microsoft&#8217;s solution is plain and effective: don&#8217;t use nested comment [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://programming.torensma.net/wp-content/uploads/2010/05/script-failed-sql-server.png"><img title="script-failed-sql-server" src="http://programming.torensma.net/wp-content/uploads/2010/05/script-failed-sql-server.png" alt="Scripting a trigger fails in SQL server due to nested comments" width="489" height="122" /></a></p>
<p>It&#8217;s a documented bug in SQL server that causes above error message. The error is triggered by nested comment blocks, like this example:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/*<br />
<br />
some comments<br />
/* nested comments*/</span><br />
some more comments<br />
<span style="color: #66cc66;">*/</span></div></div>
<p>All very well, it&#8217;s a documented bug so it shouldn&#8217;t be a problem. Microsoft&#8217;s solution is plain and effective:<em> don&#8217;t use nested comment blocks</em>.</p>
<p>But what if, like in my case, you created the trigger using SQL server 2000&#8242;s Enterprise Manager (which does not suffer from the bug) and you&#8217;re trying to open the trigger much later using Microsoft&#8217;s SQL Server Management Studio? The trigger will fail to open and you&#8217;re pretty well stuck.</p>
<p>What is needed now is a way to get to the trigger without opening it directly in the Management Studio. Luckily SQL Server stores all its tables, views, stored procedures and triggers in the database itself. So to get to the trigger we need to know where it is stored.</p>
<p>In <a href="http://programming.torensma.net/2008/05/select_all_user_tables_in_a_ms-sql_server_database/">this post</a> I described how to display a list of tables, views or other user objects from SQL Server. If we expand the query a little it allows us to get to the contents of the trigger we need:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> o<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>name<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">,</span> c<span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>text<span style="color: #66cc66;">&#93;</span><br />
<span style="color: #993333; font-weight: bold;">FROM</span> sysobjects o <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span><br />
syscomments c <span style="color: #993333; font-weight: bold;">ON</span> o<span style="color: #66cc66;">.</span>ID<span style="color: #66cc66;">=</span>c<span style="color: #66cc66;">.</span>ID<br />
<span style="color: #993333; font-weight: bold;">WHERE</span> o<span style="color: #66cc66;">.</span>xtype <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'TR'</span></div></div>
<p>As you can see the contents of triggers is stored in the SYSCOMMENTS table. Note that longer functions, triggers and stored procedures may have multiple entries with the same name in SYSCOMMENTS. You may have to concatenate the text fields of multiple records together to get the complete contents of your function. I found the best way is create a small loop and PRINT the results instead of outputting them to the default grid.</p>
]]></content:encoded>
			<wfw:commentRss>http://programming.torensma.net/2010/05/script-failed-for-trigger-trigger-name-microsoft-sqlserver-smo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to display table sizes in SQL server</title>
		<link>http://programming.torensma.net/2010/05/how-to-display-table-sizes-in-sql-server/</link>
		<comments>http://programming.torensma.net/2010/05/how-to-display-table-sizes-in-sql-server/#comments</comments>
		<pubDate>Fri, 07 May 2010 08:28:28 +0000</pubDate>
		<dc:creator>Elmer</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[sql-server]]></category>

		<guid isPermaLink="false">http://programming.torensma.net/?p=519</guid>
		<description><![CDATA[There are a few ways to retrieve the table sizes (both row count and size in bytes) in SQL server. The simplest is the sp_spaceused stored procedure which takes a table name as argument: EXEC sp_spaceused 'table_name' This is all fine, but what if you want to display info about a dozen or more tables? [...]]]></description>
			<content:encoded><![CDATA[<p>There are a few ways to retrieve the table sizes (both row count and size in bytes) in SQL server. The simplest is the <code class="codecolorer text default"><span class="text">sp_spaceused</span></code> stored procedure which takes a table name as argument:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">EXEC sp_spaceused <span style="color: #ff0000;">'table_name'</span></div></div>
<p>This is all fine, but what if you want to display info about a dozen or more tables? The undocumenten stored procedure <code class="codecolorer text default"><span class="text">sp_MSforeachtable</span></code> might proof useful here:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">EXEC sp_MSforeachtable @command1<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;EXEC sp_spaceused '?'&quot;</span></div></div>
<p>This statement executes the <code class="codecolorer text default"><span class="text">sp_spaceused</span></code> sp for every table in the connected database. This actually gets the information we want, albeit not in a very readable form. Because the sp is execute for each table, we get a result set for every table. If we want to do some filtering and sorting we&#8217;re out of luck here. So we need something more flexible.</p>
<p>The following routine executes the <code class="codecolorer text default"><span class="text">sp_spaceused</span></code> sp for each table again, but the results are aggregated into a temporary table. Now we get a nice result set that we can actually work with. Here&#8217;s the code:</p>
<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> #SpaceUsed <span style="color: #808080;">&#40;</span>name sysname,<span style="color: #0000FF;">rows</span> <span style="color: #0000FF;">bigint</span>,reserved sysname,<span style="color: #0000FF;">data</span> sysname,index_size sysname,unused sysname<span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #0000FF;">DECLARE</span> @Counter <span style="color: #0000FF;">int</span> <br />
<span style="color: #0000FF;">DECLARE</span> @<span style="color: #FF00FF;">Max</span> <span style="color: #0000FF;">int</span> <br />
<span style="color: #0000FF;">DECLARE</span> @<span style="color: #0000FF;">Table</span> sysname<br />
<br />
<span style="color: #0000FF;">SELECT</span> &nbsp;name, <span style="color: #0000FF;">IDENTITY</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">int</span>,<span style="color: #000;">1</span>,<span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> ROWID <br />
<span style="color: #0000FF;">INTO</span> &nbsp; &nbsp; &nbsp; #TableCollection <br />
<span style="color: #0000FF;">FROM</span> &nbsp; &nbsp;sysobjects <br />
<span style="color: #0000FF;">WHERE</span> xtype <span style="color: #808080;">=</span> <span style="color: #FF0000;">'U'</span> <br />
<span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span> <span style="color: #FF00FF;">lower</span><span style="color: #808080;">&#40;</span>name<span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #0000FF;">SET</span> @Counter <span style="color: #808080;">=</span> <span style="color: #000;">1</span> <br />
<span style="color: #0000FF;">SET</span> @<span style="color: #FF00FF;">Max</span> <span style="color: #808080;">=</span> <span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> <span style="color: #FF00FF;">Max</span><span style="color: #808080;">&#40;</span>ROWID<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">FROM</span> #TableCollection<span style="color: #808080;">&#41;</span><br />
<br />
<span style="color: #0000FF;">WHILE</span> <span style="color: #808080;">&#40;</span>@Counter <span style="color: #808080;">&lt;=</span> @<span style="color: #FF00FF;">Max</span><span style="color: #808080;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #0000FF;">BEGIN</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @<span style="color: #0000FF;">Table</span> <span style="color: #808080;">=</span> <span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> name <span style="color: #0000FF;">FROM</span> #TableCollection <span style="color: #0000FF;">WHERE</span> ROWID <span style="color: #808080;">=</span> @Counter<span style="color: #808080;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #SpaceUsed <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">EXECUTE</span> <span style="color: #AF0000;">sp_spaceused</span> @<span style="color: #0000FF;">Table</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> @Counter <span style="color: #808080;">=</span> @Counter <span style="color: #808080;">+</span> <span style="color: #000;">1</span> <br />
&nbsp; &nbsp; <span style="color: #0000FF;">END</span><br />
<br />
<span style="color: #0000FF;">SELECT</span> <span style="color: #808080;">*</span> <span style="color: #0000FF;">FROM</span> #SpaceUsed<br />
<br />
<span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">TABLE</span> #TableCollection <br />
<span style="color: #0000FF;">DROP</span> <span style="color: #0000FF;">TABLE</span> #SpaceUsed</div></div>
]]></content:encoded>
			<wfw:commentRss>http://programming.torensma.net/2010/05/how-to-display-table-sizes-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows 7 &#8211; Explorer.exe server execution failed</title>
		<link>http://programming.torensma.net/2010/05/windows-7-explorer-exe-server-execution-failed/</link>
		<comments>http://programming.torensma.net/2010/05/windows-7-explorer-exe-server-execution-failed/#comments</comments>
		<pubDate>Mon, 03 May 2010 08:27:31 +0000</pubDate>
		<dc:creator>Elmer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://programming.torensma.net/?p=515</guid>
		<description><![CDATA[On my company laptop I have a network drive attached which is not always available. Recently I got annoyed about files not always being there so I decided to disconnect the company drive all together. After restarting I then got EXPLORE.EXE server execution failed and the Windows Explorer no longer started. Turns out I had [...]]]></description>
			<content:encoded><![CDATA[<p>On my company laptop I have a network drive attached which is not always available. Recently I got annoyed about files not always being there so I decided to disconnect the company drive all together. After restarting I then got EXPLORE.EXE server execution failed and the Windows Explorer no longer started.</p>
<p>Turns out I had some registry settings pointing to my company drive. Changing them to local paths solved my problem. These are the keys in question:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal<br />
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Personal</div></div>
]]></content:encoded>
			<wfw:commentRss>http://programming.torensma.net/2010/05/windows-7-explorer-exe-server-execution-failed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make a .NET web service accept GET requests</title>
		<link>http://programming.torensma.net/2010/04/make-a-net-web-service-accept-get-requests/</link>
		<comments>http://programming.torensma.net/2010/04/make-a-net-web-service-accept-get-requests/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 12:44:24 +0000</pubDate>
		<dc:creator>Elmer</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[DotNET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://programming.torensma.net/?p=504</guid>
		<description><![CDATA[The usual way to call web service is by using POST requests. But sometimes GET requests are required. To make .NET web services accept their parameters from GET requests, add a ScriptMethod attribute to your web service routine. First add some libraries: C# Using System.Web.Services; Using System.Web.Services.Protocols; Using System.Web.Script.Services; Visual Basic Imports System.Web.Services Imports System.Web.Services.Protocols [...]]]></description>
			<content:encoded><![CDATA[<p>The usual way to call web service is by using POST requests. But sometimes GET requests are required. To make .NET web services accept their parameters from GET requests, add a ScriptMethod attribute to your web service routine.</p>
<p>First add some libraries:<br />
C#</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">Using</span> <span style="color: #008080;">System.Web.Services</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">Using</span> <span style="color: #008080;">System.Web.Services.Protocols</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF; font-weight: bold;">Using</span> <span style="color: #008080;">System.Web.Script.Services</span><span style="color: #008000;">;</span></div></div>
<p>Visual Basic</p>
<div class="codecolorer-container vb default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Imports System.Web.Services<br />
Imports System.Web.Services.Protocols<br />
Imports System.Web.Script.Services</div></div>
<p>Then decorate your web service method:<br />
C#:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">&#91;</span>WebMethod<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
<span style="color: #008000;">&#91;</span>ScriptMethod<span style="color: #008000;">&#40;</span>UseHttpGet<span style="color: #008000;">=</span><span style="color: #0600FF; font-weight: bold;">True</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span><br />
<span style="color: #0600FF; font-weight: bold;">Public</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> WebServiceName<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">String</span> q, <span style="color: #6666cc; font-weight: bold;">Int</span> count<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; <span style="color: #008080; font-style: italic;">// Web service implementation</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>Visual Basic:</p>
<div class="codecolorer-container vb default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;WebMethod()&gt; _<br />
&lt;ScriptMethod(UseHttpGet:=<span style="color: #000080;">True</span>)&gt; _<br />
<span style="color: #000080;">Public</span> <span style="color: #000080;">Function</span> WebServiceName(<span style="color: #000080;">ByVal</span> q <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>, <span style="color: #000080;">ByVal</span> count <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>) <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>()<br />
&nbsp; <span style="color: #008000;">' Web service implementation<br />
</span><span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></div></div>
<p>Finally you need to tell your application to accept GET requests in your web.config:</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.web<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; ...<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;webServices<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;protocols<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;HttpGet&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/protocols<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/webServices<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; ...<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.web<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>One note of warning: GET requests may be easier to hack because the querystring is visible to the user. Use it wisely. On the other hand, POST requests can be tampered with just as well, don&#8217;t expect them to be saver!</p>
]]></content:encoded>
			<wfw:commentRss>http://programming.torensma.net/2010/04/make-a-net-web-service-accept-get-requests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to rename a column in a MS-SQL database?</title>
		<link>http://programming.torensma.net/2010/03/how-to-rename-a-column-in-a-ms-sql-database/</link>
		<comments>http://programming.torensma.net/2010/03/how-to-rename-a-column-in-a-ms-sql-database/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 10:49:57 +0000</pubDate>
		<dc:creator>Elmer</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[t-sql]]></category>

		<guid isPermaLink="false">http://programming.torensma.net/?p=499</guid>
		<description><![CDATA[Easy peasy, use the sp_rename stored procedure: EXEC sp_rename 'TABLENAME.OLD_COLUMNNAME', 'NEW_COLUMNAME', 'COLUMN';]]></description>
			<content:encoded><![CDATA[<p>Easy peasy, use the <strong>sp_rename</strong> stored procedure:</p>
<div class="codecolorer-container sql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">EXEC sp_rename <span style="color: #ff0000;">'TABLENAME.OLD_COLUMNNAME'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'NEW_COLUMNAME'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'COLUMN'</span>;</div></div>
]]></content:encoded>
			<wfw:commentRss>http://programming.torensma.net/2010/03/how-to-rename-a-column-in-a-ms-sql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CakePHP: catching errors in Model-&gt;query()</title>
		<link>http://programming.torensma.net/2010/02/cakephp-catching-error-in-model-query/</link>
		<comments>http://programming.torensma.net/2010/02/cakephp-catching-error-in-model-query/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 21:04:22 +0000</pubDate>
		<dc:creator>Elmer</dc:creator>
				<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://programming.torensma.net/?p=479</guid>
		<description><![CDATA[In my recent CakePHP application I use some custom SQL queries that I fire at the database using the $model-&#62;query($sql) syntax. Works great, until you have an error in your $sql. I tried the obvious error handling with try &#8230; catch: try &#123; &#160; $this-&#62;Model-&#62;query&#40;'INSERT INTO model WHERE id=invalid'&#41;; &#125; catch &#40;exception $ex&#41; &#123; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>In my recent CakePHP application I use some custom SQL queries that I fire at the database using the $model-&gt;query($sql) syntax. Works great, until you have an error in your $sql. I tried the obvious error handling with try &#8230; catch:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">try <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'INSERT INTO model WHERE id=invalid'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>exception <span style="color: #000088;">$ex</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// exception never happens</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>But the CakePHP Debugger class already catches the error and does it&#8217;s handling; which is writing the error to the browser. In my case I need to act upon an error.</p>
<p>After some trial and error (including hacking the core Cake files, which is really dirty) I came up with this: the Cake Debugger class set an error handler using <code class="codecolorer text default"><span class="text">set_error_handler('someErrorHandlingRoutine')</span></code>. So i made my own error handing routine, borrowing some from the Debugger class:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> AppController <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">function</span> handleError<span style="color: #009900;">&#40;</span><span style="color: #000088;">$code</span><span style="color: #339933;">,</span> <span style="color: #000088;">$description</span><span style="color: #339933;">,</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$line</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$context</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/error_reporting"><span style="color: #990000;">error_reporting</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$code</span> <span style="color: #339933;">===</span> <span style="color: #cc66cc;">2048</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$code</span> <span style="color: #339933;">===</span> <span style="color: #cc66cc;">8192</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// throw error for further handling</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> exception<span style="color: #009900;">&#40;</span><a href="http://www.php.net/strip_tags"><span style="color: #990000;">strip_tags</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$description</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>What it does is simple and ellegant; throw an exception. Now my $model-&gt;query code can be wrapped in a try&#8230;catch block and if an exception happens I can act on it.</p>
<p>As you can see I placed my error handler in the app_controller.php. This way it&#8217;s easily accessible from all my controllers.</p>
<p>Now before calling <code class="codecolorer php default"><span class="php"><span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span></span></code> I set my custom error handler:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// set error handler in controller</span><br />
<a href="http://www.php.net/set_error_handler"><span style="color: #990000;">set_error_handler</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'handleError'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
try <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// execute dangerous sql</span><br />
&nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>exception <span style="color: #000088;">$ex</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// custom error handling here...</span><br />
<span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://programming.torensma.net/2010/02/cakephp-catching-error-in-model-query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
