<?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>Geek Scrapbook</title>
	<atom:link href="http://www.geekscrapbook.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.geekscrapbook.com</link>
	<description>The .Net developer&#039;s everyday how-to guide.</description>
	<lastBuildDate>Fri, 03 Sep 2010 19:58:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>CashTrackerOnline.com Sneak Peek</title>
		<link>http://www.geekscrapbook.com/2010/09/03/cashtrackeronline-com-sneak-peek/</link>
		<comments>http://www.geekscrapbook.com/2010/09/03/cashtrackeronline-com-sneak-peek/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 18:55:41 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Cash Tracker Online]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/09/03/cashtrackeronline-com-sneak-peek/</guid>
		<description><![CDATA[Here’s a preview of the account tracker I’m working on. I filled it with my own account data to make it look realistic (and because I’m migrating my own finances from the Windows app to the new framework), which is why most of the actual names and numbers are blurred out. Enjoy! &#160;]]></description>
			<content:encoded><![CDATA[<p>Here’s a preview of the account tracker I’m working on. I filled it with my own account data to make it look realistic (and because I’m migrating my own finances from the Windows app to the new framework), which is why most of the actual names and numbers are blurred out. Enjoy!</p>
<p>&#160;</p>
<p><a href="http://www.geekscrapbook.com/wp-content/uploads/2010/09/screenshot.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="screenshot" border="0" alt="screenshot" src="http://www.geekscrapbook.com/wp-content/uploads/2010/09/screenshot_thumb.png" width="768" height="870" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/09/03/cashtrackeronline-com-sneak-peek/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CashTrackerOnline.com Weekly Development Update &#8211; 9/2/2010</title>
		<link>http://www.geekscrapbook.com/2010/09/02/cashtrackeronline-com-weekly-development-update-922010/</link>
		<comments>http://www.geekscrapbook.com/2010/09/02/cashtrackeronline-com-weekly-development-update-922010/#comments</comments>
		<pubDate>Fri, 03 Sep 2010 01:34:43 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Cash Tracker Online]]></category>
		<category><![CDATA[Notes]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/09/02/cashtrackeronline-com-weekly-development-update-922010/</guid>
		<description><![CDATA[I’ve spent a lot of time working on CashTrackerOnline.com in the past few days, and the done list is starting to outnumber the to-do list. Newly-initiated members of the done list are: Logic for budget accuracy calculations (just a method right now, no actual implementation on the site yet) CRUD for recurrences (and a slick [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve spent a lot of time working on CashTrackerOnline.com in the past few days, and the done list is starting to outnumber the to-do list. Newly-initiated members of the done list are:</p>
<ol>
<li>Logic for budget accuracy calculations (just a method right now, no actual implementation on the site yet)</li>
<li>CRUD for recurrences (and a slick interface to boot—I’m really enjoying working with these DevExpress controls)</li>
<li>Account balance projection chart</li>
</ol>
<p>So, that leaves the following stragglers on my to-do list before the first release (likely to be labeled an alpha—not all features are there, not everything works):</p>
<ul>
<li>Actual implementation of the budget accuracy calculations (displayed as % error)</li>
<li>Logic/implementation for budget adjustment suggestions</li>
<li>CRUD for manual entry and adjustments</li>
<li>GUI work</li>
<li>Data export</li>
<li>Wizardry for new users to introduce them to key elements of the app</li>
</ul>
<p>I’m really excited about where things are going with this project, to the point that I don’t think the Windows version of this project is going to be able to keep up with all the great features. I’ll tune in again next Thursday at the latest for another update on this (probably sooner). I should have some real web hosting by then, so I’m pushing hard to get a release out in the next two weeks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/09/02/cashtrackeronline-com-weekly-development-update-922010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CashTrackerOnline.com Updates</title>
		<link>http://www.geekscrapbook.com/2010/08/31/cashtrackeronline-com-updates/</link>
		<comments>http://www.geekscrapbook.com/2010/08/31/cashtrackeronline-com-updates/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 05:02:12 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Cash Tracker Online]]></category>
		<category><![CDATA[Notes]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/08/31/cashtrackeronline-com-updates/</guid>
		<description><![CDATA[I’ve been making some progress on the web project over the past few days. I’ve only got the steam for an hour or two each day, but since the last update I’ve accomplished a few things: Worked out web and data hosting (thanks boss). GoDaddy just doesn’t give me enough control over things to go [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been making some progress on the web project over the past few days. I’ve only got the steam for an hour or two each day, but since the last update I’ve accomplished a few things:</p>
<ol>
<li>Worked out web and data hosting (thanks boss). GoDaddy just doesn’t give me enough control over things to go that route with any real web applications (although they’re great at hosting this blog!)</li>
<li>Decided on some controls I’m licensed for through work. They aren’t free, but if you want to debug through any source code I make available you can install a trial. I decided quality was more important than making the code super easy to share in this case.</li>
<li>CRUD finished for accounts.</li>
<li>Some back-end work done on recurrences/transactions.</li>
<li>Balance calculations are working.</li>
</ol>
<p>Immediately next on my list are:</p>
<ul>
<li>Logic for budget accuracy calculations (this one’s a new idea)</li>
<li>Logic for budget adjustment suggestions (based on the accuracy calculations, also a new idea)</li>
<li>CRUD for recurrences/manual entry/adjustments.</li>
<li>Account balance projection chart</li>
<li>More time spent on GUI design</li>
<li>Data export functionality</li>
<li>Process to drive new users to the most useful functionality right away so they see the real benefits over time (following the visualize, control, predict pattern):</li>
<ul>
<li>Set up an account with recurrences to visualize the current state of the account</li>
<li>Use transactional adjustments to correct the budget with actual figures</li>
<li>Modify budget (recurrences) based on suggestions (control)</li>
<li>Using an established budget and calculations based on the average error margin, allow the website to predict the most accurate balance curve possible over the next year</li>
</ul>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/08/31/cashtrackeronline-com-updates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CashTrackerOnline.com Weekly Development Summary</title>
		<link>http://www.geekscrapbook.com/2010/08/26/cashtrackeronline-com-weekly-development-summary/</link>
		<comments>http://www.geekscrapbook.com/2010/08/26/cashtrackeronline-com-weekly-development-summary/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 17:36:23 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Cash Tracker Online]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/08/26/cashtrackeronline-com-weekly-development-summary/</guid>
		<description><![CDATA[This will be the first of a series of weekly updates about the Cash Tracker Online project. I’m happy with the progress I have made so far. I have a lot of the groundwork laid, but it will still be a few weeks before the initial version is ready to be published. Here’s the summary… [...]]]></description>
			<content:encoded><![CDATA[<p>This will be the first of a series of weekly updates about the Cash Tracker Online project.</p>
<p>I’m happy with the progress I have made so far. I have a lot of the groundwork laid, but it will still be a few weeks before the initial version is ready to be published. Here’s the summary…</p>
<p><strong>Finished Work</strong></p>
<ol>
<li>Domain purchased </li>
<li>Database Schema tentatively complete </li>
<li>Website project created </li>
<li>Simple Logo produced </li>
<li>Default / login screen working </li>
<li>Error handling in place, notifications of problems being routed correctly </li>
<li>Maintenance mode working </li>
<li>Dashboard “shell” built </li>
<li>Accounts summary pane on dashboard finished </li>
</ol>
<p><strong>Needed Before Release</strong></p>
<ol>
<li>A place to host the website and database (being worked out, should have this soon) </li>
<li>Make a decision on whether to use some third party controls and which ones </li>
<li>CRUD (Create, Read, Update, &amp; Delete) for:
<ul>
<li>Accounts </li>
<li>Recurrences </li>
<li>Manual Entry </li>
<li>Recurrence adjustments </li>
</ul>
</li>
<li>Balance calculations </li>
<li>Account projections </li>
<li>Graphical visuals </li>
<li>Data export </li>
</ol>
<p> <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="LogoSmall" border="0" alt="LogoSmall" src="http://www.geekscrapbook.com/wp-content/uploads/2010/08/LogoSmall_thumb.png" width="240" height="64" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/08/26/cashtrackeronline-com-weekly-development-summary/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CashTrackerOnline.com Domain Purchased</title>
		<link>http://www.geekscrapbook.com/2010/08/23/cashtrackeronline-com-domain-purchased/</link>
		<comments>http://www.geekscrapbook.com/2010/08/23/cashtrackeronline-com-domain-purchased/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 01:14:48 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Cash Tracker Online]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/08/23/cashtrackeronline-com-domain-purchased/</guid>
		<description><![CDATA[I’ve decided to go ahead with the online version of Cash Tracker. I purchased and parked the domain on my personal hosting account today. You can view the “coming soon” splash page here. I’ve also decided to convert Cash Tracker to a web project before implementing any of the new features. I think the development [...]]]></description>
			<content:encoded><![CDATA[<p> I’ve decided to go ahead with the online version of <a href="http://www.geekscrapbook.com/cash-tracker" target="_blank">Cash Tracker</a>. I purchased and parked the domain on my personal hosting account today. You can view the “coming soon” splash page <a href="http://www.cashtrackeronline.com" target="_blank">here</a>. I’ve also decided to convert Cash Tracker to a web project before implementing any of the new features. I think the development will be much faster-paced because programming for the web is my strong suit. Also, the tool will be much more accessible on the web, and version control will be much easier to implement (no more converting .tfx files to a new version because of a schema change). </p>
<p>I already have the database all laid out on paper, and I will make database diagrams and code samples available as I finish them. At some point I may be forced to stop posting source code for the sake of security, but until I start collecting sensitive data (right now the data I track can’t be tied to anyone or any actual accounts), I will continue to post code here.</p>
<p>  <img title="CTComingSoon" border="0" alt="CTComingSoon" src="http://www.geekscrapbook.com/wp-content/uploads/2010/08/CTComingSoon_thumb.jpg" width="1000" height="465" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/08/23/cashtrackeronline-com-domain-purchased/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Screen Tracker Upgrade Available</title>
		<link>http://www.geekscrapbook.com/2010/08/19/screen-tracker-upgrade-available/</link>
		<comments>http://www.geekscrapbook.com/2010/08/19/screen-tracker-upgrade-available/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 18:37:26 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Release]]></category>
		<category><![CDATA[Screen Tracker]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/08/19/screen-tracker-upgrade-available/</guid>
		<description><![CDATA[I have just released a Screen Tracker update. I’ll get the source code uploaded at some point. In the mean-time, here is the new feature list: Improved interface: Allows you to select the recording area from a list of pre-defined options Allows you to move the window around to “frame” your recording area The window [...]]]></description>
			<content:encoded><![CDATA[<p>I have just released a Screen Tracker update. I’ll get the source code uploaded at some point. In the mean-time, here is the new feature list:</p>
<ul>
<li>Improved interface:
<ul>
<li>Allows you to select the recording area from a list of pre-defined options </li>
<li>Allows you to move the window around to “frame” your recording area </li>
<li>The window containing the recording area stays on top, so you always know what you’re recording </li>
</ul>
</li>
<li>AVI files are now compressed using the WM3 video codec, resulting in far smaller file size </li>
<li>Frame rate is now throttled at 25 frames-per-second, resulting in somewhat-smaller file size </li>
<li>Ability to overwrite files when saving. </li>
<li>Progress bar shows save progress while exporting the AVI file. </li>
</ul>
<p>If you already have Screen Tracker, you should get the update the next time you use it. If you don’t have it yet, just click the Screen Tracker link under “Downloads” or go to the <a href="http://www.geekscrapbook.com/screen-tracker" target="_blank">Screen Tracker</a> page to install the latest release.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/08/19/screen-tracker-upgrade-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Screen Tracker Download Available</title>
		<link>http://www.geekscrapbook.com/2010/08/16/screen-tracker-download-available/</link>
		<comments>http://www.geekscrapbook.com/2010/08/16/screen-tracker-download-available/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 02:12:18 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Release]]></category>
		<category><![CDATA[Screen Tracker]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/08/16/screen-tracker-download-available/</guid>
		<description><![CDATA[The Screen Tracker tool is now available. View the Screen Tracker page for details. There’s also a new download link for it on the menu to the right. Screen Tracker is still very rough around the edges. Immediate improvements to be made are: Progress bar when saving the .avi file (a piece of cake, but [...]]]></description>
			<content:encoded><![CDATA[<p>The Screen Tracker tool is now available. View the <a href="http://www.geekscrapbook.com/screen-tracker" target="_blank">Screen Tracker</a> page for details. There’s also a new download link for it on the menu to the right. Screen Tracker is still very rough around the edges. Immediate improvements to be made are:</p>
<ol>
<li>Progress bar when saving the .avi file (a piece of cake, but time-consuming to implement)</li>
<li>Use a compressed format (the current file-sizes are enormous!)</li>
<li>A resizable “recording area” instead of the X, Y, Height, and Width boxes.</li>
<li>A “quality” radio button that increases performance at the expense of frame-rate (and maybe even the image quality)</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/08/16/screen-tracker-download-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cash Tracker 0.9 (beta) Now Available for Download</title>
		<link>http://www.geekscrapbook.com/2010/08/16/cash-tracker-0-9-beta-now-available-for-download/</link>
		<comments>http://www.geekscrapbook.com/2010/08/16/cash-tracker-0-9-beta-now-available-for-download/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 00:30:05 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Cash Tracker]]></category>
		<category><![CDATA[Code Release]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/08/16/cash-tracker-0-9-beta-now-available-for-download/</guid>
		<description><![CDATA[After several months of testing/tweaking, I have released a beta version of Cash Tracker. I believe it to be a stable product at this point that is simply lacking in some extra features. You can go to the Cash Tracker page to download and install using Click-Once. I have also made the latest source code [...]]]></description>
			<content:encoded><![CDATA[<p>After several months of testing/tweaking, I have released a beta version of Cash Tracker. I believe it to be a stable product at this point that is simply lacking in some extra features. You can go to the <a href="http://www.geekscrapbook.com/cash-tracker" target="_blank">Cash Tracker</a> page to download and install using Click-Once. I have also made the latest source code available on that page. Feel free to leave comments with any feature requests.</p>
<p><strong>The Roadmap      <br /></strong>I believe I am the only person who uses Cash Tracker on a consistent basis, but I’ve found the application so useful that I’m going to plow ahead until I’m satisfied. So, for the Cash Tracker 1.0 release I plan to unveil some big new features. Plus, I’ve determined to create an online version of the tool. Here are the steps needed to proceed to that point:</p>
<ol>
<li>Add most or all of the features on the upcoming features list </li>
<li>Acquire a catchy web domain name and SSL certificate </li>
<li>Possibly re-brand Cash Tracker under a different name for the web (i.e. whatever catchy domain name I find) </li>
<li>Port the Windows project to a data-driven website project using ASP.NET and SQL Server technologies</li>
</ol>
<p><strong>Contributions</strong>     <br />If you’d like to contribute to the project, just <a href="mailto:dave@geekscrapbook.com" target="_blank">drop me an email</a>; I’ll be happy to set up a source control server. The project doesn’t really need funding beyond a web domain and SSL certificate purchase, but an extra pair of coding hands would definitely accelerate the release timeline.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/08/16/cash-tracker-0-9-beta-now-available-for-download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coming Soon! Screen Tracker: A Video Screen Capture Tool Built Using C# and .NET</title>
		<link>http://www.geekscrapbook.com/2010/08/16/coming-soon-screen-tracker-a-video-screen-capture-tool-built-using-c-and-net/</link>
		<comments>http://www.geekscrapbook.com/2010/08/16/coming-soon-screen-tracker-a-video-screen-capture-tool-built-using-c-and-net/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 20:09:19 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Cash Tracker]]></category>
		<category><![CDATA[Screen Tracker]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/08/16/coming-soon-screen-tracker-a-video-screen-capture-tool-built-using-c-and-net/</guid>
		<description><![CDATA[It’s been a while since I worked on anything I’d consider “hobby code” on my own time. Recently, I had an idea for a utility that will require me to produce a library that will record video capture from the screen. I won’t say what it is, because if I can pull it off I [...]]]></description>
			<content:encoded><![CDATA[<p>It’s been a while since I worked on anything I’d consider “hobby code” on my own time. Recently, I had an idea for a utility that will require me to produce a library that will record video capture from the screen. I won’t say what it is, because if I can pull it off I will probably be visiting a patent office first. However, as I learn more about video capture (and audio capture as well), I will package up what I’ve produced into utilities that may be useful for someone else.</p>
<p><strong>So what goodies do you have for us?      <br /></strong>The tool I will post (most likely tonight or tomorrow, under the name Screen Tracker) will do the following:</p>
<ol>
<li>Record frames from the screen or a portion of the screen to a working directory. </li>
<li>Compile the frames into an AVI formatted video file. </li>
</ol>
<p>And my upcoming feature wish-list:</p>
<ol>
<li>Audio recording (either through the computer itself or via a microphone, maybe both) </li>
<li>The ability to add an .mp3 or .wav audio track </li>
</ol>
<p>Audio/video is not a world I am well-versed in, so don’t hold your breath on the wish-list <img src='http://www.geekscrapbook.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Just hope my great idea motivates me to make useful tools for you.</p>
<p><strong>Cash Tracker going Beta      <br /></strong>I’ve been using my latest version of <a href="http://www.geekscrapbook.com/cash-tracker">Cash Tracker</a> for a while, now, and it’s been working beautifully for me. I will probably post the most recent code and installer tonight or tomorrow as well. It’s ready for beta status, so I’ll update that designation as well (and maybe someone else will actually start using it!).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/08/16/coming-soon-screen-tracker-a-video-screen-capture-tool-built-using-c-and-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connection Timeout Using LINQ DataContext</title>
		<link>http://www.geekscrapbook.com/2010/08/13/connection-timeout-using-linq-datacontext/</link>
		<comments>http://www.geekscrapbook.com/2010/08/13/connection-timeout-using-linq-datacontext/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 16:23:48 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/08/13/connection-timeout-using-linq-datacontext/</guid>
		<description><![CDATA[For a while now, I’ve had a website that was sporadically encountering the following error: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. My Research On the website in question, I use [...]]]></description>
			<content:encoded><![CDATA[<p>For a while now, I’ve had a website that was sporadically encountering the following error:</p>
<blockquote><p>Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.</p>
</blockquote>
<p><strong>My Research      <br /></strong>On the website in question, I use LINQ-to-SQL heavily to perform data operations. Naturally, I suspected that I wasn’t disposing of my DataContext objects correctly, causing me to exceed the number of connections available in the pool. After doing a little research on the subject, I read in several articles (some by folks who are much more knowledgeable than myself) that I shouldn’t have to dispose of them. They all said the following code is just fine:</p>
<blockquote><pre class="code"><span style="color: #2b91af">CORDataContext </span>mcon = <span style="color: blue">new </span><span style="color: #2b91af">CORDataContext</span>();
<span style="color: #2b91af">COR_Employee </span>emp = mcon.COR_Employees.FirstOrDefault();</pre>
</blockquote>
<p>In fact, I should be able to put that into an infinite loop and never get the exception I was encountering. According to the experts, LINQ is not only smart enough to automatically open and close the connection for me, but also smart enough to dispose of the object when I’m done. No need for a “using” around my code or even a Connection.Close().</p>
<p><strong>An Exception to the Rule</strong></p>
<p>I noticed, though, that my code was slightly different. In my specific setup, I have a central database and a LOT of other databases I might want to connect to. So, to take advantage of connection pooling more, I always connect to the central database first and change to whatever catalog I need to access. In doing so, it is necessary to manually open the connection, like the following:</p>
<blockquote>
<pre class="code"><span style="color: #2b91af">CORDataContext </span>mcon = <span style="color: blue">new </span><span style="color: #2b91af">CORDataContext</span>();mcon.Connection.Open(); mcon.Connection.ChangeDatabase(<span style="color: #a31515">&quot;OtherDB&quot;</span>);
<span style="color: #2b91af">COR_Employee </span>emp = mcon.COR_Employees.FirstOrDefault();</pre>
</blockquote>
<p><strong>My Testing</p>
<p></strong>I began to theorize that manually opening the connection in this way <strong>keeps the connection alive</strong> after I’ve run my query. I confirmed the belief by trying to run the following code:</p>
<blockquote>
<pre class="code"><span style="color: blue">for </span>(<span style="color: blue">int </span>i = 0; i &lt; 1000; i++) {

    <span style="color: #2b91af">CORDataContext </span>mcon = <span style="color: blue">new </span><span style="color: #2b91af">CORDataContext</span>();
    <span style="color: #2b91af">COR_Employee </span>emp = mcon.COR_Employees.FirstOrDefault();
    mcon.Connection.Open();
    mcon.Connection.ChangeDatabase(<span style="color: #a31515">&quot;OtherDB&quot;</span>);

    <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;&quot; </span>+ (i + 1) + <span style="color: #a31515">&quot; / 1000&quot;</span>);
}</pre>
</blockquote>
<p>I got the exception after 230 or so connections. By default there are 100 connections available in the pool, but the garbage collector kicked in and helped give me a buffer before I ran out. So, from that I can conclude that manually opened DataContext connections will stay open until the connection is closed or the DataContext is disposed.</p>
<p><strong>The Solution</strong></p>
<p>Once I fully understood the problem, the fix was common sense:</p>
<blockquote>
<pre class="code"><span style="color: blue">for </span>(<span style="color: blue">int </span>i = 0; i &lt; 1000; i++) {

    <span style="color: blue">using </span>(<span style="color: #2b91af">CORDataContext </span>mcon = <span style="color: blue">new </span><span style="color: #2b91af">CORDataContext</span>()) {
        <span style="color: #2b91af">COR_Employee </span>emp = mcon.COR_Employees.FirstOrDefault();
        mcon.Connection.Open();
        mcon.Connection.ChangeDatabase(<span style="color: #a31515">&quot;OtherDB&quot;</span>);

        <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;&quot; </span>+ (i + 1) + <span style="color: #a31515">&quot; / 1000&quot;</span>);
    }
}</pre>
</blockquote>
<p>Adding a “using” to automatically dispose of my DataContext did the trick, and this loop now finishes in about 3 seconds (even with the overhead of writing to the console). I hope this helps someone else, because it’s been plaguing me for weeks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/08/13/connection-timeout-using-linq-datacontext/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Seeing the Big Picture While Getting Caught Up in the Details</title>
		<link>http://www.geekscrapbook.com/2010/03/07/seeing-the-big-picture-while-getting-caught-up-in-the-details/</link>
		<comments>http://www.geekscrapbook.com/2010/03/07/seeing-the-big-picture-while-getting-caught-up-in-the-details/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 01:43:05 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Notes]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/03/07/seeing-the-big-picture-while-getting-caught-up-in-the-details/</guid>
		<description><![CDATA[I’ve always wanted to know how things work. By the time I learned to talk I was asking my mother things she couldn’t answer: Me: “How does the car go?” Mom: “I press the gas pedal and it goes.” Me: “What does the gas pedal do that makes the car go?” Mom: “I don’t know, [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve always wanted to know how things work. By the time I learned to talk I was asking my mother things she couldn’t answer:</p>
<blockquote><p>Me: “How does the car go?”</p>
<p>Mom: “I press the gas pedal and it goes.”</p>
<p>Me: “What does the gas pedal do that makes the car go?”</p>
<p>Mom: “I don’t know, ask your father.”</p>
</blockquote>
<p>I probably had 5-10 conversations like that per day from the age of 3 until the age of 12. I was (and always have been) thinking about <strong>the details</strong>.</p>
<p>I define <strong>seeing the details</strong> as being able to look at something and dissect it into its smallest parts. This is a valuable skill for any programmer, and, I believe is what separates people who should learn to code from those who might be better off avoiding it. I had far too many classmates who were in it for the money, but had no passion or thirst for understanding. That drive is a key determining factor about someone’s future in software development. Seeing the details in my job means being able to mentally translate an assignment into code, including all the edge-conditions, so I can accurately estimate how long a project will need for completion. Seeing the details means being able to predict potential problems in January while the team is planning instead of getting caught off guard in June while we’re coding. It even means not writing the bugs other developers might. Yes, seeing the details is a valuable skill in software development, and I don’t see that changing anytime soon.</p>
<p>I never was a big picture kind of person growing up. I made passable grades on my papers in school because I could make really wonderful points, but I had trouble making everything from the first sentence to the last cohesive. Instead, my papers ended up often containing a few somewhat related ideas with an underwhelming effort to tie them together. As it turns out, while seeing the details is an important skill in software development, the converse is equally true; being able to let go of fine details and see <strong>the big picture</strong> is necessary for anyone who is more than just a code-monkey.</p>
<p>I define <strong>seeing the big picture</strong> as being able to look at something and understand not just how it <strong><em>can or does</em></strong> work, but how it <strong><em>could and should</em></strong> work. Seeing the big picture also means being able to look at something and understand how it should coexist and cooperate with other things. This is a valuable skill for anyone who wants to be more than a programmer. It separates people who should get a coding job and just take their annual pay increase from those who should attempt to scale the ladder.</p>
<p>I really believe that to be a truly successful leader in software development both of these skills are a must. One or the other just won’t do. Those who can only see the big picture can be great managers of small or open-ended projects, but without being able to see the details a project manager must rely on his developers to understand what a project will cost. Alternatively, those who can’t see past the details are wonderful programmers, but without seeing the big picture a developer must rely on his manager for direction. In my opinion, someone who has both skills can be a great leader and an invaluable asset, adding efficiency to an entire department.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/03/07/seeing-the-big-picture-while-getting-caught-up-in-the-details/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Serializing Data with System.Runtime.Serialization.DataContractSerializer</title>
		<link>http://www.geekscrapbook.com/2010/03/06/serializing-data-with-system-runtime-serialization-datacontractserializer/</link>
		<comments>http://www.geekscrapbook.com/2010/03/06/serializing-data-with-system-runtime-serialization-datacontractserializer/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 15:16:57 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Cash Tracker]]></category>
		<category><![CDATA[Code Samples]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/03/06/serializing-data-with-system-runtime-serialization-datacontractserializer/</guid>
		<description><![CDATA[Last time we discussed Serializing Data with System.Xml.Serialization.XmlSerializer. We will be using the same sample solution for this article. With .Net 3.5, Microsoft released the DataContractSerializer. It has a variety of uses, but at the very least it’s an improvement over the XmlSerializer. In Cash Tracker we started out by using the XmlSerializer to save [...]]]></description>
			<content:encoded><![CDATA[<p>Last time we discussed <a href="http://www.geekscrapbook.com/2010/03/06/serializing-data-with-system-xml-serialization-xmlserializer/" target="_blank">Serializing Data with System.Xml.Serialization.XmlSerializer</a>. We will be using the same sample solution for this article.</p>
<p>With .Net 3.5, Microsoft released the DataContractSerializer. It has a variety of uses, but at the very least it’s an improvement over the XmlSerializer. In <a href="http://www.geekscrapbook.com/cash-tracker" target="_blank">Cash Tracker</a> we started out by using the XmlSerializer to save files, but quickly found it inadequate, the reason being XmlSerializer does not play well with <strong>mixed access properties</strong>. </p>
<p>For an example, let’s look again at our Person class:</p>
<pre class="code"><span style="color: blue">public class </span><span style="color: #2b91af">Person </span>{
    <span style="color: blue">public string </span>FirstName { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
    <span style="color: blue">public string </span>LastName { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
    <span style="color: blue">public string </span>Initials { <span style="color: blue">get</span>; <span style="color: blue">private set</span>; }

    <span style="color: blue">private </span>Person() {
    }
    <span style="color: blue">public </span>Person(<span style="color: blue">string </span>first, <span style="color: blue">string </span>last) {
        <span style="color: blue">this</span>.FirstName = first;
        <span style="color: blue">this</span>.LastName = last;

        <span style="color: blue">this</span>.Initials = <span style="color: #2b91af">String</span>.Format(<span style="color: #a31515">&quot;{0}.{1}.&quot;</span>, FirstName[0], LastName[0]);
    }
}</pre>
<pre class="code"><font face="Tahoma">Notice I’ve added a new property with a private mutator. Also, I added a constructor to take advantage of the new property and made my default constructor private. Now when we try to serialize using the XmlSerializer we get an error:</font></pre>
<blockquote>
<p>Unable to generate a temporary class (result=1).<br />
    <br />error CS0200: Property or indexer &#8216;Person.Initials&#8217; cannot be assigned to &#8212; it is read only</p>
</blockquote>
<p><strong>What to do?</strong></p>
<p>In .Net 3.5, to get around this problem, <a href="http://connect.microsoft.com/VisualStudio/feedback/details/96882/xmlserializer-does-not-handle-properties-with-mixed-access-modifiers" target="_blank">Microsoft suggests using the DataContractSerializer</a>, so we will investigate switching to the new technology here. First, we need a reference to System.Runtime.Serialization:</p>
<p><a href="http://www.geekscrapbook.com/wp-content/uploads/2010/03/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.geekscrapbook.com/wp-content/uploads/2010/03/image_thumb2.png" width="400" height="451" /></a> </p>
<p>Once that’s done it’s actually pretty simply converting our old code. The new code looks like this:</p>
<pre class="code"><span style="color: blue">static void </span>XmlSerializePerson(<span style="color: #2b91af">Person </span>myPerson, <span style="color: blue">string </span>fileName) {
    <span style="color: #2b91af">DataContractSerializer </span>xs = <span style="color: blue">new </span><span style="color: #2b91af">DataContractSerializer</span>(<span style="color: blue">typeof</span>(<span style="color: #2b91af">Person</span>));

    <span style="color: blue">using </span>(<span style="color: #2b91af">FileStream </span>fs = <span style="color: blue">new </span><span style="color: #2b91af">FileStream</span>(fileName, <span style="color: #2b91af">FileMode</span>.Create, <span style="color: #2b91af">FileAccess</span>.Write)) {
        xs.WriteObject(fs, myPerson);
    }
}

<span style="color: blue">static </span><span style="color: #2b91af">Person </span>XmlDeserializePerson(<span style="color: blue">string </span>fileName) {
    <span style="color: #2b91af">DataContractSerializer </span>xs = <span style="color: blue">new </span><span style="color: #2b91af">DataContractSerializer</span>(<span style="color: blue">typeof</span>(<span style="color: #2b91af">Person</span>));

    <span style="color: blue">using </span>(<span style="color: #2b91af">FileStream </span>fs = <span style="color: blue">new </span><span style="color: #2b91af">FileStream</span>(fileName, <span style="color: #2b91af">FileMode</span>.Open, <span style="color: #2b91af">FileAccess</span>.Read)) {
        <span style="color: blue">return </span>(<span style="color: #2b91af">Person</span>)xs.ReadObject(fs);
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a>Notice we simply re-used the old methods, changing the object and methods used to serialize our Person. Our code will now execute as expected:</p>
<p><a href="http://www.geekscrapbook.com/wp-content/uploads/2010/03/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.geekscrapbook.com/wp-content/uploads/2010/03/image_thumb3.png" width="400" height="269" /></a> </p>
<p><strong>Download the Solution</strong></p>
<p><strong></strong></p>
<p>You can download a zip file of the solution by clicking the link below.</p>
<p><a href="http://www.geekscrapbook.com/wp-content/uploads/2010/03/DataContractSerializerDemo.zip" target="_blank">DataContractSerializerDemo.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/03/06/serializing-data-with-system-runtime-serialization-datacontractserializer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Serializing Data with System.Xml.Serialization.XmlSerializer</title>
		<link>http://www.geekscrapbook.com/2010/03/06/serializing-data-with-system-xml-serialization-xmlserializer/</link>
		<comments>http://www.geekscrapbook.com/2010/03/06/serializing-data-with-system-xml-serialization-xmlserializer/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 14:55:42 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Samples]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/03/06/serializing-data-with-system-xml-serialization-xmlserializer/</guid>
		<description><![CDATA[Serializing objects is often a useful way to save the state of an application. Let’s take a look at doing this using the XmlSerializer object. Class: Person Below is a simple class Person. My person has a name and an age: public class Person { public string FirstName { get; set; } public string LastName [...]]]></description>
			<content:encoded><![CDATA[<p>Serializing objects is often a useful way to save the state of an application. Let’s take a look at doing this using the XmlSerializer object.</p>
<p><strong>Class: Person</strong></p>
<p>Below is a simple class Person. My person has a name and an age:</p>
<pre class="code"><span style="color: blue">public class </span><span style="color: #2b91af">Person </span>{
    <span style="color: blue">public string </span>FirstName { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
    <span style="color: blue">public string </span>LastName { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }

    <span style="color: blue">public </span>Person() {
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
<p>The XmlSerializer requires that I leave an empty constructor in my class. I can make the constructor private if I don’t want it used for other things. Now, let’s create an instance of a Person.</p>
<pre class="code"><span style="color: blue">class </span><span style="color: #2b91af">Program </span>{
    <span style="color: blue">static void </span>Main(<span style="color: blue">string</span>[] args) {
        <span style="color: #2b91af">Person </span>myPerson = <span style="color: blue">new </span><span style="color: #2b91af">Person</span>();
        myPerson.FirstName = <span style="color: #a31515">&quot;John&quot;</span>;
        myPerson.LastName = <span style="color: #a31515">&quot;Smith&quot;</span>;
    }
}</pre>
<p><strong>How to serialize our class</strong></p>
<p>I will add a couple methods now to handle serializating and deserializing myPerson.</p>
<pre class="code"><span style="color: blue">static void </span>XmlSerializePerson(<span style="color: #2b91af">Person </span>myPerson, <span style="color: blue">string </span>fileName) {
    <span style="color: #2b91af">XmlSerializer </span>xs = <span style="color: blue">new </span><span style="color: #2b91af">XmlSerializer</span>(<span style="color: blue">typeof</span>(<span style="color: #2b91af">Person</span>));

    <span style="color: blue">using </span>(<span style="color: #2b91af">FileStream </span>fs = <span style="color: blue">new </span><span style="color: #2b91af">FileStream</span>(fileName, <span style="color: #2b91af">FileMode</span>.Create, <span style="color: #2b91af">FileAccess</span>.Write)) {
        xs.Serialize(fs, myPerson);
    }
}

<span style="color: blue">static </span><span style="color: #2b91af">Person </span>XmlDeserializePerson(<span style="color: blue">string </span>fileName) {
    <span style="color: #2b91af">XmlSerializer </span>xs = <span style="color: blue">new </span><span style="color: #2b91af">XmlSerializer</span>(<span style="color: blue">typeof</span>(<span style="color: #2b91af">Person</span>));

    <span style="color: blue">using </span>(<span style="color: #2b91af">FileStream </span>fs = <span style="color: blue">new </span><span style="color: #2b91af">FileStream</span>(fileName, <span style="color: #2b91af">FileMode</span>.Open, <span style="color: #2b91af">FileAccess</span>.Read)) {
        <span style="color: blue">return </span>(<span style="color: #2b91af">Person</span>)xs.Deserialize(fs);
    }
}</pre>
<p><strong>Code in action</strong></p>
<p>Now, saving myPerson is simple:</p>
<pre class="code"><span style="color: blue">static void </span>Main(<span style="color: blue">string</span>[] args) {
    <span style="color: #2b91af">Person </span>myPerson = <span style="color: blue">new </span><span style="color: #2b91af">Person</span>();
    myPerson.FirstName = <span style="color: #a31515">&quot;John&quot;</span>;
    myPerson.LastName = <span style="color: #a31515">&quot;Smith&quot;</span>;

    XmlSerializePerson(myPerson, <span style="color: #a31515">@&quot;C:\MyPerson.xml&quot;</span>);
}</pre>
<p><a href="http://11011.net/software/vspaste"></a>Let’s take a look at the resulting XML:</p>
<pre class="code"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot;<span style="color: blue">?&gt;
&lt;</span><span style="color: #a31515">Person </span><span style="color: red">xmlns:xsi</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://www.w3.org/2001/XMLSchema-instance</span>&quot; <span style="color: red">xmlns:xsd</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://www.w3.org/2001/XMLSchema</span>&quot;<span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">FirstName</span><span style="color: blue">&gt;</span>John<span style="color: blue">&lt;/</span><span style="color: #a31515">FirstName</span><span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">LastName</span><span style="color: blue">&gt;</span>Smith<span style="color: blue">&lt;/</span><span style="color: #a31515">LastName</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">Person</span><span style="color: blue">&gt;</span></pre>
<p>Now, let’s deserialize our person and display its data:</p>
<pre class="code"><span style="color: blue">static void </span>Main(<span style="color: blue">string</span>[] args) {
    <span style="color: #2b91af">Person </span>myPerson = XmlDeserializePerson(<span style="color: #a31515">@&quot;C:\MyPerson.xml&quot;</span>);

    <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Name: &quot; </span>+ myPerson.LastName + <span style="color: #a31515">&quot;, &quot; </span>+ myPerson.FirstName);
    <span style="color: #2b91af">Console</span>.ReadLine();
}</pre>
<p><a href="http://11011.net/software/vspaste"></a>The result:</p>
<p><a href="http://www.geekscrapbook.com/wp-content/uploads/2010/03/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.geekscrapbook.com/wp-content/uploads/2010/03/image_thumb1.png" width="400" height="269" /></a> </p>
<p>As you can see, the XmlSerializer did its job.</p>
<p><strong>Download the Solution</strong></p>
<p>You can download a zip file of the solution by clicking the link below.</p>
<p><a href="http://www.geekscrapbook.com/wp-content/uploads/2010/03/XmlSerializerDemo.zip" target="_blank">XmlSerializerDemo.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/03/06/serializing-data-with-system-xml-serialization-xmlserializer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cash Tracker (pre-alpha) Now Available for Download</title>
		<link>http://www.geekscrapbook.com/2010/03/05/cash-tracker-alpha-now-available-for-download/</link>
		<comments>http://www.geekscrapbook.com/2010/03/05/cash-tracker-alpha-now-available-for-download/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 03:38:15 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Cash Tracker]]></category>
		<category><![CDATA[Code Release]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/03/05/cash-tracker-alpha-now-available-for-download/</guid>
		<description><![CDATA[I’m happy to announce there’s now a somewhat usable version of Cash Tracker available for download. Click here to get it! It’s really rough; I’m giving it a version of 0.7. I don’t have any error handling in place, so if you put the wrong values into the tracker it will probably scream at you [...]]]></description>
			<content:encoded><![CDATA[<p>I’m happy to announce there’s now a somewhat usable version of Cash Tracker available for download. <strong><a href="http://www.geekscrapbook.com/cashtrackerinstall/publish.htm" target="_blank">Click here to get it!</a></strong></p>
<p>It’s really rough; I’m giving it a version of 0.7. I don’t have any error handling in place, so if you put the wrong values into the tracker it will probably scream at you and then die. If you’re not a geek you probably want to wait at least until version 0.9 gets released. Until then, I’m probably not going to settle on a reliable file type, so .tfx files saved before 0.9 probably won’t be compatible with later versions.</p>
<p>For a current list of features, check the Cash Tracker’s <a href="http://www.geekscrapbook.com/cash-tracker" target="_blank">main page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/03/05/cash-tracker-alpha-now-available-for-download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Announcing Cash Tracker</title>
		<link>http://www.geekscrapbook.com/2010/03/05/announcing-cash-tracker/</link>
		<comments>http://www.geekscrapbook.com/2010/03/05/announcing-cash-tracker/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 04:13:14 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Cash Tracker]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/03/05/announcing-cash-tracker/</guid>
		<description><![CDATA[I’ve undertaken a personal project in my spare time. It’s a personal finance application I’m calling Cash Tracker. You can read the technical details on the Cash Tracker page. The idea for Cash Tracker came to me when I was trying to find an easy way track my own finances. I wanted something I could [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve undertaken a personal project in my spare time. It’s a personal finance application I’m calling <strong>Cash Tracker</strong>. You can read the technical details on the <a href="http://www.geekscrapbook.com/cash-tracker/" target="_blank">Cash Tracker page</a>.</p>
<p>The idea for Cash Tracker came to me when I was trying to find an easy way track my own finances. I wanted something I could put my income and bills into and get a simple projection of my account balance throughout the year. Then, if I didn’t mind making adjustments later to reconcile (thus improving the projections as time goes by), I wanted to be able to enter a manual transaction here and there, too. But my main focus was <strong>keeping it simple</strong>. So, I wrote a very simple program that reads in a set of recurrences (bills, income) and transactions (non-recurring expenses or adjustments to bills/income). Then, it displays a set of numbers that are designed to help give me peace of mind about the future, like my project low and high balances for the year. To help me reconcile with my balance at the bank as the year goes on, I had the program output a running total I could open in Excel and compare with the bank.</p>
<p>Right now, that’s pretty much all the Cash Tracker does. <strong>It’s ugly</strong>, but it works as well as I need it to and keeps me from worrying about my finances. The project I’m undertaking is to bring Cash Tracker from “personal helper” to “helper to a lot of people” by making it easier for people to use who can’t write code or format a flat file correctly; people who don’t know what a CSV file is or what XML looks like. And, of course, I want to bring the Cash Tracker to other people like me who just don’t want to waste time on a “big” personal finance application, but still want to feel secure financially and have some numbers to support themselves with. I’m doing this solely because my Cash Tracker has helped me organize my own finances <strong>so much </strong>over the past 3 months.</p>
<p>I think Cash Tracker will appeal to many people because it makes maintaining finances so painless. Now that I have all my income and expenses into the program, it takes me just a few minutes every week or two to make the current projected balance line up with my actual balance. That includes the time I spend editing <strong>ugly, tab-delimited files</strong>. I am sure I can speed up the process even more.</p>
<p>So, the goal right now is to get the Cash Tracker into a form that other people can actually use. Eventually, I’d like to get it to “auto-magical” status, which would look something like this:</p>
<ol>
<li>Select your financial institution </li>
<li>Enter your login credentials </li>
<li>Hit “Track It!” </li>
<li>&lt;magic&gt; </li>
<li>View a list of your regular expenses and income, your projected high and low balances this year, your projected balance for any date in the future, etc. </li>
</ol>
<p>We’re talking <strong>zero maintenance</strong>. I believe we can get there, but we’re going to take baby steps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/03/05/announcing-cash-tracker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IHttpHandler and IRequiresSessionState</title>
		<link>http://www.geekscrapbook.com/2010/03/04/ihttphandler-and-irequiressessionstate/</link>
		<comments>http://www.geekscrapbook.com/2010/03/04/ihttphandler-and-irequiressessionstate/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 01:25:35 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/03/04/ihttphandler-and-irequiressessionstate/</guid>
		<description><![CDATA[If your web application relies on session to persist the user’s state and you’ve ever tried writing your own HTTP handler, you’ve probably run into an error: “Session state is not available in this context”. Thankfully, there is a simple remedy. In your class definition you need to implement the interface System.Web.SessionState.IRequiresSessionState. Once you’ve done [...]]]></description>
			<content:encoded><![CDATA[<p>If your web application relies on session to persist the user’s state and you’ve ever tried writing your own HTTP handler, you’ve probably run into an error: “Session state is not available in this context”. Thankfully, there is a simple remedy. </p>
<p>In your class definition you need to implement the interface <a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.irequiressessionstate.aspx" target="_blank">System.Web.SessionState.IRequiresSessionState</a>. Once you’ve done that you’ll find yourself magically able to use session once more.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/03/04/ihttphandler-and-irequiressessionstate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Version Checking with System.Version</title>
		<link>http://www.geekscrapbook.com/2010/03/04/version-checking-with-system-version/</link>
		<comments>http://www.geekscrapbook.com/2010/03/04/version-checking-with-system-version/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 01:19:02 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Samples]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2010/03/04/version-checking-with-system-version/</guid>
		<description><![CDATA[The .Net Framework makes version checking extremely simple. The framework provides a Version class that implements IComparable. Comparing two versions is as easy as the code below: using System; namespace VersionChecker { class Program { static void Main(string[] args) { Version v1 = new Version(&#34;1.0.0.0&#34;); Version v2 = new Version(&#34;1.0.0.1&#34;); if (v1 &#62; v2) { [...]]]></description>
			<content:encoded><![CDATA[<p>The .Net Framework makes version checking extremely simple. The framework provides a <a href="http://msdn.microsoft.com/en-us/library/system.version.aspx" target="_blank">Version</a> class that implements IComparable. Comparing two versions is as easy as the code below:</p>
<pre class="csharpcode"><span class="kwrd">using</span> System;

<span class="kwrd">namespace</span> VersionChecker {
    <span class="kwrd">class</span> Program {
        <span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args) {
            Version v1 = <span class="kwrd">new</span> Version(<span class="str">&quot;1.0.0.0&quot;</span>);
            Version v2 = <span class="kwrd">new</span> Version(<span class="str">&quot;1.0.0.1&quot;</span>);

            <span class="kwrd">if</span> (v1 &gt; v2) {
                Console.WriteLine(<span class="str">&quot;v1 is higher&quot;</span>);
            } <span class="kwrd">else</span> {
                Console.WriteLine(<span class="str">&quot;v2 is higher&quot;</span>);
            }

            Console.ReadLine();
        }
    }
}</pre>
<p>Here’s the result:</p>
<p><a href="http://www.geekscrapbook.com/wp-content/uploads/2010/03/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.geekscrapbook.com/wp-content/uploads/2010/03/image_thumb.png" width="399" height="268" /></a></p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2010/03/04/version-checking-with-system-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# Method to Add an Image to a PDF</title>
		<link>http://www.geekscrapbook.com/2009/11/16/c-method-to-add-an-image-to-a-pdf/</link>
		<comments>http://www.geekscrapbook.com/2009/11/16/c-method-to-add-an-image-to-a-pdf/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 23:31:41 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Code Samples]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2009/11/16/c-method-to-add-an-image-to-a-pdf/</guid>
		<description><![CDATA[I had to write a method to put images onto PDFs generically, so I wrote this handy little method. Just get your PDF and your image into byte arrays and fire the method below. I used PDFSharp to append the image. This method could be used to do things like build a letterhead generator or [...]]]></description>
			<content:encoded><![CDATA[<p>I had to write a method to put images onto PDFs generically, so I wrote this handy little method. Just get your PDF and your image into byte arrays and fire the method below. I used <a href="http://www.pdfsharp.net" target="_blank">PDFSharp</a> to append the image. This method could be used to do things like build a letterhead generator or any other kind of PDF document generation.</p>
<p>Here’s the method:<a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
<pre class="code"><span style="color: blue">public static byte</span>[] AppendImageToPdf(<span style="color: blue">byte</span>[] pdf, <span style="color: blue">byte</span>[] img, <span style="color: #2b91af">Point </span>position, <span style="color: blue">double </span>scale)
{
    <span style="color: blue">using </span>(System.IO.<span style="color: #2b91af">MemoryStream </span>msPdf = <span style="color: blue">new </span>System.IO.<span style="color: #2b91af">MemoryStream</span>(pdf))
    {
        <span style="color: blue">using </span>(System.IO.<span style="color: #2b91af">MemoryStream </span>msImg = <span style="color: blue">new </span>System.IO.<span style="color: #2b91af">MemoryStream</span>(img))
        {
            System.Drawing.<span style="color: #2b91af">Image </span>image = System.Drawing.<span style="color: #2b91af">Image</span>.FromStream(msImg);
            PdfSharp.Pdf.<span style="color: #2b91af">PdfDocument </span>document = PdfSharp.Pdf.IO.<span style="color: #2b91af">PdfReader</span>.Open(msPdf);
            PdfSharp.Pdf.<span style="color: #2b91af">PdfPage </span>page = document.Pages[0];
            PdfSharp.Drawing.<span style="color: #2b91af">XGraphics </span>gfx = PdfSharp.Drawing.<span style="color: #2b91af">XGraphics</span>.FromPdfPage(page);
            PdfSharp.Drawing.<span style="color: #2b91af">XImage </span>ximg = PdfSharp.Drawing.<span style="color: #2b91af">XImage</span>.FromGdiPlusImage(image);

            gfx.DrawImage(
                ximg,
                position.X,
                position.Y,
                ximg.Width * scale,
                ximg.Height * scale
            );

            <span style="color: blue">using </span>(System.IO.<span style="color: #2b91af">MemoryStream </span>msFinal = <span style="color: blue">new </span>System.IO.<span style="color: #2b91af">MemoryStream</span>())
            {
                document.Save(msFinal);
                <span style="color: blue">return </span>msFinal.ToArray();
            }

        }
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2009/11/16/c-method-to-add-an-image-to-a-pdf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET Maintenance Scheduling Made Easy</title>
		<link>http://www.geekscrapbook.com/2009/08/04/asp-net-maintenance-scheduling-made-easy/</link>
		<comments>http://www.geekscrapbook.com/2009/08/04/asp-net-maintenance-scheduling-made-easy/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 00:54:24 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Guides]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2009/08/04/asp-net-maintenance-scheduling-made-easy/</guid>
		<description><![CDATA[Any time I have code I need to release for an ASP.NET website that I know is going to cause a recompile (like anything in app_code, any new binaries, master pages, user controls, etc.) I try to avoid doing it when I know there are a lot of users on the site. The best way [...]]]></description>
			<content:encoded><![CDATA[<p align="left">Any time I have code I need to release for an ASP.NET website that I know is going to cause a recompile (like anything in app_code, any new binaries, master pages, user controls, etc.) I try to avoid doing it when I know there are a lot of users on the site. The best way to ensure that nobody will be using your website is to add scheduled maintenance support to your site. It’s very easy to do and it can save you and your users a lot of headache while you make updates.</p>
<p><strong>Deriving from System.Web.UI.Page&#160; <br /></strong>A quick and dirty way to get a maintenance window up for your site is to write a base page (derived from System.Web.UI.Page) that all of your pages derive from. That way you can specify things to happen on multiple pages from one central location. So let’s say I have BasePage.cs in my App_Code folder. I can override the OnPreInit() method to check to see whether I’m supposed to be in maintenance mode or not. If the site is supposed to be “down” I will redirect the user to a page that will say the site is down for maintenance. For now I will just be checking a flag I’ve set in app settings.</p>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnPreInit(EventArgs e) {
    <span class="kwrd">base</span>.OnPreInit(e);
    <span class="kwrd">if</span> (ConfigurationManager.AppSettings[<span class="str">&quot;MaintenanceMode&quot;</span>].ToUpper() == <span class="str">&quot;TRUE&quot;</span>) {
        <span class="kwrd">if</span> (Request.Url.AbsolutePath.ToLower() != <span class="str">&quot;/maintenance.aspx&quot;</span>) {
            Response.Redirect(<span class="str">&quot;Maintenance.aspx&quot;</span>);
        }
    }
}</pre>
<p>
  </p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p><strong>Using an HttpModule </p>
<p></strong>An alternate way to add code that checks for maintenance (and is less work if you have medium-to-large sized site OR multiple sites that need to use the same maintenance code) is to place it in an HttpModule and add the module to web.config. I personally think the HttpModule is perfectly suited to solving this problem. Checking for maintenance is typically something that is separate from most other things, so it makes sense to modularize it as much as possible. It’s just good form! Here’s my module code:</p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<pre class="csharpcode">

<span class="kwrd">public</span> <span class="kwrd">class</span> MaintenanceModule : IHttpModule
{
    <span class="preproc">#region</span> IHttpModule Members

    <span class="kwrd">public</span> <span class="kwrd">void</span> Dispose() {

    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> Init(HttpApplication context) {
        context.BeginRequest +=<span class="kwrd">new</span> EventHandler(context_BeginRequest);
    }

    <span class="kwrd">public</span> <span class="kwrd">void</span> context_BeginRequest(<span class="kwrd">object</span> sender, EventArgs e) {&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="kwrd">if</span> (ConfigurationManager.AppSettings[<span class="str">&quot;MaintenanceMode&quot;</span>] == <span class="str">&quot;TRUE&quot;</span>) { &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="kwrd">if</span> (Request.Url.AbsolutePath.ToLower() != <span class="str">&quot;/maintenance.aspx&quot;</span>) { &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Redirect(<span class="str">&quot;Maintenance.aspx&quot;</span>);             }         }
    }
    <span class="preproc">#endregion</span>
}
</pre>
<p>And here is my web.config entry (added to the httpModules section in system.web for local use; put it in the modules section of system.webserver for IIS to pick it up):</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;MaintenanceModule&quot;</span> <span class="attr">type</span><span class="kwrd">=&quot;MaintenanceModule&quot;</span> <span class="kwrd">/&gt;</span></pre>
<p>
  </p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p><strong>Scheduling Maintenance Ahead of Time </p>
<p></strong>I like to give my users several days’ notice before I bring a site down for maintenance, so I do two things to accomplish that. First, I keep a table called MaintenanceSchedule that I can put a start time, end time, public message, and private message into. Then, on pages where I want to notify users of the upcoming maintenance, I check the table for maintenance periods that haven’t yet begun.</p>
<pre class="csharpcode"><span class="kwrd">string</span> connectionString =
    ConfigurationManager.ConnectionStrings[<span class="str">&quot;DefaultConnection&quot;</span>].ConnectionString;

<span class="kwrd">using</span> (SqlConnection con = <span class="kwrd">new</span> SqlConnection(connectionString)) {
    con.Open();
    <span class="kwrd">using</span> (SqlCommand com = con.CreateCommand()) {
        com.CommandText = <span class="str">&quot;GetNextMaintenancePeriod&quot;</span>;
        com.CommandType = CommandType.StoredProcedure;

        <span class="kwrd">using</span> (SqlDataReader sdr = com.ExecuteReader()) {
            <span class="kwrd">if</span> (sdr.Read()) {
                DateTime start = sdr.GetDateTime(1);
                DateTime end = sdr.GetDateTime(2);

                litUpcomingMaintenance.Text =
                    <span class="str">&quot;&lt;strong&gt;Alert!&lt;/strong&gt; &quot;</span>
                    + <span class="str">&quot;This site will be going down for maintenance from &quot;</span>
                    + start.ToString() + <span class="str">&quot; until &quot;</span> + end.ToString() + <span class="str">&quot;.&quot;</span>;
            }
            <span class="kwrd">else</span> {
                <span class="rem">// throw an exception to show the default message.</span>
                <span class="kwrd">throw</span> <span class="kwrd">new</span> Exception(<span class="str">&quot;No maintenance period found...&quot;</span>);
            }
        }
    }
}</pre>
<p>
  </p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>This method also allows me to put a more specific message out when the site is actually being worked on as well as a way to keep a record of when past maintenance periods occurred.</p>
<pre class="csharpcode"><span class="kwrd">string</span> connectionString =
    ConfigurationManager.ConnectionStrings[<span class="str">&quot;DefaultConnection&quot;</span>].ConnectionString;

<span class="kwrd">try</span> {
    <span class="kwrd">using</span> (SqlConnection con = <span class="kwrd">new</span> SqlConnection(connectionString)) {
        con.Open();
        <span class="kwrd">using</span> (SqlCommand com = con.CreateCommand()) {
            com.CommandText = <span class="str">&quot;GetCurrentMaintenancePeriod&quot;</span>;
            com.CommandType = CommandType.StoredProcedure;

            <span class="kwrd">using</span> (SqlDataReader sdr = com.ExecuteReader()) {
                <span class="kwrd">if</span> (sdr.Read()) {
                    DateTime start = sdr.GetDateTime(1);
                    DateTime end = sdr.GetDateTime(2);
                    <span class="kwrd">string</span> message = sdr.GetString(3);

                    litMaintenance.Text =
                        <span class="str">&quot;This site is currently undergoing maintenance. &quot;</span>
                        + <span class="str">&quot;Maintenance is expected to start at &quot;</span>
                        + start.ToString() + <span class="str">&quot; and end at &quot;</span> + end.ToString()
                        + <span class="str">&quot;.&lt;br/&gt;&lt;br/&gt;&quot;</span> + message;
                }
                <span class="kwrd">else</span> {
                    <span class="rem">// throw an exception to show the default message.</span>
                    <span class="kwrd">throw</span> <span class="kwrd">new</span> Exception(<span class="str">&quot;No maintenance period found...&quot;</span>);
                }
            }
        }
    }
}
<span class="kwrd">catch</span> (Exception ex) {
    <span class="rem">// This is in case my database goes down during the maintenance period.</span>
    litMaintenance.Text = <span class="str">&quot;This site is currently undergoing maintenance.&quot;</span>
        + <span class="str">&quot; Please try again later.&quot;</span>;
}</pre>
<p>I’ll also alter my base page to automatically take the site down when maintenance is scheduled to begin.</p>
<pre class="csharpcode"><span class="kwrd">string</span> connectionString =
    ConfigurationManager.ConnectionStrings[<span class="str">&quot;DefaultConnection&quot;</span>].ConnectionString;

<span class="kwrd">if</span> (Request.Url.AbsolutePath.ToLower() != <span class="str">&quot;/maintenance.aspx&quot;</span>) {
    <span class="kwrd">using</span> (SqlConnection con = <span class="kwrd">new</span> SqlConnection(connectionString)) {
        con.Open();
        <span class="kwrd">using</span> (SqlCommand com = con.CreateCommand()) {
            com.CommandText = <span class="str">&quot;GetCurrentMaintenancePeriod&quot;</span>;
            com.CommandType = CommandType.StoredProcedure;

            <span class="kwrd">using</span> (SqlDataReader sdr = com.ExecuteReader()) {
                <span class="kwrd">if</span> (sdr.Read()) {
                    Response.Redirect(<span class="str">&quot;Maintenance.aspx&quot;</span>);
                }
            }
        }
    }
}</pre>
<p>
  </p>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p><strong>Code Sample</strong></p>
<p>I’ve included a sample website with a SQL script to show how all the pieces fit together. Just download the files, run the SQL against your database, open the website (I used Microsoft Visual Web Developer 2008 Express Edition), and put your connection string into the web.config. Then, add some rows into the MaintenanceSchedule table and run the site to see how it all works.</p>
<p><a href="http://www.geekscrapbook.com/wp-content/uploads/2009/08/MaintenanceTest.zip" target="_blank">Download Sample Code (.zip)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2009/08/04/asp-net-maintenance-scheduling-made-easy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Sub-query vs. the &#8220;UPDATE FROM&#8221; Statement</title>
		<link>http://www.geekscrapbook.com/2009/07/11/the-sub-query-vs-the-update-from-statement/</link>
		<comments>http://www.geekscrapbook.com/2009/07/11/the-sub-query-vs-the-update-from-statement/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 14:03:49 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.geekscrapbook.com/2009/07/11/the-sub-query-vs-the-update-from-statement/</guid>
		<description><![CDATA[From time to time I run across a table I need to update based on an ID column or other condition that doesn’t originate from that table. This usually occurs when there are one or more foreign keys in play. For instance, consider the tables below: Categories CategoryID Name Products ProductID CategoryID Name Price Suppose [...]]]></description>
			<content:encoded><![CDATA[<p>From time to time I run across a table I need to update based on an ID column or other condition that doesn’t originate from that table. This usually occurs when there are one or more foreign keys in play. For instance, consider the tables below:</p>
<p><u>Categories      <br /></u>CategoryID     <br />Name</p>
<p><u>Products</u>     <br />ProductID     <br />CategoryID     <br />Name     <br />Price</p>
<p>Suppose I want to collapse the categories named Televisions and Ipods into a the Electronics category, knowing only the category names. There are two obvious ways to pull off the update statement: using a sub-query OR an UPDATE FROM.</p>
<p><strong>Using a sub-query</strong></p>
<pre class="csharpcode"><span class="kwrd">DECLARE</span> @NewCategoryID <span class="kwrd">int</span>
<span class="kwrd">SELECT</span> @NewCategoryID = CategoryID <span class="kwrd">FROM</span> Categories <span class="kwrd">WHERE</span> Name=<span class="str">'Electronics'</span>

<span class="kwrd">UPDATE</span> Products <span class="kwrd">SET</span> CategoryID = @NewCategoryID <span class="kwrd">WHERE</span> CategoryID <span class="kwrd">in</span> (
    <span class="kwrd">SELECT</span> CategoryID <span class="kwrd">FROM</span> Categories <span class="kwrd">WHERE</span> Name <span class="kwrd">IN</span> (<span class="str">'Televisions'</span>, <span class="str">'Ipods'</span>)
)</pre>
<p>Here we simply ensure that our category is in a list. It’s important to remember that the list here gets queried fresh for each row. For a small table or a simple, well indexed, table this isn’t a real problem. Now, imagine there are millions of categories in our table. We’ve dramatically increased the processing time by adding a sub-query.</p>
<p><strong>Using an UPDATE FROM</strong></p>
<pre class="csharpcode"><span class="kwrd">DECLARE</span> @NewCategoryID <span class="kwrd">int</span>
<span class="kwrd">SELECT</span> @NewCategoryID = CategoryID <span class="kwrd">FROM</span> Categories <span class="kwrd">WHERE</span> Name=<span class="str">'Electronics'</span>

<span class="kwrd">UPDATE</span> Products <span class="kwrd">SET</span> CategoryID = @NewCategoryID
<span class="kwrd">FROM</span> Products p <span class="kwrd">INNER</span> <span class="kwrd">JOIN</span> Categories c <span class="kwrd">ON</span> p.CategoryID = c.CategoryID
<span class="kwrd">WHERE</span> c.Name <span class="kwrd">IN</span> (<span class="str">'Televisions'</span>, <span class="str">'Electronics'</span>)</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>The UPDATE FROM statement has an advantage over the sub-query because it performs the query with the join only once. The WHERE still has to be evaluated on each row, but if you look at our last example the WHERE was being evaluated for every row in the categories table for every row in the products table, or, the product of the count of rows in each table. So we’ve saved time by not running an extra query for each row and by cutting down the number of expression evaluations to perform.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geekscrapbook.com/2009/07/11/the-sub-query-vs-the-update-from-statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
