April 2006 - Posts

I've Joined the Twenty-First Century - Dual Monitors at Last!
28 April 06 03:09 PM | Scott Mitchell

While I wouldn't label myself a Luddite (seeing as I'm a software developer by trade!), I am pretty far from the cutting edge. I recently joined this century, however, by upgrading my work environment to include dual monitors, a move I've been meaning to do over the past several years but have never gotten around to it for a variety of reasons. I've heard/read of the benefits[1][2][3], and my wife's been telling me how proficient she is with her dual monitor setup at work..... I guess it's a mix of laziness and cheapness that keeps me fairly wed to the status quo. I think I'd be a good Buddhist, since my desire for material items and “stuff” is pretty much nil.

Anywho, after enough years of kicking around the idea I decided this past weekend to take the plunge and go dual monitor. We went to Frys to see about getting another video card (since mine only has a single output) and matching monitor. Sadly, they weren't selling the monitor I had purchased from the store a year or two ago (a Sharp LCD 17” LL-172C-B), but I did pick up the same video card (except a PCI one, versus the original AGP one), a cheap-o GeForce 4000 MX, about $50.

Sadly, Sharp doesn't appear to be making the same monitor I had, but I found a site where I could buy a refurbished one for about half of what a new one would cost. I'm always a bit concerned when buying used/refurbished electronic equipment, but this monitor looks and behaves brand new. Setting up the dual monitors is fairly easy (I'm using Windows 2003). The only part that wasn't straightforward was in installing the video card. Once I installed it, the BIOS thought that the PCI card was the main video output, but Windows thought the AGP card was the video output. What happened was that the monitor plugged into the AGP slot wouldn't show anything and the one in the PCI slot would show the startup screen when turning the computer on, but would go blank once Windows had loaded. The fix was to go into the BIOS editor and set the primary display channel from PCI back to AGP.

And now I have two monitors! I've just been using this setup for a couple of days. I can't say how much of a real productivity boost there is, though. It's nice to have the two monitors, don't get me wrong, but I'm just not sure if, for what I do, two is any quicker than one. The only thing that seems to be a bit quicker is debugging, since I can have VS.NET on one screen and a browser in the other, which helps with interacting with the page/stepping through lines of code in the debugger.

Pardon the gunk on the keyboard, I need to clean that off one of these days.

Right now I'm trying out UltraMon, which adds a lot of nice features for dual monitor support, such as extending the task bar, providing buttons in the Windows title bar to quickly stretch windows across screens or move it from one screen to another, and so on.

Now that I've got two monitors, I'm wondering if it's worth it to go for three...... :-)

Filed under:
Generating a List of Unattached Databases
26 April 06 06:37 PM | Scott Mitchell

SQL Server databases are implemented as physical files with the MDF extension. They can be attached and detached from the running SQL Server instance through Enterprise Manager/Management Studio or via the sp_attach_db and sp_detach_db system stored procedures. Alex B. recently asked a question on the sql_server_maint listserv I'm on about how to list the unattached databases:

Is there a way to find out what db's are unattached on your server?

In short, Alex was interested in having a list of those MDF files on his file system that were not registered with the SQL Server instance. Michael Campbell chimed in:

You won't be able to get a list of unattached dbs. SQL Server will keep track of which files it currently has its hooks into, but once you detach a DB, SQL Server no longer tracks it - it's like it no longer exists as far as SQL Server is concerned. (Which makes perfect sense - as the alternative would be something lame like "SQL Server can't start 'cuz it can't find a file that you detached 3 months ago, and just now deleted...")

Michael suggested trying to move a file to determine whether or not it was attached. If attempting to move the MDF file gave you a locked file error, it was (probably) because it was attached to the SQL Server instance.

Here's a more thorough solution, one that uses a bit of SQL, a bit of command-line goodness, and a little program called Excel. (Excel, believe it or not, has helped out with a sundry of development tasks, such as auto-generating code, turning a list of statements into a series of INSERT statements (to ease porting data from a text file into SQL Server), and so on.) Here's what to do:

  1. Open Excel
  2. Get a list of the attached databases for the SQL Server instance by running the following query in SQL Query Analyzer:

    select [filename] from master.dbo.sysdatabases
  3. Copy the results from the results grid directly into a column in Excel. (I started it at cell A1.)
  4. Next, we need a list of all of the MDF files in the file system. Drop to the command line and run:

    dir /s /b C:\*.MDF > dblist.txt

    This will recurse through all of the directories on C: looking for any file with the extension MDF, and will save the results in a file named dblist.txt.
  5. Open dblist.txt in Notepad, copy its contents, and paste them into Excel. (I started this at cell C1.)
  6. Using the tip discussed at Comparing Two Lists with Conditional Formatting, with a few clicks of the mouse you can name the two list ranges and then apply conditional formatting so that the two lists will be color-coded such to show:

    -- What files are similar between the two lists (these are the attached databases)
    -- What files are attached, but not in the file system (in which case you probably have the MDF files on another drive)
    -- What files are in the file system, but not attached, which was what Alex was after

    The screen shot below shows the attached DBs listed on the left and the MDF files in the file system on the right. Those entries shaded green are those that are found in the list on the right, but not in the list on the left; namely, those database files on my file system that are not attached.
Excel to the rescue again! :-)
Filed under:
Paging Done RIGHT (in SQL Server 2000 & 2005)
25 April 06 01:25 PM | Scott Mitchell

In an earlier article of mine, Custom Paging in ASP.NET 2.0 with SQL Server 2005, I wrote about SQL Server 2005's new ROW_NUMBER() function, which makes efficiently returning a paged result in SQL Server 2005 relatively easy (blog entry). While the SQL Server 2005 technique is neat, not everyone has migrated to SQL Server 2005, and a number of 4Guys readers had asked for an article that examined efficiently paging results with SQL Server 2000. So I wrote the horribly mis-titled article, Efficiently Paging Through Large Results Sets in SQL Server 2000, which showcased the technique I've always used for implementing custom paging in ASP.NET 1.x.

In a word, it is the “wrong” way, as my technique, while more efficient than simply grabbing all of the records blindly as in default paging, is still more than an order of magnitude worse in performance than an improved version. My slow approach used a stored procedure that created a table variable into which the entire contents of the table to be paged through were dumped. This created a “synthetic ID” that could be used to correctly grab just the correct page of data. The inefficiency stemmed from the fact that all of the table's data was being poured into this table variable, which could be prohibitively slow for result sets with as little as tens of thousands of records.

After publishing the article I quickly started receiving emails from folks helpfully pointing out that my technique could be vastly improved upon by using SET ROWCOUNT to reduce the number of records that needed to be injected into the table variable. Using SET ROWCOUNT, you can instruct SQL Server to stop processing a query after a certain number of records have been processed. To retrieve the mth page of data when showing n records per page, one could simply grab the first m*n records and then return the last n records in that subset. When m is sufficiently small enough (that is, when retrieving small page numbers... 1, 2, 10, 15, etc.), m*n is likely to be much smaller than the total number of records in the table, thereby greatly improving performance. (It's a tad embarassing that I've overlooked ROWCOUNT for all these years, seeing as I've written an article on it in the past...)

I was planning on writing an article on this improvement when I got an even more clever suggestion from Greg Hamilton. Greg showed how the table variable could be dispensed of altogether. Rather than move all m*n records into a table variable, just compute the ID of record (m-1)*n+1. This is the ID of the record at the start of page m. Then, use SET ROWCOUNT to just get the next n records after (and including) that ID. The clever part was in efficiently finding the ID value of the (m-1)*n+1 record. Greg did this by using a query like so:

DECLARE @first_id int

SET ROWCOUNT @startRowIndex
SELECT @first_id = ID_Field FROM Table

Such a query assigns the last value of ID_Field in the result set to @first_id. Since the SET ROWCOUNT limits the result set size to the starting row index, the last record returned in the first record of the page to retrieve. Once this value has been obtained, the following query returns the appropriate page of data:

SET ROWCOUNT @recordsPerPage

SELECT ... FROM Table
WHERE ID_Field >= @first_id

Pretty slick! For more on Greg's technique, along with some performance comparisons, check out his article, A More Efficient Method for Paging Through Result Sets.

Learning that my approach that I've used for years had much to be improved upon imparts three important lessons:

  1. Never assume that your approach/code/algorithm is optimal. There may be (and likely is!) some way in which it can be optimized or better-tuned.
  2. Due to the breadth of technologies and concepts a web developer must be familiarized with (ASP.NET, SQL, client/server model, client-side script, etc., etc.), it's easy to overlook an important aspect on one area that can greatly affect performance or other areas of usability.
  3. No matter how much you may know (or think you know :-), there's always new things to learn. I guess this is part of what makes this job so fun - there's always something new to learn!
Filed under:
Visual Studio Express Versions - Free for Life
21 April 06 01:29 PM | Scott Mitchell

Previously, the Visual Studio Express line (SQL Server 2005 Express Edition excluded) were only free for one year, after which... well, who knew what would happen? Would Microsoft charge? Would they give another free year of service? I've had more than a few people express a shade of concern over the one-year period, worrying that they were essentially locking themselves into to dropping the big bucks on Visual Studio down the line.

That concern is now moot, thanks to Microsoft's announcement that the Visual Studio Express line is now free-for-life. From the official Express Line FAQ:

How much will these products cost?

Effective April 19th, 2006, all Visual Studio 2005 Express Editions are free permanently. This pricing covers all Visual Studio 2005 Express Editions including Visual Basic, Visual C#, Visual C++, Visual J#, and Visual Web Developer as well as all localized versions of Visual Studio Express.

SQL Server 2005 Express Edition has always been and will continue to be a free download.

Search Trends
21 April 06 10:49 AM | Scott Mitchell

Recently found out about a Google feature that's apparently a few months old - Personalized Search Trends. If you search through Google and have an account with them they'll kindly record your search history. While there may be folks who don't want their search history examined, I find it an invaluable tool since it can easily be searched and scanned. That link I found the other day that I forgot to bookmark is a lot easier to dig back up thanks to the Personalized Search. Moreover, there is potential for Google to use your search history / click through information to better provide search results, and the ability to bookmark search results (although this feature still needs some work, IMO).

Since I use Google as my search engine of choice, the Trends information provides an interesting insight into my searching habits. For example, looking at the top sites that I click through it's pretty evident that I'm a Web developer working on Microsoft technologies:

Top sites

1.
msdn.microsoft.com
2.
msdn2.microsoft.com
3.
aspnet.4guysfromrolla.com
4.
www.4guysfromrolla.com
5.
weblogs.asp.net
6.
scottonwriting.net
7.
en.wikipedia.org
8.
www.microsoft.com
9.
blogs.msdn.com
10.
www.w3schools.com

The Trends report also breaks down the search activity by month, day, and hour, along with the most popular search terms for each unit of time. Since searching, for me, is typically work-related, the hour report shows that my most productive hours are between 8 AM and 3 PM. And for some odd reason I was up once at four in the morning searching on Google for conversions from miles to yards.

I've found the quickest way to search for online documentation on .NET issues is, when in FireFox, to do the following:

  • Hit Ctrl+K (puts the cursor up in the “Quick Search“ box)
  • Type in class name, method name, or property name to search on, along with “msdn2“
  • Hit enter.

Very often the first result is the official docs on Microsoft's site. Quicker than opening or searching the offline docs, in my experiences. There's also a Google Microsoft search page, but the main Google search index works good enough for me.

Filed under:
May's Toolbox Column in MSDN
11 April 06 08:57 AM | Scott Mitchell

My fifth Toolbox column in the March 2006 issue of MSDN Magazine is now available online. The article covers the following three products:

  • Express Agent, a tool for adding job support for Microsoft SQL Server Express Edition and MSDE
  • BrowserHawk, which provides in-depth browser capabilities detection and logging
  • UltimateSearch, an ASP.NET site search engine

There was no book review for this issue. You can keep abreast of the latest Toolbox articles through the column's RSS feed or the Toolbox column category here on my blog.

Filed under:
Can You Learn ASP.NET in 24 Hours?
06 April 06 10:46 AM | Scott Mitchell

Earlier this week I blogged about my latest book hitting bookstores, Teach Yourself ASP.NET 2.0 in 24 Hours. Jeff Atwood chimed in with a blog post that pokes fun at the title Teach Yourself ASP.NET 2.0 in 24 Hours. Take a moment to read his post, it's both entertaining and brings up some good points, the main ones being:

  1. What's with the 24 Hours bit in the title? Why not 23 Hours? Or 25 Hours? Or 1 Hour? Or 5 minutes? Or 1 SECOND?
  2. How in the world can a book say that you can learn ASP.NET 2.0 in 24 Hours. It takes months, years... and even then who really knows it? (Perhaps I don't get out enough, but the only two people I've ever talked to/interfaced with that I felt really knew ASP.NET to their core were Scott Guthrie and Rob Howard. Now Scott, along with Mark Anders, invented ASP.NET, and Rob was a program manager from the early days. I'm know there are more folks out there who have as deep an understanding as those two, but the point remains - very, very, very few people can truly, profoundly know a technology whose breadth is so immense.)
  3. Books with titles like Teach Yourself X in 24 Hours cheapen the field. To quote from Jeff's blog entry: “I humbly submit that books with titles like Teach Yourself ASP.NET 2.0 in 24 Hours cheapen our craft. Any computer book with a length of time in the title -- weeks, months, days, hours -- is doing its readers a disservice by demoting software development from a craft you spend your life practicing to a mechanical activity that can be learned in a limited time window.“

I'd like to address each of these points Jeff makes.

What's with the 24 Hours bit in the title? Why not 23 Hours? Or 25 Hours? Or 1 Hour? Or 5 minutes? Or 1 SECOND?
Sams Publishing is the publisher with the Teach Yourself X in <INSERT TIME LIMIT HERE> series. Now I am not a publisher nor was asked to sit in any meetings when deciding these series structure and semantics, but my understanding is that the time periods are chosen for logical reasons. For a 24 Hour book, each hour corresponds to a chapter in the book that, in theory, takes an hour to work through. In a 21 Days book, there are 21 chapters, and the chapters are intended to cover more content at a deeper level of detail than in a 24 Hour chapter.

The point is that there is thought and meaning behind the time period. It's an indication to the prospective buyer on the depth of the material contained within and the “difficulty level” of the text. Want a quick, scatch-the-surface introduction to a technology? Pick up a Teach Yourself X in 10 Minutes. Interested in a more detailed examination, but one still geared for beginner- to intermediate-level developers? The 24 Hours series may be better suited. And if you want a more in-depth exploration of the technology, the 21 Days book is more up your alley.

How in the world can a book say that you can learn ASP.NET 2.0 in 24 Hours
The word “learn” means different things to different people based upon their experiences and expectations. To someone who has never created an ASP.NET page in her life, when she says she wants to “learn” ASP.NET she doesn't mean, “Explain how I can create a custom membership provider to utilize my existing application's database credential store.” She means, “How do I create a Web page that can collect user input?“ and “How do I show database information on a web page?“ Ditto for people who may have had some experience with competing technologies - classic ASP, PHP, ColdFusion - but is interested to moving to ASP.NET. Ditto for junior-level ASP.NET 1.x developers.

Some of the comments left in response to Jeff's blog entry suggested that the book's title spell out what, exactly, will be learned, because it's clearly impossible to learn everything in ASP.NET 2.0 in 24 hours. This information is available. The back of the book spells out what you can expect to accomplish. “In just 24 sessions of one hour or less, you will be able to create ASP.NET web pages that interact with user input and online databases.“ It has a bulleted list of what you can expect to learn:

  • Get started creating ASP.NET web pages
  • Collect and store input from users visiting your website
  • Display, sort, edit, and page through database data in an ASP.NET web page
  • Allow visitors to insert, update, and delete data from an underlying database
  • Build websites that support user accounts

The book's Introduction also includes a synopsis of the book's material and what a prospective reader can expect to learn. No where does it promise to make you an ASP.NET master ninja guru.

Furthermore, on the book's cover and spine it clearly says STARTER KIT in a font the same size as the “Teach Yourself.”

Someone who has architected and created large data-driven ASP.NET 1.x applications obviously isn't going to gain much from this book. But here's the kicker - this book ain't for them! What is a little frustrating is that they know this. You can't tell me some developer who's been around the ASP.NET block more than a few times actually says to herself, “I need to master ASP.NET 2.0. Ah, this Teach Yourself in 24 Hours ought to do the trick!” So why gripe about the title? (This provides a nice segue into the next section...........)

Books with titles like Teach Yourself ASP.NET 2.0 in 24 Hours cheapen our craft
I can see where this sentiment comes from - there's nothing more frustrating than working with some novice developer who's created his first data-driven website and now thinks he is some ASP.NET Master of the Universe. And, perhaps, books with such titles give a false sense of confidence to those who have worked through the book, allowing them to rationalize, “Well, I've put in my 24 hours and now I am an ASP.NET guru. Watch out Dino Esposito, your job will be mine shortly!”

But what I also think there's a bit of ego wrapped up in this. A top-notch developer has no doubt invested years in formal education, real-world experience, attending conferences/LUG talks/classes, and now, when he walks into the bookstores with his friends they see this book and say, “Oh, that's what you do all day? And it only takes 24 hours to learn it? Man, you have it easy.”

My take on it is thus: I like programming and really enjoy ASP.NET. I think it's neat and fun and interesting and cool how you can go from literally nothing to having a data-driven web application that can be used by people around the world in an amazingly fast amount of time. Furthermore, I want to spread that enthusiasm to folks. I want to say to those who may have never programmed, or to those who are using competing technologies, or to those who are just starting out - “Come over here and try out this ASP.NET stuff. Here, let me show you what it can do!” That's why I teach (which pays pennies compared to consulting). That's why I write (which pays better than teaching, but still is not anywhere near as lucrative as consulting). That's why I give free talks at local user groups and community-sponsored conferences here in Southern California. To get the word out!

To me, saying that titles like Teach Yourself X in 24 Hours cheapen the craft is tantamount to saying, “Our club is full. Go away.” It's not saying, “Let's welcome the newbies and get them excited about this technology.” Rather, it's saying, “Newbies are ok, but they must first realize how hard this is, how hard we've worked, and how much more we know than them.” I worry that such sentiment from the community will come across as pompousness to those very people whom we should be welcoming. (I'm not trying to imply that Jeff has a holier than thou attitude, as his humility is evidenced by various blog entries[1][2][3], but I think some folks do fall into this camp. And even if it's not an ego-driven attitude, it's one that can be off-putting to those entering the field.)

In closing, the Teach Yourself X in 24 Hours title may seem a bit of a laugh for an experienced ASP.NET developer who knows that ASP.NET is not something that can be “learned” in a scant 24 hours, but to those entering the field, such a title expresses the book's intent and level of detail, and I think it helps reassure an on-the-fence user that they don't need to be a computer whiz to get started with ASP.NET.

Hot Off the Presses - Teach Yourself ASP.NET 2.0 in 24 Hours!
04 April 06 08:10 PM | Scott Mitchell

As an author the most rewarding day in the life of a book is the day you are sent your author copies. When signing the author agreement many, many months ago, there is typically a clause that promises the author X copies of the finished book to give out to user groups, friends, family, coworkers, and so on. What follows are months filled with arduous writing, interspersed with reviews and the early stages of editing. The length of this stage depends on the number of authors, the length of the book, and the productivity of the author(s). My experience has been 3 to 4 months of writing, on average, but keep in mind that I'm verbose and that's typically writing three to four days a week for maybe six hours per day.

After the book has been written and the chapters submitted to the publisher, there's typically a month of author review, which involves the publisher editing the content for grammar and layout along with some technical editing/reviewing. Following that there's silence. The book is in the hands of the publisher as they put together the layout, get the book printed, have any accompanying media pressed, package everything, and distribute to the bookstores' warehouses. So after 3 to 4 months of really hard and tiring work, followed by a month (or two) of lightweight author review, there's 2 to 3 months of quiet. And then, it happens. That box of books arrives in the mail, your author copies. You get to hold in your hands the fruit of your labors. Those words that were just ones and zeros on your computer several month ago are now paper between your fingers. I imagine it's similar (albeit a very muted version) of what it must feel like to hold your child for the first time after their birth.

Today I received my author copies of my latest book, Teach Yourself ASP.NET 2.0 in 24 Hours (which is now available for purchase from online and local bookstores (ISBN 0672327384))! The book's first words were typed into Microsoft Word back in September 2005 and today, six months later, they are paper underneath my fingertips.

(In case you're wondering, the second most rewarding day for an author is when he sees it for the first time in a bookstore, sitting there proudly on the shelf. On a side note, if you ever do stumble across any of my books in a bookstore, please take a moment to turn it cover-out. That is, turn it so that the cover is facing outward, rather than just the spine. Thanks! :-)

...Now, about this book....

Teach Yourself ASP.NET 2.0 in 24 Hours is geared toward beginner to intermediate developers who are interested in learning ASP.NET version 2.0. The book is designed to be approachable by those who are brand new to development, and the first third of the book looks at fundamentals of server-side technologies (like ASP.NET), familiarizing oneself with Visual Web Developer, and a crash course of the Visual Basic programming language. Readers with experience with ASP.NET version 1.x (or other dynamic web technologies) will likely breeze through this first third.

The middle portion of the book looks at the core controls for creating data-driven ASP.NET pages. It begins with an examination of common Web controls like the Label, TextBox, DropDownList, RadioButtonList, and so on, and then transitions into working with databases, accessing data with the SqlDataSource control, and displaying data with the data Web controls, such as the GridView, DetailsView, FormView, DropDownList, CheckBoxList, and so on. This exploration also includes examining how to add paging and sorting support and creating GridViews that support editing and deleting of data and DetailsView controls that provide editing, inserting, and deleting capabilities.

The final third of the book examines master pages, membership, and site navigation, and then concludes with building a real-world web application from the ground up that ties together the lessons learned throughout the preceding chapters. This real-world application, whose design and creation spans three chapters, is a photo album application that allows for registered users to upload images to the website and manage them through a web-based administration page. Any visitor may view the images in a user's photo album, but only other registered users may leave comments about a picture.

Keep in mind that this book is targetted to the beginner to intermediate developer. If you're a hard core ASP.NET 1.x developer, this book is not the one you should pick up if you are interested in learning about 2.0. Rather, this title is for those developers brand new to ASP.NET who want to start with 2.0 or 1.x developers who would classify themselves as beginner- or intermediate-level. The book includes a CD with Microsoft's free Visual Web Developer software, which is the editor used throughout the book.

If you are a beginner- to intermediate-level developer interested in learning ASP.NET 2.0, or know someone who is, I hope you'll pick up a copy of Teach Yourself ASP.NET 2.0 in 24 Hours.

Scott Mitchell - Fabrikam Product Manager!
04 April 06 10:33 AM | Scott Mitchell

Everybody's favorite fictional company used for Microsoft demos - Fabrikam - has apparently hired me as a Product Manager... although I've yet to receive a letter of employment. It was this Office Groove 2007 demo that clued me in to my new position. You can fast-forward to the second chapter and right there they start talking about me and my collaborations with other Fabrikam employees around the world. It appears that my new position has be based out of New York, but apparently I get to travel back to San Diego on occassion when working from the PR firm.

Thanks to alert reader Gary Chin for giving me the heads up on my new job.

Filed under:
More Posts

Archives

My Books

  • Teach Yourself ASP.NET 4 in 24 Hours
  • Teach Yourself ASP.NET 3.5 in 24 Hours
  • Teach Yourself ASP.NET 2.0 in 24 Hours
  • ASP.NET Data Web Controls Kick Start
  • ASP.NET: Tips, Tutorials, and Code
  • Designing Active Server Pages
  • Teach Yourself Active Server Pages 3.0 in 21 Days

I am a Microsoft MVP for ASP.NET.

I am an ASPInsider.