← All articles

DbDataReader Mishap

A debugging gotcha: leaving a DbDataReader sitting in an unpinned Watch window during a test run triggered it early and broke a unit test.

Donn Felker

Donn Felker

2007.08.09 · 1 min read

This is something that I’m almost afraid to admit to. *sheepish grin*

I was debugging a DbDataReader Unit Test and all of a sudden it started to fail. After  about 5 minutes of thrashing I saw that I had put the DbDataReader object into the Watch window (which was not pinned — therefore I could not see it). I was checking a value of the DbDataReader and working with it in the watch window. Well, I forgot to remove that watch, and as soon as the unit test started again, it bombed bout because as soon as the DbDataReader was available it attempted to perform some work on it (before the Read method was called). Therefore when we did call anything on the DbDataReader later in the game, it blew up because it had already thrown  an exception in the watch window.

Ooops. 🙂

Moral of the story: Make sure you delete your watch variables when you’re done. Oops. 🙂 Perhaps I should be using the Auto’s window instead. 🙂

Donn Felker

Written by Donn Felker

I've spent 25+ years shipping software, writing books, and running my own companies. I write about thinking clearly, working for yourself, and doing real work while AI rewrites the rules. New essays land here every week.

Get the newsletter

Keep reading