30 Jan 2006

Slow SQL Server Delete

Just wanted to share a solution with you. Slow SQL deletes had begun to make an application perform poorly.

I had optimized a delete sproc as much as possible using WITH (ROWLOCK) and all the other performance tricks I could find. Showing Execution Plan in Query Analyser shed no light on the problem - it reckoned the delete was putting little load on the server. However, deleting 500 rows from a table was taking 40 seconds!

Turns out that if you have referential integrity set up between your tables (i.e. foreign key relationships with Foreign Key Constraints enforced), you need to ensure that all foreign key columns in your tables have an index. Otherwise, when you delete a record from a primary key table, referential integrity checks will cause table scans on the referring foreign key tables - and scans are terribly slow compared to index lookups. Sure enough I had neglected to put an index on one of the referring tables; when fixed the same query took less than 2 seconds.

EXAMPLE

TABLE: Customer

CustomerID (Primary Key)
Name
Address etc.

TABLE: Order

OrderID (Primary Key)
CustomerID (Foreign Key - Relationship with Customer table - THIS FIELD SHOULD BE INDEXED)
Order Details etc.

18 Jan 2006

W800i MP3 file problem

Hello zootfans. I've got a new mobile phone, a Sony Ericsson W800i, to replace my old SPV C500 (what a piece of crap that turned out to be!!).

The new phone seems pretty good so far. Just wanted to share with you something I've observed with it when trying to copy files to it via USB from Windows 2000.

Basically, don't try to access the MP3 tracks on the phone while the cable is connected to the pooter. Otherwise weird stuff happens, like tracks going missing. Here's how I transfer without problems:

1. Connect phone to computer via USB.
2. Copy tracks to phone either using Disc2Phone or Windows Explorer (the latter is quicker I reckon)
3. Use "Unplug or Eject Hardware" in the Windows taskbar to safely drop the connection.
4. Remove the USB cable from the phone.

I'm guessing step 3 won't be required on XP, but haven't tested it yet.

8 Jan 2006

Outlook 2000 Send/Receive Error "Operation Failed"

Bah, second time I've had to fix my crappy Outlook 2000. Works fine for a while then some day I'll press "Send / Receive" and it'll just come back with "The Operation Failed". Thanks a bunch Microsoft!

So I did a bunch of googling but the best solution I could find is just to create a new mail profile (in Control Panel > Mail), fill in all the bleedin' POP3 account details again and then add my old PST file with all my mail in it. You do that in Outlook - Tools > Options > Mail Setup > Data Files > Add. Then you have to set the old PST file as your default delivery location: Tools > Email Accounts > View / Change Existing Email Accounts > Deliver New Mail To The Following Location.

Only then can you delete the new PST file, smoke a doobie and pretend none of this crap ever happened. As ZZ Top said - "have you heard... what's the word??? It's Thunderbird".

6 Jan 2006

GuitarPort from Line6

Yay! My 73 quid ebay purchase finally arrived - a used Line6 Guitar Port. Okay, so I paid only a little less than for new - my least successful ebay bargain to date ;) Never mind, it's essentially a USB dongle and some software, so there's not much to go wrong with it when second hand.

So what is it? Basically it's a USB soundcard in a snazzy red case, with phono outputs, a headphone output, a line-in and most importantly - an input for an electric guitar (or microphone or whatever). That's not the clever bit - the clever stuff is the bundled software that processes the guitar input and makes it sound like I'm playing through a giant marshall stack with a grand's worth of effects pedals at my feet.

Really, for the money it is excellent - umpteen different amps modelled, a bunch of stomp boxes, a noisegate, a metronome and a tuner all united on a sweet computer interface that you control with just your mouse. For me with wife and tiny baby, being able to get a good sound without cranking up an amp is really cool. Headphones are fine - and if I want I can stick it through my stereo too.

Anyone considering purchasing one may have some questions like I did, about what else you need to run it an such. Well, because it's a soundcard in its own right all you really need is:
  • Computer with Win98-ME-2000-XP (I use a 1.8MHz laptop with 1Gb of RAM)
  • Guitarport Sound Engine software (included)
  • USB cable to GuitarPort (included)
  • GuitarPort (obviously :)
  • Electric guitar cable
  • Electric guitar
  • Headphones (they plug into the GuitarPort, not the computer)

That's the super-slimline basic requirements. Other than that you could run a cable from the line-out of your computer (if you have one) to the line-in of the GuitarPort; That would let you mix the computer's sound output with the modelled sound output of your guitar. Another groovy thing about it being a soundcard is that you can select it as an input in some recording software (e.g. the excellent and free Audacity) and record your rocking new sound.

Good job, Line6!

4 Jan 2006

ASP.NET 2.0 default form buttons

Back in the old days we used to be able to put as many forms as we liked on a page. One cool thing about that was they could be set to action on different pages, and the appropriate submit buttons would fire when Enter was pressed.

Now ASP.NET only really allows us to use one form (without nasty hacks) on a page, we have the problem that any submit button is potentially the target of the Enter key.

I did an ASP.NET 1.1 site where I had to solve this prob and used the MetaBuilders solution: http://www.metabuilders.com/Tools/DefaultButtons.aspx

Well, I just found out that the Panel object in ASP.NET 2.0 has a DefaultButton property which applies to all the child inputs of the Panel. Lordy loo.

There is a drawback however - it requires Javascript to work (like so many other ASP.NET controls). I'm no JavaScript hater but bear in mind that WCAG 1.0 Level A requires a site to work without Client Script. Nothing's ever easy is it?

3 Jan 2006

ASP.NET - controls created dynamically on event fail to fire their handler

Another wild goose chase, hoorah. So - I wanted to create an input control dynamically in response to a button being pressed on the same page. But I naturally wanted to handle events for the dynamically created control.

Here's how I did it:

1. Create a method e.g. LoadControl() to load the control.
2. Create the OnClick() handler for the button that initially loads the control onto the page, and wire it to LoadControl();

At this point, the control will appear in response to the OnClick() method, but will disappear again when you try to handle any further events that the control creates. This is because the control is only created in reaction to OnClick, not by the postback from the control. So....

3. Place code in the Page_Load() or OnLoad() method to call LoadControl() if certain postback criteria are met e.g. IsPostBack and detect some property of the dynamically loaded control from the postback.

4. And here's the bit that took me ages to track down - ensure you have given an explicit ID to every input of your dynamic control including buttons. Otherwise .NET will generate its own ID which may be different between requests, hence causing missed event handling.

Pretty obvious really, but I, as the Lancaster Bomber used to say, "had a cold". Ho ho ho.
If I helped you out today, you can buy me a beer below. Cheers!