Wednesday, September 16, 2009

Windows 7: Sound Problems on Dell Studio 15 Notebook

Windows 7 stopped acknowledging the onboard speakers on my Dell notebook yesterday.  The only output options I had were via the HDMI port and the headphone jack.  Everything looked normal in device manager (no missing drivers) and no new software was installed to my knowledge.  I ended up fixing the issue by re-installing the audio drivers from the DVD that came with the computer.  Since Windows 7 was not the OS that came with the computer when I got it I had to choose Vista as my OS, but everything installed normally and the issue was resolved.

Tuesday, September 15, 2009

Code: Handling SQL Command Timeout Errors

Unfortunately there is not an exception object in .Net that corresponds directly to a command timeout.  However you can specifically handle one by checking the Number property on the exception.  The number for an SQL Exception happens to be –2 (Using reflection you can see the TdsEnum in System.Data.SqlClient).

catch (SqlException ex)
//Sql time out exception number is -2
if (ex.Number == -2)
//timeout exception, tell user to try changing params
lblTimeOut.Visible = true;
throw (ex);

Code: Setting Command Timeouts using Data Access Application Blocks

When doing database work in .Net you can set a timeout value in your connection string.  This timeout specifies the length of time (in seconds) to wait for a connection to the database server to be established.  If you want to specify a timeout value for your stored procedure in SQL command to complete, you need to set the time out on your command object.  If you are using Enterprise Library’s Data Access Application Blocks your code should look similar to below

Database db = DatabaseFactory.CreateDatabase("ConnectionStringName");
using (DbCommand cmd = db.GetStoredProcCommand("StoredProcedureName"))
    cmd.CommandTimeout = 60;
    int rowsAffected = db.ExecuteNonQuery(cmd);

Tuesday, September 8, 2009

Code: ASP.Net MVC Maintain Checkbox State

Below is a quick and dirty way to maintain a check box checked state during postbacks with MVC:

<%= Html.CheckBox("IsSecure", (Request.Form["IsSecure"] ?? string.Empty).Contains("true"))%>

Code: ASP.Net MVC SelectList / DropDownList Selected Item

I spent an hour on a strange issue on my MVC page the other day where MVC would not obey my SelectedItem assignment on a drop down list.  I originally thought the issue was how I was making the assignment in code, or the object I was using to do the binding, but it turns out that some built in MVC functionality was actually working against me.  If you name your ViewData key name the same name as your Html.DropDownList item, MVC will attempt to populate the selected value for you.  However I wanted to manually set the selected value so my solution was to change this:
<%= Html.DropDownList("Encoding", ViewData["Encoding"] as SelectList)%>

<%= Html.DropDownList("Encoding", ViewData["EncodingData"] as SelectList)%>

And in my controller I just needed to change the ViewData key name accordingly:
Dictionary<string, string> pushPull = new Dictionary<string, string>();
pushPull.Add("pull_encode", "Pull");
pushPull.Add("push_encode", "Push");
if (pushPullValue == "") pushPullValue = "pull_encode";
ViewData["EncodingData"] = new SelectList(pushPull, "Key", "Value", pushPullValue);

Wednesday, September 2, 2009

Fitness: Listen to Music to Improve Your Workout

There have been numerous studies on the effect of listening to music during exercise, Men's health has a good summary and recommendations in their article The Science of Workout Music.  Below is a list of songs that seem to work well for me.  These are just some initial suggestions, use whatever motivates you.

Kanye West - Stronger
Kanye West - Gold Digger
Linkin Park & Jay-Z - Numb/Encore
Linkin Park - Somewhere I Belong
Paramore - For a Pessimist I'm Pretty Optimistic
blink-182 - All the Small Things
Fergie - London Bridge
Linkin Park - Papercut
Aerosmith - The Other Side
All American Rejects - Dirty Little Secret
Aerosmith - Mama Kin
All American Rejects - Move Along
Fall Out Boy - This Ain't A Scene, It's An Arms Race
blink-182 - Dammit
Buckcherry - Lit Up
Green Day - Basket Case
Eminem - Lose Yourself
Linkin Park - What I've Done
Linkin Park - Faint
Def Leppard - Promises
Green Day - Hitchin' A Ride
Everclear - Santa Monica
Eminem - The Way I Am
Evanescence - Taking Over Me
American Hi-Fi - Flavor Of The Weak
blink-182 - Adam's Song
Green Day - Brain Stew
Jay-Z - I Just Wanna Love U (Give It 2 Me)
Limp Bizkit - My Way
Lit - My Own Worst Enemy
Missy Elliott - Gossip Folks
New Found Glory - My Friends Over You
Pink - Sober
Rage Against The Machine - Renagades of Funk
Van Halen - Dance The Night Away
Van Halen - Why Can`t This Be Love
Van Halen - Right Now
Theory of a Deadman - Bad Girlfriend
Theory of a Deadman - So Happy
Tantric - Breakdown
Sum 41 - In Too Deep

Tuesday, September 1, 2009

Tech: Opera 10 Web Browser First Impressions

First let me admit that my current web browser of choice is Firefox, however I also have chrome and IE (and now opera) installed.  Opera 10.0 was released today so I thought I'd take a look and see how it stacks up.  The download is 6.6 MB, so not a bad size.  Installation is quick, choosing custom just lets you change the install path and choose to create start menu, desktop, or quick launch icons.  One thing to note that I installed this on Windows Server 2008 which only has the Windows classis UI, so buttons etc may look different.

The screen shot below is Opera 10 on Google's home page.  One issue I noticed immediately is the address bar didn't span the whole width when I reduced the size of the window for the screenshot.  This was remedied by expanding the size of the window which then showed the address bar and the search bar, and resizing the width by clicking between the two boxes.  I think I prefer chrome's approach to having a single bar for both purposes.

Opera on the left, Firefox on the right.

image image

I then opened 4 tabs with both browsers:

image image

With,, Hulu (paused on a video), and pages loaded. Opera was using 176,000K of memory, Firefox was at 187,000K.  My machine has 6 gig of ram so even though those numbers seem high I still have plenty to spare on my system, they may be more frugal on system with less memory (but maybe not).  After killing all the open tabs except Google, Firefox's memory usage dropped to 89,000K whereas Opera hung around 149,000K.  Unexpectedly I did not have to install flash on Opera's browser when I went to Hulu.  So I then went to a Silverlight site and didn't have to install it either.  Nice. 

Opera feels very fast when navigating.  Pages load like they are in a hurry.  Opening a new tab loads a speed dial window showing your most visited sites in thumbnails.  There is a little x in the top right corner to remove unwanted items from the speed dial page.


One feature that only Firefox has implemented which keeps it at the top of my list is the ability to select a section of the page, right click and choose "View Selection Source" so you can see the html of your selection.  This feature is also not available in Opera 10.  New to Opera 10 is inline spell checking, so the browser will underline misspelled words in text boxes (this feature is available in Firefox).

I was unable to select gMail as my mail service when clicking on mailto links.  The 4 options shown to me were Yandex, Fastmail, Opera Mail, and  I use (and have never heard of none of these).  I've read other blogs that seem to show gmail being provided as an option.  I don't know why it wasn't provided to me.  I even went to my gmail with opera logged in, restarted the browser, and still no change.  This will be a deal breaker if I cannot resolve the issue.

For the brief set of pages I visited Opera rendered all content correctly and quickly, and seemed faster than Firefox.  However the lack of "View Selection Source" and using gmail as my default mail provider leaves Firefox as the reigning browser of choice for me.