January 2007 - Posts

Close your web connections too!

In an earlier post, I had talked about a Windows service I was working on.  This service periodically performs an HTTP GET request to check if a device that accepts incoming HTTP requests is still working.  It was pretty simple to perform the GET with .NET -- something I'm sure many of you have done hundreds of times before.

Everything worked fine, except that after a while, I couldn't connect to the remote device and was getting a timeout.  The other developer working on the device insisted that the device was running.  In fact, it was still sending me data from time to time.  We had a problem earlier with timeouts because a breakpoint was hit on the other device while my service was trying to send a GET request.  I was sure this was the problem again.

I stopped my service and added a few more debug statements to log to the event log.  When I restarted the service, everything worked fine -- for a while.  Then the timeouts started again.  I decided to double-check the documentation for the HttpWebResponse.  Man, was I embarassed:

You must call either the Stream.Close or the HttpWebResponse.Close method to close the response and release the connection for reuse.

Doh!  I wasn't calling the GetResponseStream method since I was just interested in the Status code (I was looking for a 200 - OK).  I didn't even think about the connection I was leaving open.

I wrapped the code in a try/finally that calls the Close method and things have been running smoothly ever since!  ;)

Technorati tags: , ,

Posted by PSteele | with no comments

Using ILMerge on Compact Framework Applications

Neil Cowburn has a very interesting post on using ILMerge with Compact Framework apps.  It seems that, by default, ILMerge always uses the .NET Framework Assemblies.  Neil talks about the targetplatform and platformdirectory command-line arguments that can be used to tell ILMerge to use the proper assemblies (the Compact Framework Assemblies in this case).

Posted by PSteele | with no comments

Windows Service stops updating event log

I've got a small project that involves a windows service.  The service is still in the development stages so I'm using the Application event log to keep track of what it's doing.  There's a lot of messages that get sent to the log right now (and yes, I know there's better ways to log but for this work, the EventLog is quick and easy).

At some point however, my messages just stopped.  The service was still running yet I wasn't getting any messages.  I was puzzled as to what could be wrong.  I checked the properties of the Application log to make sure the log size was big enough.  It was set at 512 KB which I thought was big enough, but the setting for what to do when the log size is reached was still set at "Overwrite events older than 7 days":

I had been doing so much logging, I had filled up the log, but none of the entries were over 7 days old -- so the calls to add log entries were just being ignored.  I changed the log settings to "Overwrite as needed" and I stopped losing log entries.  Now I know I'm not going crazy!

Technorati tags: ,
Posted by PSteele | with no comments

SVN and BerkeleyDB.

In my post on setting up Subversion, I had written to use FSFS as your repository type because "I've been told the Berkeley DB version is a little buggy".  I have no experience using BerkeleyDB with SVN (or BerkeleyDB by itself) so I was going on information I had heard.

Today, I got an email from Greg Burd.  Greg is the Product Manager for Berkeley DB/JE/XML at Oracle.  He is trying to fight this prevailing perception of BerkeleyDB ("it's buggy").  Instead of paraphrasing what he said, Greg gave me permission to reproduce his email in this post:

In the latest versions of SVN the issues using Berkeley DB have been fixed.  This was a joint effort between both engineering teams (SVN and DB) over a year ago.  Clearly there are pros and cons to DB and FSFS storage schemes, but to say that DB is "buggy" is inaccurate.

I'm trying to fight this mistaken impression that DB is buggy.  Due to the size and composition of the SVN community of users this is particularly important to me, developers are our most precious resource.

In this case there has been a lot of attention to the issues, few facts, and as a result the general feeling is that "DB is not reliable, or the best choice".  Clearly I disagree with both those statements.

DB isn't an easy product to integrate, developers must consider a number of complex issues.  A few of those slipped through the SVN team's fingers.  That's to be expected, I don't fault them.  They have a large complex code base, bugs happen.  We, Sleepycat at the time, had resisted some features that the SVN team suggested to us.  After some debate we added a few new things to ease SVN's development.  It turned out that our customers appreciated these new features too.  A perfect example of open source communities benefiting commercial users.  We helped them, they helped us and in the end both teams had better products.  I think you'll get this same story from anyone in the core SVN team, just go to irc://irc.freenode.net/#svn-dev and ask the developers about Berkeley DB and Sleepycat.  Tell them Greg from Sleepycat sent you.

Just trying to get the story right.  :)

regards,

-greg
Berkeley DB Product Manager - Oracle

I want to thank Greg for contacting me and allowing me to post this.  And as an additional note, if you look at the release notes for SVN 1.4 you'll see the following on BerkeleyDB support:

A common problem with previous versions of Subversion is that crashed server processes could leave BerkeleyDB-based repositories in an unusable "wedged" state, requiring administrators to manually intervene and bring back online. (Note: this is not due to bugs in BerkeleyDB, but due to the unorthodox way in which Subversion uses it!)

Subversion 1.4 can now be compiled against BerkeleyDB 4.4, which has a new "auto-recovery" feature. If a Subversion server process crashes and leaves the repository in an inconsistent state, the next process which attempts to access the repository will notice the problem, grab exclusive control of the repository, and automatically recover it. In theory (and in our testing), this new feature makes BerkeleyDB-based repositories just as wedge-proof as FSFS repositories.

If you decide to try Subversion, make sure you research your choices for repository type.  Each ones has pros and cons and with 1.4, it looks like some of the negative aspects of using BerkeleyDB have been eliminated.

There's also this press release from CollabNet where founding developer of Subversion, Karl Fogel, has positive things to say about BerkeleyDB.

Technorati tags: , ,

UPDATE: Fixed the mailto: link for contacting Greg Burd.

UPDATE2: Added a link to CollabNet press release.

Posted by PSteele | with no comments

Setting up Subversion

As noted in a previous post, I'm now using Subversion (SVN) for source code control of my mobile blogging app (along with a couple of other projects sitting on my hard drive).  Here's a quick "how to" on getting Subversion running under Windows XP with VS.NET integration.

1. Download TortoiseSVN.  As the website says, it's the coolest interface to SVN (to be accurate its both SVN and an SVN client all-in-one).  The download page has installers for both 32-bit and 64-bit.  Please make sure you download the correct one.  :)

2. Install TortoiseSVN.  It's a windows shell extension so you'll have to reboot after installing.

You're done.  No really.  That's pretty much all there is to getting Subversion running on your machine.  After rebooting, you can create your first repository with just a few mouse clicks.  In this example, I created a "SVN_Repositories" folder on my F:\ drive.  In that folder, I right-click, select "TortoiseSVN" and then "Create Repository Here...":

When asked for type of repository, select "Native Filesystem (FSFS)".  I've been told the Berkeley DB version is a little buggy.  That should be the default:

You should now be greeted with a dialog indicating that your repository has been created:

The folder now contains a bunch of folders and files.  This is all of the structure that defines your repository.  This is not an area you'll spend much (if any) time in.  It's just a datastore for Subversion.

If you want to see what's in this repository you just created, right-click while in any Windows Explorer window and select "TortoiseSVN" and then "Repo-Browser" (short for "Repository Browser"):

You'll now need to provide a URL for where the repository is located (subversion supports many protocols including http://, https:// and file://).  For my example, I pointed it to my F:\SVN_Repositories folder (note the use of "/" in the folder path instead of the traditional Win32 "\".  We're typing in a URL remember):

Our repository browser opens up and shows that the repository is empty -- which is expected since it is brand new!

At this point, you can add files or entire folders into the repository.  You could import an existing VS.NET solution by just right clicking on the solution folder and selecting "TortoiseSVN" and then "Import...".  However, this is a recursive operation that would bring everything into the repository -- including things you don't want like the "bin" and "obj" folders (no need to version control these since they are built from the source).  To make this really easy, we'll get AnkhSVN -- the Visual Studio.NET addin that adds Subversion integration.

There's two ways to get AnkhSVN:

1) Download and compile the source.  This is quite easy since you've got TortoiseSVN.  All you need to do is create a working directory for the source to be stored in and use TortoiseSVN to do a "Check out" over an http:// URL (if you're familiar with Visual SourceSafe, an SVN "Checkout" is the same thing as a VSS "Get Latest" -- no locking happens).  However, the AnkhSVN source requires that you have included the C++ compiler when you installed VS.NET.  If you're like me ("I'll never need that!"), you don't have the C++ compiler installed.  On to option #2.

2) Download a precompiled MSI installer.  I chose the RC4 candidate of version 1.0 which was released October 28, 2006.

Installing AnkhSVN is straightforward: close all instances of VS.NET and run the MSI installer.  No reboot is required.

Now lets get a project under version control!  For this example, I've created the canonical "Hello, world" C# console application:

To add this to our new repository, right-click on the Solution File in Solution Explorer and select "Ankh" and then "Add solution to Subversion repository...":

A dialog will pop up asking you to provide the location of the Subversion repository.  Again, I'll use the URL to my F:\SVN_Repositories directory:

You also have the option to create a subdirectory for this solution.  This is handy when you're going to be adding multiple solutions to a single repository.

Once you click OK, a progress dialog will be displayed as your solution is added to your Subversion repository.  When this is done, you'll notice a little green checkmark next to all of your source files in Solution Explorer:

This tells you that the files are under version control and that they match what is in your repository.  Now I'll make a small change to the source code:

namespace HelloWorldCS
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, Subversion!");
        }
    }
}

I save my changes and now Solution Explorer will now show a small red mark next to Program.cs and the HellowWorldCS project.  This indicates that your local file no longer matches what is in the repository:

To place these changes into our repository (thus creating a new version), you can either right-click on an individual file to update (like Program.cs) or right-click on the entire project (or even the entire solution).  Select "Commit..." from the menu:

A dialog box will pop up allowing you to place comments with this commit.  This is helpful to document the changes you've made:

Click "Commit" and a progress dialog will display as your changes are committed to the repository.  Solution Explorer will now display the green checkmarks next to your files since everything is up to date!

This post just scratched the surface of using Subversion -- or using source control in general.  There's version history, branching, diff'ing -- lots and lots of stuff to learn to harness the power of version control.  Play around with Ankh and SVN and you'll find that having some version control in your development (even if you're just a single developer) comes in handy when you need to revert back to an older version or patch a release.

Posted by PSteele | 1 comment(s)

My First Amazon Order

After reading Steve Makofsky's post about his first Amazon order, I checked out my order history.  To make it interesting, here's the first three books I purchased at Amazon:

  1. March 31, 1999: Using Visual Interdev 6, $24.00
  2. April 13, 1999: Programming Windows CE, $40.00
  3. April 30, 1999: Programming Windows, The Definitive Guide to the Win32 API, $48.00

What a trip down memory lane!  I think I still have the latter two books.  C'mon -- who really throws out a Petzold book?

Posted by PSteele | 1 comment(s)

Codemash: Off with the hair!

Alexey Govorin posted a comment about the shaving of Josh Holmes and Brian Prince at Codemash.  Alexey has posted a video so you can see them keep their promise of shaving their heads!  Thanks Alexey!

Technorati tags:
Posted by PSteele | with no comments

Update on Mobile Blogging App

Although Keith Elder recommended I put my mobile blogging app up on CodePlex, I'm going to hold off on that for a while.  Here's why:

First off, I need to clean up the code before any of it goes public.  It started as a prototype -- sort of a "I wonder how well this would work."  As many software projects go, this "prototype" is starting to grow into a real application so I need to clean up the code a bit before I end up with a mess.

Second, I'm using Charles Cook's excellent XML-RPC.NET library to make the calls to the Metaweblog API.  This got my application up and running much quicker.  However, this library is a generic library for making any kind of XML-RPC call.  I'm wondering if I could get a little speed improvement by writing the HTTP GET and POST's for the Metaweblog API, and parsing the XML myself.  Since this is something I may investigate, I'm going to refactor the XML-RPC communication into a separate assembly so that if I make the switch, it will be contained in that one assembly and won't affect the main application.

Lastly, Codemash was all about stepping out of your comfort zone (.NET for me!) and exploring other things.  To that end, I've set up a Subversion repository on my machine and my blogging app is currently maintained in there (I'll be posting a quick "How to set up Subversion" within the next day or two).  At some point in the future, I'll probably place the code on CodePlex (and out of my local Subversion repository).  But for now, I'd like to get some experience with Subversion.

Finally, I'm posting a few screenshots of the application.  Again, this started as a prototype so this isn't very exciting!  :)

   

   

 

And yes, it will work in landscape mode too!  :)

 

 

Technorati tags: , ,
Posted by PSteele | 1 comment(s)

Claiming my blog on Technorati

As part of getting better exposure of my blog, I'm updating it more often (January has already been better than any month in all of 2006), I'm also "claiming my blog" on Technorati.  As part of this process, I need to post a special link on my blog.

Technorati Profile

Posted by PSteele | with no comments

Codemash: Putting a face to the name

Thanks Keith Elder -- I made it on his "Who's Who at CodeMash" list.  Scroll all the way to the bottom and you'll see me slouching in my chair.  I also made a brief appearance in his Zune Squirt Video with Jason Follas -- I'm the guy sitting behind Keith unpacking my lunch and getting ready to feed my face... :)

Posted by PSteele | with no comments
More Posts Next page »