<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>.NET articles</title>
        <link>http://www.sharpdeveloper.net/content/category/1.aspx</link>
        <description>C# and VB.Net articles, posts, tips, tutorials. We plan to regularly add new articles and posts on improving your code quality.  Topics include strings, enumerations, proper architecture, source control systems, and proper OOP, possibly agile development articles as well.</description>
        <language>en-US</language>
        <copyright>Sameer Alibhai</copyright>
        <managingEditor>abdullah.adam@gmail.com</managingEditor>
        <generator>Subtext Version 1.9.5.176</generator>
        <item>
            <title>Updating Your Web.Config From Each Build with CruiseControl</title>
            <link>http://sharpdeveloper.net/content/archive/2008/06/17/updating-your-web.config-from-each-build-with-cruisecontrol.aspx</link>
            <description>&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;Let's say you have CruiseControl.NET all set up nice and hunky dory.  Now you love the fact that it labels your each build, and you want to somehow show that from your project.  Here is how you can get your CruiseControl.NET project build number into your Web.Config.  This concept can be applied to update any file.&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;It’s super easy. You will need to add an exec block to your ccnet.config&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: 0.5in"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: #a31515"&gt;exec&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;                         &amp;lt;!--&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: green"&gt; Auto increment web.config build number &lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;--&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;                        &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: #a31515"&gt;executable&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt"&gt;E:\Userdata\CruiseControl\Tools\MergeWebConfigValues.exe (my custom tool)&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;executable&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;                        &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: #a31515"&gt;buildArgs&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt"&gt;"E:\Program Files (x86)\CruiseControl.NET\server\Main.state" e:\userdata\cruisecontrol\Dev_Main\Web.config&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;buildArgs&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;                        &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: #a31515"&gt;baseDirectory&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt"&gt;e:\userdata\cruisecontrol\Dev_Main&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;baseDirectory&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;                        &amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: #a31515"&gt;buildTimeoutSeconds&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt"&gt;15&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;buildTimeoutSeconds&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;                  &amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: #a31515"&gt;exec&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; Now all you need to do is write the &lt;strong&gt;MergeWebConfigValues.exe&lt;/strong&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;What does it do?&lt;br /&gt;
1. It reads the CCNET state file (provided by argument 1) and grabs the last label from there. (The state file is an XML file)&lt;br /&gt;
2. It then goes and writes to your Web.Config and updates the build number in there. (or writes to any specified file you like)&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;Lastly, update your code to read this value by adding some version or about page to read your Web.Config&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;br /&gt;
You now instantly know what version your code is.&lt;/div&gt;&lt;img src="http://sharpdeveloper.net/content/aggbug/69.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sameer Alibhai</dc:creator>
            <guid>http://sharpdeveloper.net/content/archive/2008/06/17/updating-your-web.config-from-each-build-with-cruisecontrol.aspx</guid>
            <pubDate>Tue, 17 Jun 2008 23:10:32 GMT</pubDate>
            <wfw:comment>http://sharpdeveloper.net/content/comments/69.aspx</wfw:comment>
            <comments>http://sharpdeveloper.net/content/archive/2008/06/17/updating-your-web.config-from-each-build-with-cruisecontrol.aspx#feedback</comments>
            <wfw:commentRss>http://sharpdeveloper.net/content/comments/commentRss/69.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Unit Testing on Your Database</title>
            <link>http://sharpdeveloper.net/content/archive/2008/05/22/unit-testing-on-your-database.aspx</link>
            <description>&lt;p&gt;When unit testing on your database, you will run into a common problem.&lt;/p&gt;
&lt;p&gt;Rolling back.&lt;/p&gt;
&lt;p&gt;So you want to do some unit tests, and then you want to reset your database back to the nice squeaky clean version that doesn't have half failed unit tests.&lt;/p&gt;
&lt;p&gt;So how can you do this?&lt;/p&gt;
&lt;p&gt;There are many ways to achieve this.&lt;/p&gt;
&lt;p&gt;The best way I found (requires Win XP SP2 or Windows Server 2003) is to use Roy's Unit Testing Rollback Attribute.  Simply inherit his class, add a "DataRollback" attribute, and you are good to go.  Using some complicated Interception logic and Enterprise Services (COM+) it rolls back all the database work that was done.  It's super easy to implement.  Here is some sample code that shows you just how easy it is.  You just have to download &lt;a href="http://weblogs.asp.net/rosherove/archive/2004/07/20/187863.aspx"&gt;XtUnit&lt;/a&gt; (an extension to NUnit) to do this. (Full source code available)&lt;/p&gt;
&lt;div&gt;&lt;font color="#0000ff" size="2"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;using&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt; System;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#0000ff" size="2"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;using&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt; System.Data;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#0000ff" size="2"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;using&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt; System.Collections.Generic;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#0000ff" size="2"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;using&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt; System.Text;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;font color="#0000ff" size="2"&gt;&lt;span style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: blue"&gt;using&lt;/span&gt;&lt;/font&gt;&lt;/strong&gt;&lt;strong&gt;&lt;font size="2"&gt;&lt;span style="FONT-WEIGHT: bold; FONT-SIZE: 10pt"&gt; TeamAgile.ApplicationBlocks.Interception.UnitTestExtensions;&lt;/span&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#0000ff" size="2"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;using&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt; NUnit.Framework;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#0000ff" size="2"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;using&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt; System.Data.SqlClient;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#0000ff" size="2"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;using&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt; Microsoft.ApplicationBlocks.Data;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#0000ff" size="2"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;namespace&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt; DBTest&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;{&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    &lt;font color="#808080"&gt;&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    &lt;font color="#808080"&gt;&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;/font&gt;&lt;font color="#008000"&gt;&lt;span style="COLOR: green"&gt; Test roll back functionality.&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    &lt;font color="#808080"&gt;&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;/font&gt;&lt;font color="#808080"&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    [&lt;font color="#2b91af"&gt;&lt;span style="COLOR: #2b91af"&gt;TestFixture&lt;/span&gt;&lt;/font&gt;]&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    &lt;font color="#0000ff"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;&lt;span style="COLOR: blue"&gt;class&lt;/span&gt;&lt;/font&gt; &lt;font color="#2b91af"&gt;&lt;span style="COLOR: #2b91af"&gt;RollbackTest&lt;/span&gt;&lt;/font&gt; : &lt;strong&gt;&lt;font color="#2b91af"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #2b91af"&gt;ExtensibleFixture&lt;/span&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    {&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;        [&lt;font color="#2b91af"&gt;&lt;span style="COLOR: #2b91af"&gt;Test&lt;/span&gt;&lt;/font&gt;, &lt;strong&gt;&lt;font color="#2b91af"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #2b91af"&gt;DataRollBack&lt;/span&gt;&lt;/font&gt;&lt;/strong&gt;]&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;        [&lt;font color="#2b91af"&gt;&lt;span style="COLOR: #2b91af"&gt;Category&lt;/span&gt;&lt;/font&gt;(&lt;font color="#a31515"&gt;&lt;span style="COLOR: #a31515"&gt;"Database"&lt;/span&gt;&lt;/font&gt;)]&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;        &lt;font color="#0000ff"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;/font&gt; &lt;font color="#0000ff"&gt;&lt;span style="COLOR: blue"&gt;void&lt;/span&gt;&lt;/font&gt; TestInsert()&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;        {&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;            &lt;font color="#008000"&gt;&lt;span style="COLOR: green"&gt;//this method will be performed inside a COM+ transaction&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;            &lt;font color="#008000"&gt;&lt;span style="COLOR: green"&gt;//this requires windows XP SP2 or better&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;            &lt;font color="#008000"&gt;&lt;span style="COLOR: green"&gt;//Windows Server 2003 works as well.&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#008000" size="2"&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;            &lt;font color="#0000ff"&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;/font&gt; strCnn = &lt;font color="#a31515"&gt;&lt;span style="COLOR: #a31515"&gt;"your_conn_string"&lt;/span&gt;&lt;/font&gt;;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;            &lt;font color="#2b91af"&gt;&lt;span style="COLOR: #2b91af"&gt;Guid&lt;/span&gt;&lt;/font&gt; random = &lt;font color="#2b91af"&gt;&lt;span style="COLOR: #2b91af"&gt;Guid&lt;/span&gt;&lt;/font&gt;.NewGuid();&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;            &lt;font color="#0000ff"&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;/font&gt; sqlI = &lt;font color="#0000ff"&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;/font&gt;.Format(&lt;font color="#a31515"&gt;&lt;span style="COLOR: #a31515"&gt;@"insert into log4net (message,date,thread,level,logger) values ('{0}',getdate(),'{1}','Debug','Test')"&lt;/span&gt;&lt;/font&gt;, random.ToString(), System.Threading.&lt;font color="#2b91af"&gt;&lt;span style="COLOR: #2b91af"&gt;Thread&lt;/span&gt;&lt;/font&gt;.CurrentThread.GetHashCode());&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;            &lt;font color="#2b91af"&gt;&lt;span style="COLOR: #2b91af"&gt;SqlHelper&lt;/span&gt;&lt;/font&gt;.ExecuteNonQuery(strCnn, &lt;font color="#2b91af"&gt;&lt;span style="COLOR: #2b91af"&gt;CommandType&lt;/span&gt;&lt;/font&gt;.Text, sqlI);&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;            &lt;font color="#0000ff"&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;/font&gt; sqlS = &lt;font color="#0000ff"&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;/font&gt;.Format(&lt;font color="#a31515"&gt;&lt;span style="COLOR: #a31515"&gt;@"select count(*) from log4net where message='{0}'"&lt;/span&gt;&lt;/font&gt;, random.ToString());&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;            &lt;font color="#0000ff"&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;/font&gt; rowcount = (&lt;font color="#0000ff"&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;/font&gt;)&lt;font color="#2b91af"&gt;&lt;span style="COLOR: #2b91af"&gt;SqlHelper&lt;/span&gt;&lt;/font&gt;.ExecuteScalar(strCnn, &lt;font color="#2b91af"&gt;&lt;span style="COLOR: #2b91af"&gt;CommandType&lt;/span&gt;&lt;/font&gt;.Text, sqlS);&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;            &lt;font color="#2b91af"&gt;&lt;span style="COLOR: #2b91af"&gt;Assert&lt;/span&gt;&lt;/font&gt;.That(rowcount &amp;gt; 0, &lt;font color="#a31515"&gt;&lt;span style="COLOR: #a31515"&gt;"Cannot find {0}"&lt;/span&gt;&lt;/font&gt;, random.ToString());&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;        }&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    }&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;}&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;This test passes successfully.  What does that mean? The insert and select worked perfectly fine.  After that, I did a query and found the database to be clean.  So the rollback worked too.&lt;/span&gt;&lt;/font&gt; &lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;There are also other ways to skin this cat (i.e. to achieve this goal).  One is to use Spring Framework and extend their Unit Testing class (&lt;em&gt;AbstractTransactionalSpringContextTests&lt;/em&gt;), and they will handle rolling back everything.  Here is &lt;a href="http://www.cnblogs.com/taotao/archive/2007/08/20/862840.html"&gt;an article on this topic&lt;/a&gt;, but unfortunately I was not able to make it work for me due to some odd reason.  Here's hoping you have better luck.  If you don't have any transactions, and your code is wired to use Spring, it's still also very easy, you just need to call &lt;a href="http://www.sharpdeveloper.net/content/archive/2008/04/30/manage-your-transaction-chaos-with-spring-framework.aspx"&gt;TransactionManager.Rollback&lt;/a&gt;.&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;/span&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;You can also try to achieve this using Nested Transactions if you have existing transactions implemented via Spring.  But then you have to set up checkpoints and stuff like that.  &lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;I have some other ideas on how to achieve this that I will post later, God willing.&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font size="2"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;/span&gt;&lt;/font&gt;&lt;/div&gt;&lt;img src="http://sharpdeveloper.net/content/aggbug/67.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sameer Alibhai</dc:creator>
            <guid>http://sharpdeveloper.net/content/archive/2008/05/22/unit-testing-on-your-database.aspx</guid>
            <pubDate>Thu, 22 May 2008 22:09:58 GMT</pubDate>
            <wfw:comment>http://sharpdeveloper.net/content/comments/67.aspx</wfw:comment>
            <comments>http://sharpdeveloper.net/content/archive/2008/05/22/unit-testing-on-your-database.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://sharpdeveloper.net/content/comments/commentRss/67.aspx</wfw:commentRss>
        </item>
        <item>
            <title>PHP VS. ASP.NET</title>
            <link>http://sharpdeveloper.net/content/archive/2008/05/08/php-vs.-asp.net.aspx</link>
            <description>&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;This is a very shallow comparison of my experiences with PHP and ASP.NET&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;Don’t take this as a religious war or something, the idea is just some basic comparison.&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;Here is a summary: If you are choosing which technology to use to build an application, use .NET. You will get more bang for the buck. With the same effort you will be able to build a much more rich user interface. &lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;My Disclaimer: Keep in mind there are a lot of great libraries and tools for PHP which I never got to use, I just had a simple PSPad text editor and my handy PHP web site.  I really wanted some “Intellisense” style code completion but I could not get it to work with PHP since I couldn’t find a decent IDE (i.e. editor)&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;However, it all depends on your requirements. For example, if you are selling something that most of your customers will be on a shared linux hosting environment, then why would you use .NET ? A good example is the software Clipshare, which is a clone of Youtube. The sites purchasing this product are mainly shared hosting customers who have PHP but not .NET. And Mono (.NET port on Linux) is not yet stable or popular enough to use.&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;I did some PHP programming before I started doing .NET fulltime. Before then I couldn’t say much about it, but after working with .NET for a few years now, I have much to say.&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;.NET does a very good job in handling the whole life cycle. With PHP you have to do it manually.   For example, there is no such concept of “Postback” with PHP. This is such a basic thing that you can easily check with .NET to see if the page has been submitted and what button was pressed. For example if your “btnSubmit” was pressed, it will call btnSubmit_Click. With PHP, you have to do this manually. Not to mention how mish mashed your PHP page can be in terms of mixed code and style/HTML elements.&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;br /&gt;
How about caching? I wanted to implement caching with PHP and I had a fun time, I had to check if the cached output file existed, and then if so, then check how old it is, and so on... Yeah okay again maybe there are some nice components already done for this, but I didn’t have to look very hard to do it with .NET, I simply added a CacheDependency on an XML file (or whatever the case was), and BOOM! It regenerated the file whenever necessary.&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;How about reusable components? With .NET you can create ASCX (Custom Controls) that you can place within a page that expose certain properties and the control itself maintains its state, can have buttons, etc, etc.&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;br /&gt;
How about master pages (i.e. templates) in .NET? Again, super cool reusability! You can create pages with repeatable parts, with headers, footers, all sorts of fun stuff.&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;&lt;br /&gt;
I can go on and on...  but in general, the more I use .NET, the more impressed I am with it. However, what makes it not-so-practical is how expensive Windows Server hosting is.  In summary .NET kicks butt!&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;&lt;img src="http://sharpdeveloper.net/content/aggbug/66.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sameer Alibhai</dc:creator>
            <guid>http://sharpdeveloper.net/content/archive/2008/05/08/php-vs.-asp.net.aspx</guid>
            <pubDate>Thu, 08 May 2008 21:42:05 GMT</pubDate>
            <wfw:comment>http://sharpdeveloper.net/content/comments/66.aspx</wfw:comment>
            <comments>http://sharpdeveloper.net/content/archive/2008/05/08/php-vs.-asp.net.aspx#feedback</comments>
            <slash:comments>6</slash:comments>
            <wfw:commentRss>http://sharpdeveloper.net/content/comments/commentRss/66.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Manage your transaction chaos with Spring Framework</title>
            <link>http://sharpdeveloper.net/content/archive/2008/04/30/manage-your-transaction-chaos-with-spring-framework.aspx</link>
            <description>&lt;p&gt;Spring is a popular framework available in Java.  It has also been published in .NET and is called &lt;a href="http://www.springframework.net/"&gt;Spring.NET&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This framework is huge, but what I wanted to focus on is the section that deals with &lt;strong&gt;transaction management.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you have ever worked with Transactions, (say SQLTransactions), you would realize how messy it can be when you have to keep your connection open and pass around a transaction to many different functions that are making updates or queries, and then you might make a small little change and find out you forgot to use the transaction object and you caused a deadlock!&lt;/p&gt;
&lt;p&gt;How can you fix this?  By having a generic transaction/connection object?  Well, that's one way.. but how about using the Spring.NET framework to deal with the transactions?&lt;br /&gt;
&lt;br /&gt;
Spring.NET allows you to specify when you need a transaction, and you would begin and end the transaction.  However, when you do the actual database calls, you would not pass any connection string, it would automatically use the transaction in process if there is one, or if not needed then it would use a regular connection and disconnect after the query is complete.&lt;/p&gt;
&lt;p&gt;Here is a code snippet to demonstrate programmative transaction management, taken from the Spring.NET source code (yeah its open source!)&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;pre class="csharpcode"&gt;[Test]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ExecuteTransactionManager()
        {
            DefaultTransactionDefinition def = &lt;span class="kwrd"&gt;new&lt;/span&gt; DefaultTransactionDefinition();
            def.PropagationBehavior = TransactionPropagation.Required;

            &lt;span class="rem"&gt;//TODO change to property of name TransactionStatus...&lt;/span&gt;
            ITransactionStatus status = transactionManager.GetTransaction(def);
            
            &lt;span class="kwrd"&gt;int&lt;/span&gt; iCount = 0;
            &lt;span class="kwrd"&gt;try&lt;/span&gt;
            {
                iCount = (&lt;span class="kwrd"&gt;int&lt;/span&gt;)&lt;strong&gt;adoOperations.ExecuteScalar&lt;/strong&gt;(CommandType.Text, &lt;span class="str"&gt;"SELECT COUNT(*) FROM TestObjects"&lt;/span&gt;);
                &lt;span class="rem"&gt;/*&lt;/span&gt;
&lt;span class="rem"&gt;                IAdoCommand cmd = new AdoCommand(dbProvider, CommandType.Text);&lt;/span&gt;
&lt;span class="rem"&gt;                cmd.CommandText = "SELECT COUNT(*) FROM TestObjects";&lt;/span&gt;
&lt;span class="rem"&gt;                iCount = (int)&lt;strong&gt;cmd.ExecuteScalar();&lt;/strong&gt;&lt;/span&gt;
&lt;span class="rem"&gt;                */&lt;/span&gt;

                &lt;span class="rem"&gt;//other AdoCommands can be executed within same tx.&lt;/span&gt;
            } &lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception e)
            {
                transactionManager.Rollback(status);
                &lt;span class="kwrd"&gt;throw&lt;/span&gt; e;
            }
            transactionManager.Commit(status);
            Assert.AreEqual(2, iCount);

        }&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;As you can see from this code, the adoOperations.ExecuteScalar does not have any connection string passed to it.  Same thing with ExecuteDataSet, and so on.  &lt;/p&gt;
&lt;p&gt;This actually saves you a lot of headache, as you just have to make sure you use the spring DataOperations object.  The easiest way to implement this on a ASP.NET site is to put these objects as a static variable and initialize them on Application_Load.  Just an idea but it should work.  &lt;/p&gt;
&lt;p&gt; If you want to do more digging, Spring.NET has tons of stuff, it seems to mostly focus on Dependency Injection and loose coupling of code from objects from the data layer.  I really like it and I recommend you give it a shot.&lt;/p&gt;
&lt;p&gt;It's proven itself in Java and I think this framework is going to prove itself in .NET as well.  At the very least the source code is a prime example of a clean object oriented well designed application with full unit tests and sample code, XML documentation, thorough use of interfaces and inheritance, and even ORM (object relational mapping) using NHibernate (again a popular Java framework which has come into .NET)&lt;/p&gt;
&lt;p&gt; Update: I called this "declarative transaction management", actually its "programmative transaction management". - FIXED&lt;/p&gt;&lt;img src="http://sharpdeveloper.net/content/aggbug/64.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sameer Alibhai</dc:creator>
            <guid>http://sharpdeveloper.net/content/archive/2008/04/30/manage-your-transaction-chaos-with-spring-framework.aspx</guid>
            <pubDate>Wed, 30 Apr 2008 22:51:24 GMT</pubDate>
            <wfw:comment>http://sharpdeveloper.net/content/comments/64.aspx</wfw:comment>
            <comments>http://sharpdeveloper.net/content/archive/2008/04/30/manage-your-transaction-chaos-with-spring-framework.aspx#feedback</comments>
            <wfw:commentRss>http://sharpdeveloper.net/content/comments/commentRss/64.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Convert your site from VB.NET to C#</title>
            <link>http://sharpdeveloper.net/content/archive/2008/02/12/convert-from-vb.net-to-csharp-code.aspx</link>
            <description>If you are tired of the headaches of using VB.NET code, and want to convert it to C#.. Here is a nice way to do it and get the comments too.  &lt;br /&gt;
&lt;br /&gt;
Why would you do that?  Well if I have to explain to you, then you probably don't need to do it.  One big reason for me is that VB.NET does not support multi line strings.  You have to keep putting "&lt;span style="FONT-WEIGHT: bold"&gt; &amp;amp; _  &lt;/span&gt;at the end of each line making it very difficult to go back and forth from another program with strings.  You could technically create a tool to do this for you but that's so silly.   Another thing is I really like using &lt;span style="FONT-WEIGHT: bold"&gt;??&lt;/span&gt; operator in C#, for example txtLocation.Text = (GetLocation() ?? "").ToString() will ensure that even if SomeFunction returns null, this will always give you at least empty string..  I like to use this in cases where I am getting null and its a text box I am setting the text for.&lt;br /&gt;
&lt;br /&gt;
Another reason is that VB.NET code doesn't force you to &lt;span style="FONT-STYLE: italic"&gt;type &lt;/span&gt;your variables properly, so everything is an object unless you specify, or unless you put on &lt;span style="FONT-WEIGHT: bold"&gt;Option Strict&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
One way to do it is to use Reflector + Code generation add-in, but you will lose the comments and maybe even variable names because it uses the intermediate language (IL) from the DLL to re-make the source, so it's pretty useless to do it this way if you want to keep your code in the long run.&lt;br /&gt;
&lt;br /&gt;
The way I like is to use a site such as &lt;a href="http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx"&gt;http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Keep in mind I know there are other tools available that you can pay for, and some that are free too, but this is a quick and easy way to do it at work without requiring any installation.&lt;br /&gt;
&lt;br /&gt;
Once you perform the conversion, the code will still have some things that need to be manually converted.&lt;br /&gt;
One thing is this site does not compile the code, so it does not know if the VB code .Rows(5) is actually a function call called Rows with a parameter 5, or its an array index [5].  So you will need to fix these manually.&lt;br /&gt;
&lt;br /&gt;
Same thing with Tables[], Session[], etc. &lt;br /&gt;
Sometimes with VB code you will see .Item being used when no such thing exists in C#, you just use the square brackets to get the item directly such as .Rows.Item(5) in VB.NET is equal to .Rows[5] in C#&lt;br /&gt;
&lt;br /&gt;
Here is how you can search and replace these with a regular expression.&lt;br /&gt;
&lt;br /&gt;
&lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;font face="Arial" size="2"&gt;&lt;span style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Search: \({(["|a-z|A-Z|,|0-9|\:|\.|_])+}\)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;font face="Arial" size="2"&gt;&lt;span style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Replace: [\1]&lt;/span&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;strong&gt;&lt;font face="Arial" size="2"&gt;&lt;span style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;You have to do this manually and confirm each one.. Or make it more smart by searching for keywords such as QueryString, Cookie, Value, etc.. and replace all, then do the rest manually&lt;br /&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;div class="Section1"&gt;And again if you want to do them all at once, I wold recommend improving this search to find Rows, Tables, etc.. Also if you have declared an instance of a DataRow object or any other array type object, you will need to search for those as well. &lt;/div&gt;
&lt;div class="Section1"&gt;&lt;/div&gt;
&lt;div class="Section1"&gt;Keep in mind its not perfect.  For example I did not put any numbers in my search, so it will miss some of the results.  You might need to tweak it a bit and add |&lt;span style="FONT-WEIGHT: bold"&gt;0-9&lt;/span&gt; to the first set of brackets which means OR 0-9&lt;strong&gt;&lt;font face="Arial" size="2"&gt;&lt;span style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;p&gt;The next thing is that functions such as .InStr are not supported directly from C#, you need to call Microsoft.VisualBasic.Strings.InStr(...)   The code converter will automatically do this, but you need to add using Microsoft.VisualBasic.Strings to the top of your class file.&lt;br /&gt;
&lt;br /&gt;
There are a few more things I could mention, but just try it out and see how it goes. &lt;br /&gt;
&lt;br /&gt;
Here is a few more things&lt;br /&gt;
1) "my string" &amp;amp; " is very long" will give an error while converting. Before you run the converter, replace these &lt;span style="FONT-WEIGHT: bold"&gt;&amp;amp; &lt;/span&gt;in your VB code with &lt;span style="FONT-WEIGHT: bold"&gt;+&lt;/span&gt; instead.&lt;br /&gt;
2) the functions that have &lt;span style="FONT-WEIGHT: bold"&gt;handles&lt;/span&gt; such as lstItems_SelectedIndexChanged(...) &lt;span style="FONT-WEIGHT: bold"&gt;handles lstItems.SelectedIndexChanged &lt;/span&gt;need to be taken care of by putting either an event in the ASPX page in the &amp;lt;DropDownList OnSelectedIndexChanged="lstItems_SelectedIndexChanged"&lt;/p&gt;
&lt;p&gt;Also, they might be private, so you need to make them protected.  Here's a regexp to start you off:&lt;br /&gt;
&lt;font face="Arial"&gt;find: &lt;strong&gt;{(protected|private)} void {(lnk|lst)}&lt;br /&gt;
&lt;/strong&gt;replace with: &lt;strong&gt;public void \2&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
3) Functions that have optional parameters need to be taken care of.  An easy way to take care of this is to create another function that calls the second one that passes the default value with the same name. That easy!&lt;br /&gt;
&lt;br /&gt;
By the way, since I am not regularly writing here, I would suggest you subscribe to &lt;a href="http://feeds.feedburner.com/sharpdeveloper"&gt;my feed&lt;/a&gt; so you can get an update when I post a new article.&lt;/p&gt;&lt;img src="http://sharpdeveloper.net/content/aggbug/58.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sameer Alibhai</dc:creator>
            <guid>http://sharpdeveloper.net/content/archive/2008/02/12/convert-from-vb.net-to-csharp-code.aspx</guid>
            <pubDate>Tue, 12 Feb 2008 12:45:24 GMT</pubDate>
            <wfw:comment>http://sharpdeveloper.net/content/comments/58.aspx</wfw:comment>
            <comments>http://sharpdeveloper.net/content/archive/2008/02/12/convert-from-vb.net-to-csharp-code.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://sharpdeveloper.net/content/comments/commentRss/58.aspx</wfw:commentRss>
        </item>
        <item>
            <title>How Random is your Random??</title>
            <link>http://sharpdeveloper.net/content/archive/2007/12/05/how-random-is-your-random.aspx</link>
            <description>&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: navy"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: navy"&gt;How random is your random?  &lt;br /&gt;
&lt;br /&gt;
Computers are very deterministic.  What that means is that you put something in, you get something out.  In order to get computers to perform "randomness", it is very difficult.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: navy"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: navy"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: navy"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: navy"&gt;Why is this important to understand? Because we want to write our code properly, if we depend on the random function for some security purpose, such as for generating passwords, we are actually putting security holes in our application without realizing it.&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: navy"&gt;In .NET Using RNGCryptoServiceProvider would give you much better random results than just a Random.Next()&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: navy"&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/system.security.cryptography.rngcryptoserviceprovider.aspx"&gt;&lt;font color="#800080"&gt;http://msdn2.microsoft.com/en-us/library/system.security.cryptography.rngcryptoserviceprovider.aspx&lt;/font&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: navy"&gt;However, in order to &lt;strong&gt;truly&lt;/strong&gt;  randomize your number, you would have to do something like use data from customer mouse movements, or something wierd like that.  &lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: navy"&gt;Alternatively you can use a hardware random number generator such as the one Intel created that uses thermal noise to generate &lt;strong&gt;real&lt;/strong&gt; random numbers&lt;/span&gt;&lt;/div&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: navy"&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;br /&gt;
To realize just how complicated this really is, lets look at this quote from the Pokerstars web site on how they shuffle the cards in their software:&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;/div&gt;
&lt;div style="BACKGROUND: whitesmoke; LINE-HEIGHT: 140%"&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: #333333; LINE-HEIGHT: 140%"&gt;SHUFFLE&lt;/span&gt;&lt;/div&gt;
&lt;div style="BACKGROUND: whitesmoke; LINE-HEIGHT: 140%"&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: #333333; LINE-HEIGHT: 140%"&gt;"Anyone who considers arithmetic methods of producing random digits is, of course, in a state of sin." - John von Neumann, 1951&lt;/span&gt;&lt;/div&gt;
&lt;div style="BACKGROUND: whitesmoke; LINE-HEIGHT: 140%"&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: #333333; LINE-HEIGHT: 140%"&gt;We understand that a use of a fair and unpredictable shuffle algorithm is critical to our software. To ensure this and avoid major problems described in [2], we are using two independent sources of truly random data:&lt;/span&gt;&lt;/div&gt;
&lt;div style="BACKGROUND: whitesmoke; LINE-HEIGHT: 140%"&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: #333333; LINE-HEIGHT: 140%"&gt;* user input, including summary of mouse movements and events timing, collected from client software&lt;br /&gt;
* true hardware random number generator developed by Intel [3], which uses thermal noise as an entropy source&lt;/span&gt;&lt;/div&gt;
&lt;div style="BACKGROUND: whitesmoke; LINE-HEIGHT: 140%"&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: #333333; LINE-HEIGHT: 140%"&gt;Each of these sources itself generates enough entropy to ensure a fair and unpredictable shuffle.&lt;br /&gt;
Shuffle Highlights:&lt;/span&gt;&lt;/div&gt;
&lt;div style="BACKGROUND: whitesmoke; LINE-HEIGHT: 140%"&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: #333333; LINE-HEIGHT: 140%"&gt;* A deck of 52 cards can be shuffled in 52! ways. 52! is about 2^225 (to be precise, 80,658,175,170,943,878,571,660,636,856,404,000,000,000,000,000 ways). We use 249 random bits from both entropy sources (user input and thermal noise) to achieve an even and unpredictable statistical distribution.&lt;br /&gt;
* Furthermore, we apply conservative rules to enforce the required degree of randomness; for instance, if user input does not generate required amount of entropy, we do not start the next hand until we obtain the required amount of entropy from Intel RNG.&lt;br /&gt;
* We use the SHA-1 cryptographic hash algorithm to mix the entropy gathered from both sources to provide an extra level of security&lt;br /&gt;
* We also maintain a SHA-1-based pseudo-random generator to provide even more security and protection from user data attacks&lt;br /&gt;
* To convert random bit stream to random numbers within a required range without bias, we use a simple and reliable algorithm. For example, if we need a random number in the range 0-25:&lt;br /&gt;
o we take 5 random bits and convert them to a random number 0-31&lt;br /&gt;
o if this number is greater than 25 we just discard all 5 bits and repeat the process&lt;br /&gt;
* This method is not affected by biases related to modulus operation for generation of random numbers that are not 2n, n = 1,2,..&lt;br /&gt;
* To perform an actual shuffle, we use another simple and reliable algorithm:&lt;br /&gt;
o first we draw a random card from the original deck (1 of 52) and place it in a new deck - now original deck contains 51 cards and the new deck contains 1 card&lt;br /&gt;
o then we draw another random card from the original deck (1 of 51) and place it on top of the new deck - now original deck contains 50 cards and the new deck contains 2 cards&lt;br /&gt;
o we repeat the process until all cards have moved from the original deck to the new deck&lt;br /&gt;
* This algorithm does not suffer from "Bad Distribution Of Shuffles" described in [2]&lt;/span&gt;&lt;/div&gt;
&lt;div style="BACKGROUND: whitesmoke; LINE-HEIGHT: 140%"&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: #333333; LINE-HEIGHT: 140%"&gt;PokerStars shuffle verified by Cigital and BMM International&lt;/span&gt;&lt;/div&gt;
&lt;div style="BACKGROUND: whitesmoke; LINE-HEIGHT: 140%"&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: #333333; LINE-HEIGHT: 140%"&gt;PokerStars submitted extensive information about the PokerStars random number generator (RNG) to two independent organizations. We asked these two trusted resources to perform an in-depth analysis of the randomness of the output of the RNG, and its implementation in the shuffling of the cards on PokerStars.&lt;/span&gt;&lt;/div&gt;
&lt;div style="BACKGROUND: whitesmoke; LINE-HEIGHT: 140%"&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: #333333; LINE-HEIGHT: 140%"&gt;Both independent companies were given full access to the source code and confirmed the randomness and security of our shuffle. Visit Online Poker Random Number Generator for more details.&lt;/span&gt;&lt;/div&gt;
&lt;div style="BACKGROUND: whitesmoke; LINE-HEIGHT: 140%"&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: #333333; LINE-HEIGHT: 140%"&gt;[2] "How We Learned to Cheat at Online Poker: A Study in Software Security" - &lt;a href="http://itmanagement.earthweb.com/entdev/article.php/616221"&gt;http://itmanagement.earthweb.com/entdev/article.php/616221&lt;/a&gt;&lt;br /&gt;
[3] "The Intel Random Number Generator" - &lt;a href="http://www.cryptography.com/resources/whitepapers/IntelRNG.pdf"&gt;http://www.cryptography.com/resources/whitepapers/IntelRNG.pdf&lt;/a&gt;"&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: navy"&gt;Here is an article about how to shuffle a deck of cards: &lt;a href="http://www.codinghorror.com/blog/archives/001008.html?r=31644"&gt;&lt;font color="#800080"&gt;http://www.codinghorror.com/blog/archives/001008.html?r=31644&lt;/font&gt;&lt;/a&gt; and in one of the links it explains a big security hole in their random number generation and how it could have been used to leverage thousands of dollars from players.&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: navy"&gt;&lt;br /&gt;
Here is a snippet of how to get Cryographically safe random numbers:&lt;br /&gt;
&lt;font size="2"&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;This will fill in the 8 bytes with a crytographically strong sequence of random values.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;
&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;byte&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;[] salt = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;byte&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;[8];&lt;br /&gt;
&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;RNGCryptoServiceProvider&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; rng = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;RNGCryptoServiceProvider&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;();&lt;br /&gt;
rng.GetBytes(salt);&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/span&gt;&lt;/div&gt;&lt;img src="http://sharpdeveloper.net/content/aggbug/56.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sameer Alibhai</dc:creator>
            <guid>http://sharpdeveloper.net/content/archive/2007/12/05/how-random-is-your-random.aspx</guid>
            <pubDate>Wed, 05 Dec 2007 13:52:22 GMT</pubDate>
            <wfw:comment>http://sharpdeveloper.net/content/comments/56.aspx</wfw:comment>
            <comments>http://sharpdeveloper.net/content/archive/2007/12/05/how-random-is-your-random.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://sharpdeveloper.net/content/comments/commentRss/56.aspx</wfw:commentRss>
        </item>
        <item>
            <title>How To Debug Inside The Code Of Your 3rd Party Libraries</title>
            <link>http://sharpdeveloper.net/content/archive/2007/11/06/how-to-debug-inside-the-code-of-your-3rd-party.aspx</link>
            <description>&lt;p&gt;Let's say you are using a 3rd Party Library like &lt;a href="http://code.google.com/p/elmah"&gt;ELMAH&lt;/a&gt; in your web site project to handle unhandled exceptions and it's throwing an exception and you don't know why.  Since the code is open source, you would LOVE to see what line its crashing on and then submit your changes to the project so that others can benefit from the fix you made.  It gives you that good feeling, right?&lt;/p&gt;
&lt;p&gt;Well, unfortunately, you put the compiled DLL in the bin folder and when it crashes, it just crashes and burns.&lt;/p&gt;
&lt;p&gt;How can you see the source code?  Simple!  Compile the source code on your machine, and copy the PDB ("Debugging Database") file to your bin folder along with the DLL, and then your web site crashes while in debug mode, it will go to the exact folder on your file system where the DLL was compiled from and show you the exact line of the error.&lt;/p&gt;
&lt;p&gt;This was my recent experience with Elmah that it was crashing due to the fact that XMLWriter was misbehaving and throwing an exception when it was supposed to actually replace invalid entities in the XML automatically (at least, according to the MSDN documentation).&lt;/p&gt;
&lt;p&gt;Take a look at &lt;a href="http://code.google.com/p/elmah/issues/detail?id=43&amp;amp;can=1&amp;amp;q=Xml"&gt;Issue 43 on Elmah Site&lt;/a&gt; for more details.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;img src="http://sharpdeveloper.net/content/aggbug/54.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sameer Alibhai</dc:creator>
            <guid>http://sharpdeveloper.net/content/archive/2007/11/06/how-to-debug-inside-the-code-of-your-3rd-party.aspx</guid>
            <pubDate>Tue, 06 Nov 2007 13:08:55 GMT</pubDate>
            <wfw:comment>http://sharpdeveloper.net/content/comments/54.aspx</wfw:comment>
            <comments>http://sharpdeveloper.net/content/archive/2007/11/06/how-to-debug-inside-the-code-of-your-3rd-party.aspx#feedback</comments>
            <wfw:commentRss>http://sharpdeveloper.net/content/comments/commentRss/54.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Are You a Sharp Developer?? (Part 2)</title>
            <link>http://sharpdeveloper.net/content/archive/2007/08/12/are-you-a-sharp-developer-part-2.aspx</link>
            <description>&lt;p&gt;This is the second post in the series "&lt;a href="http://www.sharpdeveloper.net/content/archive/2007/07/11/what-makes-a-sharp-developer-part-1.aspx"&gt;What Makes a Sharp Developer&lt;/a&gt;"&lt;br /&gt;
&lt;strong&gt;The next article in this series will discuss keeping up with the bleeding edge - Visual Studio 2008 (Orcas), Silverlight, .NET 3.5, LINQ, .. and more&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This post will focus on: balanced lifestyle, staying away from drugs, and keeping a healthy balance between learning and working.  Overall this article discusses how you can become a more valuable resource to your team and to your employers.&lt;br /&gt;
 &lt;/p&gt;
&lt;h2&gt; &lt;/h2&gt;
&lt;h2&gt;Lead a Balanced Lifestyle&lt;/h2&gt;
Many of us in the development or business field unfortunately tend to overwork ourselves.  We work late nights at the office surviving on Java alone (caffeine, that is, not Sun Microsystems Java&lt;sup&gt;R&lt;/sup&gt;).  We take our work home in the evenings, or we might be doing stuff on the weekend that is work related so that we have a head start during the week.  I feel this tendency to overwork ourselves is part of our human nature.  We have to protect ourselves against this and yearn to keep a balance.  Although there is some overlap, I like to divide my time into three categories - Work time, Time for God, and Time for my family (don't forget Time for Myself).  The difficult part is keeping the three in balance and perspective.  &lt;br /&gt;
&lt;br /&gt;
If we start doing fifty or sixty hour weeks consistently, our quality of work will definitely go down.  It is unfortunate that some companies do not understand this, and push their developers to work longer and harder despite the fact that inevitably their performance will suffer.  As well if your family life suffers, that will not be good for you at work.  Your wife (or husband) might end up putting extra hot sauce in your sandwich because you didn't spend time with her for the last six weeks and your stomach isn't going to like that.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt; &lt;/h2&gt;
&lt;h2&gt;Stay away from the drugs&lt;/h2&gt;
One of the keys to success is to stay away from drugs.  That includes alcohol, nicotine, and.... that includes caffeine, man (Bummer!).  Actually caffeine is one of my favourite drugs :(.  But keep it in moderation.  If you overdo it, or if you become dependent on caffeine to survive, you are going to be at a weakness to those who can survive without their daily injection.  Also it hides your tiredness, especially if you start to use it regularly even when you aren't working, you might not realize just how tired you are.  If you notice you are coming home with bad headaches, or are feeling dizzy or other strange things are happening, THOSE ARE NOT A GOOD SIGNS.&lt;br /&gt;
&lt;h2&gt; &lt;/h2&gt;
&lt;h2&gt;A balance between working and learning&lt;/h2&gt;
This one is a tricky one.  It depends a lot on your work environment and how tight your deadlines are.  I am suggesting that you make sure that no matter what, each day you learn something new.  Do not spend so much time on your task so that you are completing it as fast as possible without taking the time to investigate or find better solutions.  Don't assume that just because you did this four times before, that the fifth time you should do the same thing.  It could be possible that you did it a silly way four times and you are just going to make it the fifth now!  There have been so many cases where I have been repeating my same noobness (i.e. lack of expertise) by declaring my SQL parameters as an ArrayList for example, whereas I could do it without the additional memory overhead and then conversion into an array by &lt;a href="http://sharpdeveloper.net/content/archive/2007/05/25/creating-sqlparameters-best-practices.aspx"&gt;declaring my SQLParameters directly into an array&lt;/a&gt; with the exact size I need!  Sometimes employees think that they are not doing their company a favour if they "waste" time reading stuff like this.  &lt;br /&gt;
&lt;br /&gt;
Infact, I beg to differ!!  On the contrary, you will be a MUCH more valuable employee if you insist on taking the time to learn things.  An employee who consistently learns is the last one to get fired, whereas the old dog who can't learn new tricks is going to be the first one to have to sleep outside (so to speak).  Please, this is so important.  If your boss doesn't give you time for this, either get a new job, or work late so that you can spend an hour a day on this.  As well, this will give you a bit of job security incase you end up being the one who is laid off, because you have been keeping up with the improvements and constantly &lt;span style="FONT-WEIGHT: bold"&gt;sharpening&lt;/span&gt; your skills, you will be more in touch with the technology than the ones sitting on their old skills.&lt;br /&gt;
&lt;br /&gt;
As a PS, I would also recommend looking at current job postings to see what technologies are in demand, and as well try to see if you can figure out trends (i.e. which direction the market is heading and what technologies are up and coming.)&lt;br /&gt;&lt;img src="http://sharpdeveloper.net/content/aggbug/44.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sameer Alibhai</dc:creator>
            <guid>http://sharpdeveloper.net/content/archive/2007/08/12/are-you-a-sharp-developer-part-2.aspx</guid>
            <pubDate>Mon, 13 Aug 2007 01:18:17 GMT</pubDate>
            <wfw:comment>http://sharpdeveloper.net/content/comments/44.aspx</wfw:comment>
            <comments>http://sharpdeveloper.net/content/archive/2007/08/12/are-you-a-sharp-developer-part-2.aspx#feedback</comments>
            <wfw:commentRss>http://sharpdeveloper.net/content/comments/commentRss/44.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Smarter Debug Code With Conditional Compilation</title>
            <link>http://sharpdeveloper.net/content/archive/2007/07/18/smarter-debug-code-with-conditional-compilation.aspx</link>
            <description>&lt;div style="MARGIN: 0in 0in 0pt"&gt;Debug statements. We've all used debug statements at one time or another--most commonly to print out some values and see what they are. Commonly criticized (and rightly so) as a "beginners" way to debug, many developers usually advance to a proper debugger and leave behind semi-useless print statements.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;But wait.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;em&gt;Are&lt;/em&gt; they useless?&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;The idea of print statements is to show something to the developer--print some value.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;br /&gt;
But what about more &lt;em&gt;advanced&lt;/em&gt; debug code? Extra buttons that let you skip and automate tedious steps. Labels that show you that certain values are meeting their expectations. Forms that run in the background and churn out useful information.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;"Ok, sure," you might say, "but, eh, I have to remove that for the release version."&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;But do you?&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;.NET says you don't &lt;em&gt;have&lt;/em&gt; to.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;How does it work?&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;.NET has something called &lt;strong&gt;conditional compilation&lt;/strong&gt;--the gist of it is that, like System.Diagnostics.Assert, certain methods are &lt;strong&gt;only compiled into the code when you're running in debug mode.&lt;/strong&gt; Otherwise, they're ignored, and all calls to those methods do nothing. So you can happily introduce function calls all over the place to help you test your code, without worrying about the extra overhead of it compiling into production code (not to mention having to remove it from your application).&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;How do you do it? Simply add the following attribute to your desired methods:&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;[System.Diagnostics.&lt;span style="COLOR: #2b91af"&gt;Conditional&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"DEBUG"&lt;/span&gt;)]&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;And VOILA! .NET leaves the code uncompiled in Release mode, and all function calls to that method are removed.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;So go, and enjoy your newfound powers! And remember--&lt;strong&gt;it's not about print statements. Smart debugging code can be a beneficial aid to development&lt;/strong&gt;. It's a tool for you to use, just like any other tool. Don't misuse it.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;br /&gt;
Also see &lt;a href="http://www.sharpdeveloper.net/content/archive/2007/11/06/how-to-debug-inside-the-code-of-your-3rd-party.aspx"&gt;How To Debug Inside your 3rd Party Libraries&lt;/a&gt;&lt;/div&gt;&lt;img src="http://sharpdeveloper.net/content/aggbug/42.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sameer Alibhai</dc:creator>
            <guid>http://sharpdeveloper.net/content/archive/2007/07/18/smarter-debug-code-with-conditional-compilation.aspx</guid>
            <pubDate>Wed, 18 Jul 2007 22:15:30 GMT</pubDate>
            <wfw:comment>http://sharpdeveloper.net/content/comments/42.aspx</wfw:comment>
            <comments>http://sharpdeveloper.net/content/archive/2007/07/18/smarter-debug-code-with-conditional-compilation.aspx#feedback</comments>
            <wfw:commentRss>http://sharpdeveloper.net/content/comments/commentRss/42.aspx</wfw:commentRss>
        </item>
        <item>
            <title>How To Use SqlParameterCache (Caching Sql Parameters)</title>
            <link>http://sharpdeveloper.net/content/archive/2007/06/29/how-to-use-sqlparametercache-caching-sql-parameters.aspx</link>
            <description>This article describes how to cache your SqlParameters.  If you have code that is regularly executed, and that uses a stored procedure, you can benefit from this.  This information, as well as how to properly use this, is very hard to find, even on &lt;a href="http://www.google.ca/search?hl=en&amp;amp;client=firefox-a&amp;amp;rls=org.mozilla%3Aen-US%3Aofficial&amp;amp;hs=nOl&amp;amp;q=GetspParameterSet&amp;amp;btnG=Search&amp;amp;meta="&gt;Google&lt;/a&gt;. (Don't worry, you don't need to spend all that time looking, the information is already here for you!)&lt;br /&gt;
&lt;br /&gt;
There is a function that Microsoft built that will allow you to get the parameter information from the database stored procedure, and that doesn't require you to re-build your parameter array every time.  The only thing you will need to do is set the values of the parameters.&lt;br /&gt;
&lt;br /&gt;
What some people don't realize, is that a similar approach can be taken with regular SQL queries that are not stored procedures! &lt;br /&gt;
&lt;br /&gt;
The downside is that the first call will be slower, because it will need to cache the parameters, however, for each extra call, it will be faster because the parameters are already created.&lt;br /&gt;
&lt;br /&gt;
How can you do this?  You first create your parameters, and store it in the call by calling SqlParameterCache.&lt;span style="font-weight: bold;"&gt;CacheParameterSet()&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Then you call SqlParameterCache.&lt;span style="font-weight: bold;"&gt;GetCachedParameterSet()&lt;/span&gt; to get the cached result.  If the result is null, then you can store the parameters in the cache, otherwise you already have it cached!&lt;br /&gt;
&lt;br /&gt;
Here is an example in VB.NET of how to use SqlParameterCache.&lt;span style="font-weight: bold;"&gt;CacheParameterSet()&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;span id="ctl00_ContentPlaceHolder1_output"&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; cachedParams &lt;span class="kwrd"&gt;as&lt;/span&gt; SqlParameter() = SqlHelperParameterCache.GetCachedParameterSet(Config.connstring,strSql)&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt; cachedParams &lt;span class="kwrd"&gt;is&lt;/span&gt; &lt;span class="kwrd"&gt;nothing&lt;/span&gt; &lt;span class="kwrd"&gt;then&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;Dim&lt;/span&gt; params &lt;span class="kwrd"&gt;as&lt;/span&gt; SqlParameter() = { _&lt;br /&gt;    &lt;span class="kwrd"&gt;New&lt;/span&gt; SqlParameter(&lt;span class="str"&gt;"@userID"&lt;/span&gt;, userID), _&lt;br /&gt;    &lt;span class="kwrd"&gt;New&lt;/span&gt; SqlParameter(&lt;span class="str"&gt;"@timestamp"&lt;/span&gt;, timestamp), _&lt;br /&gt;    &lt;span class="kwrd"&gt;New&lt;/span&gt; SqlParameter(&lt;span class="str"&gt;"@email"&lt;/span&gt;,email), _&lt;br /&gt;    &lt;span class="kwrd"&gt;New&lt;/span&gt; SqlParameter(&lt;span class="str"&gt;"@timesLoaded"&lt;/span&gt;,5), _&lt;br /&gt;    &lt;span class="kwrd"&gt;New&lt;/span&gt; SqlParameter(&lt;span class="str"&gt;"@country"&lt;/span&gt;,country), _&lt;br /&gt;    &lt;span class="kwrd"&gt;New&lt;/span&gt; SqlParameter(&lt;span class="str"&gt;"@source"&lt;/span&gt;,source) _&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;SqlHelperParameterCache.CacheParameterSet(Config.connstring,strSql,params)&lt;br /&gt;    cachedParams = params&lt;br /&gt;&lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;    cachedParams(0).Value = userID&lt;br /&gt;    cachedParams(1).Value = timestamp&lt;br /&gt;    cachedParams(2).Value = email&lt;br /&gt;    cachedParams(3).Value = 5&lt;br /&gt;    cachedParams(4).Value = country&lt;br /&gt;    cachedParams(5).Value = source&lt;br /&gt;&lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;SqlHelper.ExecuteNonQuery(Config.connstring, CommandType.Text, strSql, cachedParams)&lt;/pre&gt;
&lt;/span&gt;&lt;br /&gt;
Now the down side to this, is you lose your ability to dynamically create your SQL parameters (i.e. it depends on the order of your SQL parameters).&lt;br /&gt;
&lt;br /&gt;
Related articles:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://sharpdeveloper.net/content/archive/2007/05/25/creating-sqlparameters-best-practices.aspx"&gt;Using Dynamically Created SqlParameter Arrays&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.sharpdeveloper.net/content/archive/2007/06/15/creating-maintainable-database-queries-in-c-with-source-code.aspx"&gt;Creating Maintainable Database Queries In C# (with source code)&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.sharpdeveloper.net/content/articles/sqlhelper-source-code.aspx"&gt;SqlHelper Source Code, Microsoft Application Blocks&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://sharpdeveloper.net/content/aggbug/35.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sameer Alibhai, Ashiq Alibhai</dc:creator>
            <guid>http://sharpdeveloper.net/content/archive/2007/06/29/how-to-use-sqlparametercache-caching-sql-parameters.aspx</guid>
            <pubDate>Sat, 30 Jun 2007 00:35:40 GMT</pubDate>
            <wfw:comment>http://sharpdeveloper.net/content/comments/35.aspx</wfw:comment>
            <comments>http://sharpdeveloper.net/content/archive/2007/06/29/how-to-use-sqlparametercache-caching-sql-parameters.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://sharpdeveloper.net/content/comments/commentRss/35.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>