<?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>FailBoy &#187; Development</title>
	<atom:link href="http://www.failboy.net/category/dev/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.failboy.net</link>
	<description>We reserve the right FAIL</description>
	<lastBuildDate>Thu, 26 Nov 2009 06:29:01 +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>9 Google Wave invites up for grabs</title>
		<link>http://www.failboy.net/2009/11/9-google-wave-invites-up-for-grabs/</link>
		<comments>http://www.failboy.net/2009/11/9-google-wave-invites-up-for-grabs/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 06:21:01 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Invites]]></category>
		<category><![CDATA[Wave]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=54</guid>
		<description><![CDATA[First 9 people to comment on this post get a Google Wave invite. In all honestly, Wave isn&#8217;t that awesome yet. Maybe with a higher adoption it&#8217;ll take off. UPDATE: Once I invite you, Google has to approve the invite and send it to you. This sometimes takes a few days]]></description>
			<content:encoded><![CDATA[<p>First 9 people to comment on this post get a Google Wave invite.</p>
<p>In all honestly, Wave isn&#8217;t that awesome yet. Maybe with a higher adoption it&#8217;ll take off.</p>
<p>UPDATE: Once I invite you, Google has to approve the invite and send it to you. This sometimes takes a few days</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/11/9-google-wave-invites-up-for-grabs/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Difference between a Junior and Senior Developer</title>
		<link>http://www.failboy.net/2009/11/difference-between-a-junior-and-senior-developer/</link>
		<comments>http://www.failboy.net/2009/11/difference-between-a-junior-and-senior-developer/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 15:39:21 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Developers]]></category>
		<category><![CDATA[Junior]]></category>
		<category><![CDATA[Senior]]></category>
		<category><![CDATA[Wisdom]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=52</guid>
		<description><![CDATA[This topic came up in the office today and one of our senior developers indicated the following: A Junior developer says: &#8220;It works on my machine&#8221;. A Senior developer says: &#8220;Its working fine on the production server&#8221;. I feel that is particularly apt]]></description>
			<content:encoded><![CDATA[<p>This topic came up in the office today and one of our senior developers indicated the following:</p>
<p>A Junior developer says: &#8220;It works on my machine&#8221;.<br />
A Senior developer says: &#8220;Its working fine on the production server&#8221;.</p>
<p>I feel that is particularly apt</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/11/difference-between-a-junior-and-senior-developer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# has an ISNULL function, its called ??</title>
		<link>http://www.failboy.net/2009/10/c-has-an-isnull-function-its-called/</link>
		<comments>http://www.failboy.net/2009/10/c-has-an-isnull-function-its-called/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 08:13:27 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[??]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ISNULL]]></category>
		<category><![CDATA[operators]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=48</guid>
		<description><![CDATA[Just a very short and quick post. For a while now .Net has had nullable types. Take for example an integer, instead of declaring it as: int x = 0; you declare it as: int? x = 0; Now in coding examples all over the web I&#8217;m seeing the same logic and its driving me [...]]]></description>
			<content:encoded><![CDATA[<p>Just a very short and quick post. For a while now .Net has had nullable types. Take for example an integer, instead of declaring it as:</p>
<pre class="brush: csharp;">int x = 0;</pre>
<p>you declare it as: </p>
<pre class="brush: csharp;">int? x = 0;</pre>
<p>Now in coding examples all over the web I&#8217;m seeing the same logic and its driving me nuts!</p>
<pre class="brush: csharp;">if(x == null){
    x = -1;
}</pre>
<p>There is a much shorter route and that is:</p>
<pre class="brush: csharp;">x = x ?? -1;</pre>
<p>The &#8220;??&#8221; operator works exactly the same way an ISNULL function call works in SQL. It evaluates the variable on the left of the operator to ensure its not null (or undefined as some people call it), and if it is, it uses the value on the right of the ?? operator. Quick and easy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/10/c-has-an-isnull-function-its-called/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LINQ: Distinct method</title>
		<link>http://www.failboy.net/2009/07/linq-distinct-method/</link>
		<comments>http://www.failboy.net/2009/07/linq-distinct-method/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 19:44:14 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Distinct]]></category>
		<category><![CDATA[IEnumerable]]></category>
		<category><![CDATA[Linq]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=42</guid>
		<description><![CDATA[Ah the beauty of LINQ. I previously did a post on How to use Lambda Expressions and if you aren&#8217;t sure now how to use them, is the time to check it out. I have decided to have a good look at the Methods available to IEnumerable collections and first on the list the DISTINCT [...]]]></description>
			<content:encoded><![CDATA[<p>Ah the beauty of LINQ. I previously did a post on<a title="how to use lambda expressions" href="http://www.failboy.net/2009/07/how-to-use-lambda-expressions/" target="_blank"> How to use Lambda Expressions</a> and if you aren&#8217;t sure now how to use them, is the time to check it out. I have decided to have a good look at the Methods available to IEnumerable collections and first on the list the DISTINCT method.</p>
<p><span style="text-decoration: underline;"><strong>The Boring Standard Method:</strong></span></p>
<p>The Distinct method removes any duplicate entries in a collection without you needing to do much work, the same as the DISTINCT keyword inT-SQL. Here is the basic and standard use that is really not difficult to understand.</p>
<pre class="brush: csharp;">
string[] names = new string[] { &quot;Peter&quot;, &quot;Paul&quot;, &quot;Mary&quot;, &quot;Peter&quot;, &quot;Paul&quot;, &quot;Mary&quot;, &quot;Janet&quot; };

foreach (string _name in names.Distinct())
{
Console.WriteLine(_name);
}</pre>
<p>So like I said, easy enough, we have a string array with names and by using the .Distinct method we remove any duplicates from the resultset that is returned. Now comes the real fun!</p>
<p><span style="text-decoration: underline;"><strong>Custom Distinct Implementation:</strong></span></p>
<p>Since the advent of generics, most of us have been creating strongly typed lists of data. Plain example would be a list of our customer UserClass.</p>
<pre class="brush: csharp;">
public class Users
{
public int ID {get; set;}
public string Name {get; set;}
public int AwesomeScore {get; set;}
}

// Create and populate new list of Users
List&lt;Users&gt; failBoyUsers = new List&lt;Users&gt;();
failBoyUsers.Add(new Users { AwesomeScore = 7, Name = &quot;FailBoy&quot;, ID = 1 });
failBoyUsers.Add(new Users { AwesomeScore = 10, Name = &quot;Rathlan&quot;, ID = 2 });
failBoyUsers.Add(new Users { AwesomeScore = 10, Name = &quot;Rathlan&quot;, ID = 2 });
failBoyUsers.Add(new Users { AwesomeScore = 7, Name = &quot;Joe&quot;, ID = 3 });
failBoyUsers.Add(new Users { AwesomeScore = 7, Name = &quot;Joe&quot;, ID = 3 });
failBoyUsers.Add(new Users { AwesomeScore = 7, Name = &quot;Joe&quot;, ID = 3 });
failBoyUsers.Add(new Users { AwesomeScore = 1, Name = &quot;newbie&quot;, ID = 4 });
</pre>
<p>This would then give us a &#8220;strongly typed Array&#8221; of our User class. If we now had to call the .Distinct function on the collection it wouldn&#8217;t work! Thats because the CLR does not know what to evaluate to decide whether an entry is unique or a duplicate so it returns all the items including the duplicates. The Distinct method accepts an overload paramter, this object must implement the IEqualityComparer interface. So we declare a new class and implement IEqualityComparer as follows:</p>
<pre class="brush: csharp;">
public class AwesomeComparer : IEqualityComparer&lt;Users&gt;
{
public bool Equals(Users x, Users y)
{
if (x == null || y == null)
return false;
else
return (x.Name.ToLower() == y.Name.ToLower() &amp;&amp;
x.AwesomeScore == y.AwesomeScore &amp;&amp;
x.ID == y.ID);
}

public int GetHashCode(Users obj)
{
return obj.Name.GetHashCode();
}
}
</pre>
<p>so what we do in the Equals Method is define what we feel a duplicate of our custom class looks like. We also implement the GetHashCode method to return the hash of the &#8220;primary field&#8221;. This will usually be the Primary Key that you class will be based on. Then we implement our Distinct method, we do so as follows:</p>
<pre class="brush: csharp;">
AwesomeComparer awesomeComparer = new AwesomeComparer();

foreach (Users usr in failBoyUsers.Distinct(awesomeComparer))
{
Console.WriteLine(usr.ID.ToString() + &quot; - &quot; + usr.Name + &quot; - &quot; + usr.AwesomeScore.ToString());
}
</pre>
<p>And that will only return Distinct values from our custom class! I hope this helps someone at some stage as I never knew about this myself and stumbled onto it. Drop me a comment if you think I suck or if my some margain of luck I managed to produce some bug free code, I am after FailBoy for a reason <img src='http://www.failboy.net/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/07/linq-distinct-method/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to use Lambda Expressions</title>
		<link>http://www.failboy.net/2009/07/how-to-use-lambda-expressions/</link>
		<comments>http://www.failboy.net/2009/07/how-to-use-lambda-expressions/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 04:46:32 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Lambda]]></category>
		<category><![CDATA[Lambda Expressions]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=30</guid>
		<description><![CDATA[Until I recently started working at Chase Software I hadn&#8217;t really dived to deep into the C# 3.0 features. I really wish I had though because man it would&#8217;ve cut down so much code at my previous job. A colleague of mine has taught me so much that I am now looking a lot deeper [...]]]></description>
			<content:encoded><![CDATA[<p>Until I recently started working at <a href="http://www.chasesoftware.co.za" target="_blank">Chase Software</a> I hadn&#8217;t really dived to deep into the C# 3.0 features. I really wish I had though because man it would&#8217;ve cut down so much code at my previous job. A <a href="http://www.twitter.com/jabezzz" target="_blank">colleague of mine</a> has taught me so much that I am now looking a lot deeper into C# 3 features. Just in time before C# 4.0 is released! One of the first things I learned to get the hang of is Lambda expressions. Lambdas are inline expressions. These expressions are mainly used in conjunction with LiNQ and thus mostly on IQueryable and IEnumerable collections. Here is an example on how it can cut a lot of code out of you work.</p>
<p>Assume we have  a basic class that contains a Name, ID and AwesomeScore for Users.</p>
<pre class="brush: csharp;">public class Users
{
public int ID {get; set;}
public string Name {get; set;}
public int AwesomeScore {get; set;}
}</pre>
<p>So as you can see there&#8217;s nothing difficult about that. Its a basic class definition. So lets create a basic console application and fill a List of Users so we can work with that:</p>
<pre class="brush: csharp;">public static void Main(string[] args)
{
// Create and populate new list of Users
List&lt;Users&gt; failBoyUsers = new List&lt;Users&gt;();
failBoyUsers.Add(new Users { AwesomeScore = 7, Name = &quot;FailBoy&quot;, ID = 1 });
failBoyUsers.Add(new Users { AwesomeScore = 10, Name = &quot;Rathlan&quot;, ID = 2 });
failBoyUsers.Add(new Users { AwesomeScore = 9, Name = &quot;Joe&quot;, ID = 3 });
failBoyUsers.Add(new Users { AwesomeScore = 1, Name = &quot;newbie&quot;, ID = 4 });
}</pre>
<p>So here we create a Generic List Collection of Users. So our failBoyUsers collection now contains 4 users with varying scores. Now, originally before the wonders of learning how to use Lambda&#8217;s, I would&#8217;ve done the following to return the users with an AwesomeScore of 8 or over:</p>
<pre class="brush: csharp;">
public static List GetAwesomestPeople(List&lt;Users&gt; usersToSort)
{
List&lt;Users&gt; returnList = new List&lt;Users&gt;();

foreach (Users userItem in usersToSort)
{
if (userItem.AwesomeScore &gt;= 8 )
{
returnList.Add(userItem);
}
}

return returnList;
}</pre>
<p>So yeah, that was me, FailBoy being very intelligent. Now, that same functionality using Lambda&#8217;s.</p>
<pre class="brush: csharp;">
public static IQueryable GetAwesomestPeopleLAMBDA(IQueryable usersToSort)
{
return usersToSort.Where(user =&gt; user.AwesomeScore &gt;= 8).AsQueryable();
}
</pre>
<p>Thats right! Using Lambda&#8217;s its a single line. So lets look at that line, I pass in the usersToSort as IQueryable instead of the List. Converting from the List to IQueryable is as easy as passing the List parameter in and simply adding .AsQueryable() to the end of the parameter name! So it would be called as :</p>
<pre class="brush: csharp;">IQueryable awesomeOkes = GetAwesomestPeopleLAMBDA(failBoyUsers.AsQueryable());</pre>
<p>Then I use the .Where() method which is an extension method on the IQueryable collection class and as such on the List&lt;&gt; class since List&lt;&gt; inherits from IEnumerable and IEnumerable inherits from IQueryable. The fun comes in where I pass the argument into the .Where() method.</p>
<pre class="brush: csharp;">user =&gt; user.AwesomeScore &gt;= 8</pre>
<p>Here I am declaring a new variable called user. The variable is an instance of the Collection we want to sort, in this case usersToSort. the &#8220;=&gt;&#8221; is what is referred to as the Lambda operator. After the Lambda operator we specify our condition. In this as we only want the users with an AwesomeScore of 8 or higher. I then append the</p>
<pre class="brush: csharp;">.AsQueryable()</pre>
<p>because we want to return the resultset as an IQueryable Collection of Users.</p>
<p>Using Lambda&#8217;s I&#8217;m condensed 9 lines of code into 1 line of code. And the less you need to code, the more time you save! I hope this is helpful to you! I&#8217;ve included the full code below.</p>
<p>FailBoy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/07/how-to-use-lambda-expressions/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Unable to launch the ASP.NET Development server because port is in use.</title>
		<link>http://www.failboy.net/2009/05/unable-launch-aspnet-development-server-port-use/</link>
		<comments>http://www.failboy.net/2009/05/unable-launch-aspnet-development-server-port-use/#comments</comments>
		<pubDate>Thu, 28 May 2009 17:00:24 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[development server]]></category>
		<category><![CDATA[ESET]]></category>
		<category><![CDATA[port in use]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=28</guid>
		<description><![CDATA[Bumped into an interesting problem today. My ASP.Net Development server would not start because the port was apparently in use. I though this was very strange and tried another port, and this one was also in use. Starting to suspect spyware I was getting worried. I finally remember that I had installed ESET NOD32 Antivirus. [...]]]></description>
			<content:encoded><![CDATA[<p>Bumped into an interesting problem today. My ASP.Net Development server would not start because the port was apparently in use. I though this was very strange and tried another port, and this one was also in use. Starting to suspect spyware I was getting worried. I finally remember that I had installed ESET NOD32 Antivirus.</p>
<p>ESET comes with a little HTTP firewall as well. So easy right? Just disable the firewall, WRONG!!! Error was still occuring. So after googling for a bit I found my problem. I was right, ESET was to blame, but I hadn&#8217;t approached the situation from correct angle. To fix the situation you need to add Visual Studio to a &#8220;safe list&#8221; so that ESET doesn&#8217;t block it.</p>
<p>To unblock Visual Studio do the following: open ESET and click setup -&gt; advanced firewall setup -&gt; antivirus &amp; anti spyware -&gt; web access protection -&gt; HTTP -&gt; webbrowsers. ESET will then show a list of Applications, find VS2008/2005 in the list and deselect it. Save your changes and close the setup window.</p>
<p>And there we go, VS2008&#8242;s buildt in Dev Server will now work again!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/05/unable-launch-aspnet-development-server-port-use/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Set Forms Authentication Path dynamically</title>
		<link>http://www.failboy.net/2009/05/set-forms-authentication-path/</link>
		<comments>http://www.failboy.net/2009/05/set-forms-authentication-path/#comments</comments>
		<pubDate>Tue, 26 May 2009 17:00:41 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[path]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=26</guid>
		<description><![CDATA[Lets say we have IIS with a default website and two Virtual Directories, both containing an instance of an application. So when a user logs into Instance A and then into Instance B, he is then logged out of Instance A. In testing I saw that if I hardcoded the path attribute on the forms [...]]]></description>
			<content:encoded><![CDATA[<p>Lets say we have IIS with a default website and two Virtual Directories, both containing an instance of an application. So when a user logs into Instance A and then into Instance B, he is then logged out of Instance A. In testing I saw that if I hardcoded the path attribute on the forms tag under authentication in the web.config then the systems would work fine and not effect each other. So I set about trying to set the path dynamically but I was doing it all over and it wasn’t working.</p>
<p>My stupidity lead me into trying to set the Path on each cookie. That, however,  wasn’t the problem. A Colleague of mine found the solution this morning though. After we log the user into the system we fire the following code:</p>
<blockquote><p><code>FormsAuthentication.RedirectFromLoginPage(authToken, true);</code></p></blockquote>
<p>However the RedirectFromLoginPage does take a 3rd parameter which will be the path that I’ve been trying to set. So now the code reads:</p>
<blockquote><p><code>string applicationBasePath = Request.ApplicationPath;<br />
FormsAuthentication.RedirectFromLoginPage(authToken, chkRememberMe.Checked, applicationBasePath);</code></p></blockquote>
<p>So once that was done everything worked like a charm!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/05/set-forms-authentication-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enumerable methods .All() and .Where()</title>
		<link>http://www.failboy.net/2009/05/enumerable-methods-all-where/</link>
		<comments>http://www.failboy.net/2009/05/enumerable-methods-all-where/#comments</comments>
		<pubDate>Fri, 15 May 2009 17:00:02 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=23</guid>
		<description><![CDATA[Today I made one of my classic mistakes. I didn&#8217;t *READ* the MSDN documention on an Extension Method in its entirety. I was discussing some Enumerable extension methods with a friend and looked up the .All() extension method. Instead of reading all of the code I read how the code was implemented and jumped to [...]]]></description>
			<content:encoded><![CDATA[<p>Today I made one of my classic mistakes. I didn&#8217;t *READ* the MSDN documention on an Extension Method in its entirety. I was discussing some Enumerable extension methods with a friend and looked up the .All() extension method.</p>
<p>Instead of reading all of the code I read how the code was implemented and jumped to some conclusions. I sat ranting about how .All() and .Where() do exactly the samething and how silly that is. Once I actually sat down and read the examples properly I saw the very <em><strong>obvious</strong></em> difference. Here is the difference between the methods though.</p>
<p><em><strong>.All()</strong></em></p>
<p>The <span id="nsrTitle">Enumerable<span class="cs">.All() method </span></span>determines whether all elements of a sequence satisfy a condition according to its MSDN entry. When using this it would be implemented as follows:</p>
<p><code>users.All(user =&gt; user.Name.StartsWith("B"));</code></p>
<p>This would return a boolean value *<em><strong>ONLY</strong></em>* if all the entries in our users Enumerable had a user.Name starting with the letter &#8220;B&#8221;.</p>
<p><em><strong>.Where()</strong></em></p>
<p>The <span id="nsrTitle">Enumerable<span class="cs">.Where() method </span></span>filters a sequence of values based on a predicate according to its MSDN entry. When using this it would be implemented as follows:</p>
<p><code>IEnumerable query = users.Where(user =&gt; user.Name.StartsWith("B"));</code></p>
<p>This would return all the records where the user&#8217;s name starts with &#8220;B&#8221;</p>
<p><em><strong>I am FailBoy</strong></em></p>
<p>This is exactly why I have been named FailBoy. So often I only read parts of something and jump to conclusions. The lesson learnt, READ the manual and don&#8217;t jump to conclusions!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/05/enumerable-methods-all-where/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SqlParameter is already contained by another SqlParameterCollection</title>
		<link>http://www.failboy.net/2009/05/sqlparameter-is-already-contained-by-another-sqlparametercollection/</link>
		<comments>http://www.failboy.net/2009/05/sqlparameter-is-already-contained-by-another-sqlparametercollection/#comments</comments>
		<pubDate>Wed, 13 May 2009 17:00:50 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[SqlParameter]]></category>
		<category><![CDATA[SqlParameterCollection]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=15</guid>
		<description><![CDATA[I discovered an interesting bug today. While executing some SQL Stored Procedures via C# I was trying to reuse a SqlParameter. However, when the SqlParameter was added to a second SqlCommand, it would throw an error when trying to execute the second command. The error encountered was the &#8220;SqlParameter is already contained by another SqlParameterCollection&#8220;. [...]]]></description>
			<content:encoded><![CDATA[<p>I discovered an interesting bug today. While executing some SQL Stored Procedures via C# I was trying to reuse a SqlParameter. However, when the SqlParameter was added to a second SqlCommand, it would throw an error when trying to execute the second command. The error encountered was the &#8220;<em><strong>SqlParameter is already contained by another SqlParameterCollection</strong></em>&#8220;.</p>
<p>It seems that .Net&#8217;s garbage collection retains a reference to the SqlParameter used in the first SqlCommand. This reference seems to survive the closing and even disposing of the connection in use. As long as the SqlCommand object is in use, .Net seems to remember that it has already been used. To bypass this, simply call the <em><strong>sqlCommand.Parameters.Clear()</strong> </em>method. You&#8217;ll need to readd the SqlParameter or SqlParameter[] to the SqlCommand and it&#8217;ll work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/05/sqlparameter-is-already-contained-by-another-sqlparametercollection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Procedure expects parameter &#8216;@statement&#8217;</title>
		<link>http://www.failboy.net/2009/05/procedure-expects-parameter-statement/</link>
		<comments>http://www.failboy.net/2009/05/procedure-expects-parameter-statement/#comments</comments>
		<pubDate>Mon, 11 May 2009 18:00:55 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[procedure '@statement']]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=13</guid>
		<description><![CDATA[Recently I was working on a script to upgrade a database and was using some dynamic T-SQL to execute a command. I kept getting the error &#8220;Procedure expects parameter &#8216;@statement&#8217; of type &#8216;ntext/nchar/nvarchar&#8217;&#8221;. Being true to my name (&#8220;FailBoy&#8221;) I knew I was doing something stupid. In my SQL Script I had declared something like [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was working on a script to upgrade a database and was using some dynamic T-SQL to execute a command. I kept getting the error &#8220;Procedure expects parameter &#8216;@statement&#8217; of type &#8216;ntext/nchar/nvarchar&#8217;&#8221;. Being true to my name (&#8220;FailBoy&#8221;) I knew I was doing something stupid. In my SQL Script I had declared something like this:</p>
<blockquote><p>DECLARE @tSql VARCHAR(max)<br />
SET @tSql = &#8216;&lt;insert Dynamic query here&gt;&#8217;<br />
execute sp_executesql @tSql</p></blockquote>
<p>Can you spot the problem? The problem is the declaration of the variable as VARCHAR. The <em>execute sp_executesql</em> procedure expects a NVARCHAR value. I simply replaced the VARCHAR with NVARCHAR and all worked perfectly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/05/procedure-expects-parameter-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate class from XSD</title>
		<link>http://www.failboy.net/2009/05/generate-class-from-xsd/</link>
		<comments>http://www.failboy.net/2009/05/generate-class-from-xsd/#comments</comments>
		<pubDate>Wed, 06 May 2009 12:25:52 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Data Structures]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[XSD]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=11</guid>
		<description><![CDATA[Discovered something nice today, Microsoft has built a small tool to convert a XSD file into a code class for you. This is very very useful when need to serialize some information and using a XSD file as a base. Simply open up the Visual Studio Command Prompt and navigate to the folder that contains [...]]]></description>
			<content:encoded><![CDATA[<p>Discovered something nice today, Microsoft has built a small tool to convert a XSD file into a code class for you. This is very very useful when need to serialize some information and using a XSD file as a base. Simply open up the Visual Studio Command Prompt and navigate to the folder that contains the XSD file and enter the following:</p>
<blockquote><p>xsd /classes /language:CS XSDFileNameHere.xsd</p></blockquote>
<p>This will generate a delightful little .cs class file for you, ready to be used in your project!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/05/generate-class-from-xsd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Improve your server Garbage Collection Performance</title>
		<link>http://www.failboy.net/2009/05/improve-your-server-garbage-collection-performance/</link>
		<comments>http://www.failboy.net/2009/05/improve-your-server-garbage-collection-performance/#comments</comments>
		<pubDate>Wed, 06 May 2009 12:24:45 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Garbage Collection]]></category>
		<category><![CDATA[Servers]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=9</guid>
		<description><![CDATA[I came across a little known config of ASP.Net applications. We all know about the built-in Garbage Collection system that the .Net Framework uses to recycle &#8220;dead&#8221; or unused objects from memory and recycle the space. By default the Garbage Collector is set to &#8220;Workstation&#8221; Mode. That means the Garbage collector will be efficient on [...]]]></description>
			<content:encoded><![CDATA[<p>I came across a little known config of ASP.Net applications. We all know about the built-in Garbage Collection system that the .Net Framework uses to recycle &#8220;dead&#8221; or unused objects from memory and recycle the space. By default the Garbage Collector is set to &#8220;Workstation&#8221; Mode. That means the Garbage collector will be efficient on a machine with a single processor and little RAM. This is usually the case on most developer PCs. However, when we deploy our applications to the server we usually have hugely powerful servers that have multiple cores and gigs of RAM. On these servers we should enable the Garbage Collection to run on Server Mode. The application will be more CPU and RAM intensive but the garbage collection will be a lot more responsive and active in monitering the objects currently in memory. To do this, in your web.config you need to add the following section:</p>
<blockquote>
<pre id="ctl00_rs1_mainContentContainer_ctl20other" class="libCScode">&lt;configuration&gt;
   &lt;runtime&gt;
      &lt;gcServer enabled="true"/&gt;
   &lt;/runtime&gt;
&lt;/configuration&gt;</pre>
</blockquote>
<p>Why should you enable this though? How does it benefit your application? It comes down to the performance of your application on the server. Not how quick your page loads, but how well your application handles large volumes of traffic without your application falling over and dying. Here&#8217;s why! Server Garbage Collection creates one GC heap per processor, which are collected in parallel. This GC mode maximizes the number of requests per second. So imagine having a server with 4 gigs of RAM and a quad core CPU, your application would be able to withstand much larger amounts of traffic without the application running over of memory! Effectively, on a quad core CPU, you would have 4 Garbage Collectors working in unison!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/05/improve-your-server-garbage-collection-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#: TinyUrl conversion code</title>
		<link>http://www.failboy.net/2009/05/c-tinyurl-conversion-code/</link>
		<comments>http://www.failboy.net/2009/05/c-tinyurl-conversion-code/#comments</comments>
		<pubDate>Wed, 06 May 2009 12:23:49 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[TinyUrl]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=7</guid>
		<description><![CDATA[I am currently working on a small project using ASP.Net MVC and I want to incorporate a TinyUrl facility such as that of www.tinyurl.com and the million other clones there are. I found this awesome piece of code that does the trick beautifully! I found the code @ http://blogs.msdn.com/bramveen/archive/2009/01/06/converting-url-to-tinyurl-in-c.aspx It was really quick to implement [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently working on a small project using ASP.Net MVC and I want to incorporate a TinyUrl facility such as that of www.tinyurl.com and the million other clones there are. I found this awesome piece of code that does the trick beautifully! I found the code @ <a title="TinyUrl code" href="http://blogs.msdn.com/bramveen/archive/2009/01/06/converting-url-to-tinyurl-in-c.aspx" target="_blank">http://blogs.msdn.com/bramveen/archive/2009/01/06/converting-url-to-tinyurl-in-c.aspx</a></p>
<p>It was really quick to implement and works really nicely.</p>
<pre class="code"><span style="color: blue;">protected string </span>ToTinyURLS(<span style="color: blue;">string </span>txt)
{
    <span style="color: #2b91af;">Regex </span>regx = <span style="color: blue;">new </span><span style="color: #2b91af;">Regex</span>(<span style="color: #a31515;">"http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&amp;amp;\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?"</span>, <span style="color: #2b91af;">RegexOptions</span>.IgnoreCase);

    <span style="color: #2b91af;">MatchCollection </span>mactches = regx.Matches(txt);

    <span style="color: blue;">foreach </span>(<span style="color: #2b91af;">Match </span>match <span style="color: blue;">in </span>mactches)
    {
        <span style="color: blue;">string </span>tURL = MakeTinyUrl(match.Value);
        txt = txt.Replace(match.Value, tURL);
    }

    <span style="color: blue;">return </span>txt;
}

<span style="color: blue;">public static string </span>MakeTinyUrl(<span style="color: blue;">string </span>Url)
{
    <span style="color: blue;">try
    </span>{
        <span style="color: blue;">if </span>(Url.Length &lt;= 12)
        {
            <span style="color: blue;">return </span>Url;
        }
        <span style="color: blue;">if </span>(!Url.ToLower().StartsWith(<span style="color: #a31515;">"http"</span>) &amp;&amp; !Url.ToLower().StartsWith(<span style="color: #a31515;">"ftp"</span>))
        {
            Url = <span style="color: #a31515;">"http://" </span>+ Url;
        }
        <span style="color: blue;">var </span>request = <span style="color: #2b91af;">WebRequest</span>.Create(<span style="color: #a31515;">"http://tinyurl.com/api-create.php?url=" </span>+ Url);
        <span style="color: blue;">var </span>res = request.GetResponse();
        <span style="color: blue;">string </span>text;
        <span style="color: blue;">using </span>(<span style="color: blue;">var </span>reader = <span style="color: blue;">new </span><span style="color: #2b91af;">StreamReader</span>(res.GetResponseStream()))
        {
            text = reader.ReadToEnd();
        }
        <span style="color: blue;">return </span>text;
    }
    <span style="color: blue;">catch </span>(<span style="color: #2b91af;">Exception</span>)
    {
        <span style="color: blue;">return </span>Url;
    }
}</pre>
<p>Hope this can as useful to you as it was for me!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/05/c-tinyurl-conversion-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert LiNQ resultset to DataTable</title>
		<link>http://www.failboy.net/2009/05/convert-linq-resultset-to-datatable/</link>
		<comments>http://www.failboy.net/2009/05/convert-linq-resultset-to-datatable/#comments</comments>
		<pubDate>Wed, 06 May 2009 12:22:27 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[DataTable]]></category>
		<category><![CDATA[ExtensionMethod]]></category>
		<category><![CDATA[Linq]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=5</guid>
		<description><![CDATA[When the LiNQ to SQL framework was originally released in BETA there was a built in extension method to convert the LiNQ result to either a DataTable or DataSet if I remember correctly. However when it came to release this disappeared for some strange reason. Now I&#8217;m sure MS had their reasons for removing it [...]]]></description>
			<content:encoded><![CDATA[<p>When the LiNQ to SQL framework was originally released in BETA there was a built in extension method to convert the LiNQ result to either a DataTable or DataSet if I remember correctly. However when it came to release this disappeared for some strange reason.</p>
<p>Now I&#8217;m sure MS had their reasons for removing it but I don&#8217;t care and want it back <img src='http://www.failboy.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  So I&#8217;ve written a little extension method to convert the LiNQ resultset to a DataTable using a bit of Reflection. Here&#8217;s the code and enjoy! As always, I take no responsibility for its usage <img src='http://www.failboy.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<blockquote><p>/// &lt;summary&gt;<br />
/// Converts an IEnumerable type collection into a DataTable<br />
/// &lt;/summary&gt;<br />
/// &lt;param name=&#8221;collection&#8221;&gt;Collection type that implements IEnumberable&lt;/param&gt;<br />
/// &lt;returns&gt;Datatable representing IEnumerable collection&lt;/returns&gt;<br />
public static DataTable ToDataTable&lt;T&gt;(this IEnumerable&lt;T&gt;collection)<br />
{<br />
// Create DataTable to Fill<br />
DataTable _newDataTable = new DataTable();</p>
<p>// Retrieve the Type passed into the Method<br />
Type _impliedType = typeof(T);</p>
<p>//Get an array of the Type&#8217;s properties<br />
PropertyInfo[] _propInfo = _impliedType.GetProperties();</p>
<p>//Create the columns in the DataTable<br />
foreach (PropertyInfo pi in _propInfo)<br />
{<br />
_newDataTable.Columns.Add(pi.Name, pi.PropertyType);<br />
}</p>
<p>//Populate the table<br />
foreach (T item in collection)<br />
{<br />
DataRow _newDataRow = _newDataTable.NewRow();<br />
_newDataRow.BeginEdit();</p>
<p>foreach (PropertyInfo pi in _propInfo)<br />
{<br />
_newDataRow[pi.Name] = pi.GetValue(item, null);<br />
}</p>
<p>_newDataRow.EndEdit();<br />
_newDataTable.Rows.Add(_newDataRow);<br />
}</p>
<p>return _newDataTable;<br />
}</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/05/convert-linq-resultset-to-datatable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encrypting SQL connection string</title>
		<link>http://www.failboy.net/2009/05/encrypting-sql-connection-string/</link>
		<comments>http://www.failboy.net/2009/05/encrypting-sql-connection-string/#comments</comments>
		<pubDate>Wed, 06 May 2009 12:19:43 +0000</pubDate>
		<dc:creator>FailBoy</dc:creator>
				<category><![CDATA[Best Practice]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Connection Strings]]></category>

		<guid isPermaLink="false">http://www.failboy.net/?p=3</guid>
		<description><![CDATA[This is something that is so easy to configure yet I’ve seen it countless times where projects are deployed and the connection string in the web.config file is not encrypted. Regardless of how small your application is, it poses a challenge to someone somewhere to try break into it. Here I’ll show you something most [...]]]></description>
			<content:encoded><![CDATA[<p>This is something that is so easy to configure yet I’ve seen it countless times where projects are deployed and the connection string in the web.config file is not encrypted. Regardless of how small your application is, it poses a challenge to someone somewhere to try break into it. Here I’ll show you something most people don’t even know about and depending on your code in your projects Data Access Layer you might not even need to change your code at all!</p>
<p><span style="text-decoration: underline;"><strong>ASPNET_regiis</strong></span>:</p>
<p>When you initially install the .Net Framework, if you look carefully, you’ll see this little executable run. The aspnet_regiis executable is there to register the ASP.Net runtimes with IIS6 and you can use this to install Sql Server State Management on a web application. There is however some very interesting other things this little executable can do for you. One of which being automatically encrypting and decrypting your connection string in your website’s web.config file.</p>
<p><span style="text-decoration: underline;"><strong>Encryption time</strong></span>:</p>
<p>Say for instance you have the following connection string in your web.config file. From this, your attacker would know exactly where your database server is located as well a valid username and password.</p>
<blockquote><p>&lt;configuration&gt;<br />
&lt;connectionStrings&gt;<br />
&lt;add name=&#8221;SqlConn&#8221; connectionString=&#8221;Server=dbServer; Database=pubs;<br />
User Id=usrName; password= p4ssw0rd&#8221; providerName=<br />
&#8220;System.Data.SqlClient&#8221; /&gt;<br />
&lt;/connectionStrings&gt;<br />
&lt;/configuration&gt;</p></blockquote>
<p>To make sure your SQL location and account credentials stay secret, you should encrypt the connection string in the web.config file using the Aspnet_regiis utility with at least the Windows Data Protection API (DPAPI) protected configuration provider. By executing the following command in your Visual Studio Command Prompt, you will have successfully encrypted your connection string!</p>
<blockquote><p><strong>aspnet_regiis -pe &#8220;connectionStrings&#8221; -app &#8220;/WebApp&#8221; –prov &#8220;DataProtectionConfigurationProvider&#8221;</strong></p></blockquote>
<p>Just remember that this command is cAsE SeNsItIve. Remember to set /WebApp to the virtual path to your application.</p>
<p><span style="text-decoration: underline;"><strong>Decrypting the Connection String</strong></span>:</p>
<p>This is the easiest part of all. When you retrieve your connection string from the web.config file, this is how you should do it:</p>
<blockquote><p><strong>string dbConn = ConfigurationManager.ConnectionString["SqlConn"].ToString();</strong></p></blockquote>
<p>By doing it this way, ASP.Net will automatically decrypt the connection string for you! This is recommended as a Best Practice by Microsoft and it is incredibly easy to implement. There is no excuse to not implement such basic security in your web based applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.failboy.net/2009/05/encrypting-sql-connection-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
