Monthly Archives: January 2009

SELECT * With MS SQL Server

SELECT * is not a good idea when you are creating a query/stored procedure etc. that will be used by various other queries, stored procedures and/or applications. If at a later date, the base table needs to be augmented with one or more columns#, anything that relies on a query using SELECT *  is likely to break.

But typing out a query with a huge number of columns is quite onerus. I discovered a very quick and easy way of populating a SELECT clause with all the attributes in a relation (using MS SQL Server). All you have to do is:

  1. enter a SELECT * query e.g. using Northwind:- SELECT * FROM Employees
  2. highlight the text of that query, then right-click on it
  3. on the resulting context menu, click Design query in editor…
  4. you will see the query, expanded out in the bottom section of the query design editor
  5. now, just copy and paste that text into your original query window (or, you could just click OK on the query design editor screen).

SQL Server tip

SQL Server tip

# Note: caution must always be taken when altering the structure of a relation, even if it is just adding attributes.

Multiple Active Result Sets (MARS)

I recently came across an error which is thrown when more than one DataReader executes on the same connection. The error meassage was:

There is already an open DataReader associated with this Command which must be closed first.

Basically, I was using two DataReaders in a method which was to be the SelectMethod of an ObjectDataSource. I nested one reader inside another to deal with the situation where the object which I needed to abstract required a many-to-one join query e.g. a book may have more than one author. So, when you read in the details for each book, you also need to read in the details of all of the authors of that particular book.

To make that error go away, you need to enable Multiple Active Result Sets (MARS). This is easily done, simply by adding ;MultipleActiveResultSets=True; to your ConnectionString. If you would like to read up on MARS, this MSDN article provides a good starting point.

Change the View Source Editor of Firefox

Firefox is highly configurable. One of the many things that it affords users, in terms of configurability, is the ability to choose the application that they want to use to view the source markup of pages loaded in the browser. Personally, my weapon of choice is notepad++ – an excellent, free text editor which has many cool features and is highly extensible.

So, to make notepadd++ the view source editor of Firefox, follow these simple steps:

  1. open firefox and type about:config in the address bar.
  2. at the top of the page, immediately below the tab, you will see a textbox which enables you to filter the possible settings. Type in “editor”, as depicted in the screenshot below.
  3. change the value of view_source.editor.external to true.
  4. enter the filepath to your installation of notepad++ in the view_source.editor.path configuration item.

Change Editor

You’re done. Next time you fire up “the fox” and click View/Page Source (or ctrl+U), the markup for that page will open in notepad++, with nice syntax colouring and all its other concomitant features.

I Built a Computer!

I took the plunge over the holidays and built myself a computer. This is something I feel all aspiring IT professionals should do at some point. As a programmer, I don’t think I should know all the ins and outs of my PC (the way a tech should). However, I think it behooves us, as professionals, to have a good understanding of the tools that we use for our “trade”.

Rather than inundate this post with photos, I refer readers to the album which I put together to capture the “build experience”. That can be viewed here. Figures 1, 2 and 3 show the relevant parts, itemised as:

Item Price ($AUD)
Antec Sonata Plus ATX Case (built-in power supply) $215.00
Seagate SATAII NCQ 1TB 7200RPM 32mb Cache $174.00
Gigabyte GA-EP45-DS3 P45+ICH10R 1394a 8Ch Audio ATX $189.00
Kingston DDR2 4G(2x2G)PC8500 1066Mhz $109.00
Gigabyte GF9600GT 512MB DDR3 PCIE2.0 $169.00
Antec TriCool 92mm Clear Case Fan with 3-Speed Switch $25.00
Intel ATX E8500 CORE 2 DUO/3.16GHz/6MB/1333FSB/LGA775 $289.00
Asus DVD Drive $32.00
Total $1,202.00

Note, I already had a mouse, keyboard and monitor. So the price is not inclusive of those items. As you can see from the photos, I sprung for a quality case. This made the build a bit easier. It also had a built in 550W power supply (PSU) , which was componentised. Now what does that mean?

A componentised PSU is one which allows you to only use what you need (in terms of hooking up cables). Figure 4 shows the cables which came with it. Back in the day, a non-componentised PSU would have all possible usable cables factory-connected. This meant for a headache in cable management. I only needed about half the cables in that picture. The rest I can stash away for when I want to add more stuff to the box.

For those of you who have never seen one, Figure 5 depicts the motherboard.  All of the silver bits at the top right-hand corner are the various ports which extrude from the rear of the box (USB, audio & monitor ports/connections etc). The big fan-looking thing is the CPU cooler which sits right above the CPU. I had added the CPU and its cooler to the motherboard just before I took that photo.

Just below that, a couple of lengthy orange/red slots can be seen. This is where the RAM is inserted. Figure 6 shows the same slots with the RAM inserted (apologies for the blurry photo).

The other important slots which I want to point out are the SATA slots, where you attach the cables that run from your hard drive and DVD drive. Those are the yellow ones in two parallel rows on the bottom left-hand corner of the motherboard (6, in all).

In Figure 7, you will notice some thin multicolored cords. These come with the case and are connected to the front USB ports, lights and power buttons. This is where you get the manual that came with your motherboard out and figure out where they connect on. Figure 8 shows where I have connected these onto the motherboard.

Finally, the clear, plastic component visible in Figure 10 is a fan which I purchased separately for the case to keep the hard drive cool. You can see from the front grill that there is capacity for 2 fans up front. These blow air over the drives, through the box and towards its rear.

The other great thing about doing your own build is that you don’t have to buy a copy of Windows. You are left to choose what operating system you want to go with. Free to choose, I like that. For now, I will satisfy myself with OpenSuse.

I think doing my own build probably ended up being a bit cheaper than buying a Dell. But that was never the main driver. I also noted that 3 separate cards in my previous PC (firewire, sound and ethernet) were on-board in this build. This means I walk out of the store with 3 less boxes and a few more bucks in my pocket. All in all, a fun project.