Wednesday, September 27, 2006

How to generate a connection string

1 The other day I found myself trying to write my own connection string to a System DSN I had just set up. That was stupid and silly and I know that now. Seriously, who remembers the syntax for creating a connection string? No one. Why? Because we don't need to create these things every day. And also, it is stupid and silly.

So I donned the ceremonial robe and beseeched the great google for help. Of course, I was presented with a mountain of information on connection strings. But then it pulled out a large chest that looked like something right out of a pirate movie. I think this was because it happened to be International Talk Like a Pirate Day. The great google loves this stuff.

It spoke these words to me, "Avast! These examples be good, but ye have the noggin of a bilge rat. Perhaps ye be in need of some voodoo, ...some Windows voodoo." And it pulled a scroll from the chest and handed it to me with a twisted ferret look in its eyes.

Hmmm... voodoo, eh? Sounds iffy. But then again, not all windows voodoo is bad. There have been books dedicated to the subject. And I think we have all been in situations where we would gladly rub our computer monitors down with a fried drumstick from KFC while chanting the names of the 12 dwarves in reverse alphabetical order, if it would just keep IE from spewing random "Operation aborted" errors at our users. But that is another blog post. I wasn't that desperate, yet. I opened up the scroll, read the instructions and said to the great google, "This may be the grog talking, but I like sheh way you sthink." What follows are simple steps to get windows to generate a connection string that even a bilge rat could perform after a couple mugs of grog.

  1. Create a new file, the name doesn't matter, and give it a .udl extension.
  2. Double click on your new file. This will bring up the Data Link Properties dialog
  3. Select the "Use connection string" option and then click the "Build..." button.
  4. Your connection string will show up in the connection string text field. You can also access it by opening up your udl file in a text editor.

Thursday, September 14, 2006

Mouseless Firefox

1I just got back from vacation and I guess I left my mind on the beach, because I forgot to pick up my mouse on the way out the door. No biggy, I still have my laptop's touch pad and I don't really use the mouse much anyway. I was even able to pick up a new short cut key, just because I had to.

In Query Analyzer:
Shift+F6 - Switch between panes.

I think this is a good time to talk about some "mouseless" features and extensions that I have found very useful in Firefox. Here are some of my least known/most favorite shortcut keys for Firefox:

F6/Shift+F6 - Cycle through the frames on a page.
F7 - Enable/Disable caret browsing. The caret browsing is great for selecting and copying text.

One of my favorite Firefox add-ons is Mouseless Browsing. It takes some getting used to, but now I don't know what I would do without it. This extension enables browsing in Firefox using only the numpad keys. The extension puts a number next to each control or link on the page. All you have to do is type in the number and hit enter to browse to that link or control. You can even hold down the alt key while entering the number to open the link in a new tab. The numbers do mess with the formatting on the page, but it is really easy to turn them on or off. Just use the period key on the numpad.

Friday, September 08, 2006

Portable Apps are cool!

I'll be going on vacation next week to the beach and then to visit some family. That means I'll probably spend some time on their computer. Now, I like my little utilities that I use from day to day, and I would like to use them but I don't want to take the time to install them. I remembered that Hansleman was looking for a portable browser and it got me searching for other portable applications.

What is a portable application? Here is the definition from the PortableApps web site:http://portableapps.com/

A portable app is a computer program that you can carry around with you on a portable device and use on any Windows computer. When your USB flash drive, portable hard drive, iPod or other portable device is plugged in, you have access to your software and personal data just as you would on your own PC. And when you unplug, none of your personal data is left behind.

So, what kinds of portable applications are out there? About everything you could want and then some.

Luckily for me I had just picked up a shiny new Verbatim 512MB USB Flash Drive. It was just over ten bucks at Office Max. Its light and feels a lot sturdier than my last one. Here is a list of some of the apps that I have installed on my USB drive.

SysInternals:
Go to SysInternals while you still can and at the very least get:
Process Explorer
FileMon
RegMon
Autoruns
TCPView

Internet Stuff:
Browsar - Private browsing in IE. http://www.browzar.com
TorPark - Ultra private browsing in FireFox. http://torpark.nfshost.com/
Gaim Portable - IM Client. http://portableapps.com/apps/internet/gaim_portable

File Stuff:
7-Zip portable - Have you ever been stuck without a way to open up a zip file? http://portableapps.com/apps/utilities/7-zip_portable
ClamWin Portable - Portable virus scanner. http://portableapps.com/apps/utilities/clamwin_portable
FileZilla - FTP utility. http://filezilla.sourceforge.net/
Foxit Reader - Smaller and faster than Acrobat reader for pdfs. http://www.foxitsoftware.com/pdf/rd_intro.php

Just for fun:
Sudoku Portable http://portableapps.com/apps/games/sudoku_portable

Unclassified but cool:
PStart - PStart can be configured to start up when you plug in your USB drive. I creates an icon in your systray that acts like a start menu for your drive. Giving you quick access to the applications in a menu.

All these utilities only added up to 77MB. I wonder what it would take to get everything that we need to do our jobs as developers onto a 1GB USB drive. We wouldn't have to worry about dragging around laptops as long as we had a clean XP install to plug our drive's into. You wouldn't even require an internet connection for some of the apps. 1
I'll be going on vacation next week to the beach and then to visit some family. That means I'll probably spend some time on their computer. Now, I like my little utilities that I use from day to day, and I would like to use them but I don't want to take the time to install them. I remembered that Hansleman was looking for a portable browser and it got me searching for other portable applications.

What is a portable application? Here is the definition from the PortableApps web site:

A portable app is a computer program that you can carry around with you on a portable device and use on any Windows computer. When your USB flash drive, portable hard drive, iPod or other portable device is plugged in, you have access to your software and personal data just as you would on your own PC. And when you unplug, none of your personal data is left behind.

So, what kinds of portable applications are out there? About everything you could want and then some.

Luckily for me I had just picked up a shiny new Verbatim 512MB USB Flash Drive. It was just over ten bucks at Office Max. Its light and feels a lot sturdier than my last one. Here is a list of some of the apps that I have installed on my USB drive.

SysInternals:
Go to SysInternals while you still can and at the very least get:
Process Explorer
FileMon
RegMon
Autoruns
TCPView

Internet Stuff:
Browsar - Private browsing in IE.
TorPark - Ultra private browsing in FireFox.
Gaim Portable - IM Client.

File Stuff:
7-Zip Portable - Have you ever been stuck without a way to open up a zip file?
ClamWin Portable - Portable virus scanner.
FileZilla - FTP utility.
Foxit Reader - Smaller and faster than Acrobat reader for pdfs.

Just for fun:
Sudoku Portable

Unclassified but cool:
PStart - PStart can be configured to start up when you plug in your USB drive. I creates an icon in your systray that acts like a start menu for your drive. Giving you quick access to the applications in a menu.

All these utilities only added up to 77MB. I wonder what it would take to get everything that we need to do our jobs as developers onto a 1GB USB drive. We wouldn't have to worry about dragging around laptops as long as we had a clean XP install to plug our drive's into. You wouldn't even require an internet connection for some of the apps.

Thursday, September 07, 2006

Decode ViewState with PowerShell

We have been screwing around with ViewState lately, trying to resolve some issues and shrink down the size. In the process, we've downloaded several utilities to decode the viewstate. However, even these were failing to decode if the Viewstate was over a certain size or if it had non-native datatypes. Since we didn't have access to the source code, we couldn't fix the problems with the utilities. So yesterday, at approximately 3:57 pm, I thought to myself, "Gee, how hard could it be to write my own decoder?" But who wants to create a new VS project for a dinky little utility that you may never use again. Time for a PowerShell Script. It's one file with no compiling necessary.

This script reads the contents of a text file containing the viewstate in question. Then it decodes it, replaces the non-printable characters with pipe symbols and writes the results to another text file. You could easily rewrite this to pass in the viewstate string as a parameter to the script, if you wanted to. You're the kind of person who isn't afraid to paste a +50kb string into your command line of choice. Get down with your bad self!

A note on the non-printable characters: As of .NET 2.0, the viewstate is now delimited with non-printable characters. To learn more read Fritz Onion's blog on the subject.

Now, onto the script:

# Get the file from the arguments and read it into the x
$x = Get-Content $Args[0]

# Parse the string into a byte array
$byteArray = [System.Convert]::FromBase64String($x)

# Create a new encoding object
$enc = New-Object System.Text.ASCIIEncoding

# We need a charArray with the same length as the byteArray. I am having a
# hard time finding out how to create an strongly typed empty array of a given
# length in powershell. If you know how, please let me know. For now I just
# make charArray a copy of byteArray that will be overwritten later.
[System.Char[]]$charArray = $byteArray

# Do the decoding.
$enc.GetDecoder().GetChars($byteArray, 0, $byteArray.Length, $charArray, 0)

# Build the result string.
$charArray | ForEach-Object { $result += $_ }

# This is a neat regex to replace all the non-printing characters with something else.
# Then the result is written out to ViewStateDecoded.txt.
$result -replace "[\x01-\x1F]+", "|" | Out-File ViewStateDecoded.txt

I could probably get this down to 5 lines of code or less, but it more readable this way.

Wednesday, September 06, 2006

Set Window Title in PowerShell

1 It's been a month since my last post, and I'm sure that you were thinking I was dead. Not quite, just really busy. Here's a little time saving tip that I implemented last week in PowerShell. I was working on several issues and had multiple PowerShell windows open. Its kind of hard to find the instance of PowerShell that you are looking for while alt+tabbing through TaskSwitchXP. TaskSwitch even has a preview window, which helps as long as your window isn't minimized. The problem was that I had 3-4 PowerShell windows all titled "Windows PowerShell".

Wouldn't it be great if I could change the window title to something more meaningful? No sweat, PowerShell gives you access to the window through the $Host variable. The command looks like this "$Host.UI.RawUI.WindowTitle = 'My New Title'". Of course, I'll never be able to remember this and it does seem like a lot of typing. So I added the following function and alias statement to my profile.

function Set-WindowTitle($title)
{
$Host.UI.RawUI.WindowTitle = $title
}

set-alias swt Set-WindowTitle

Notice that I tried to mimic the verb-noun convention used by the rest of the PowerShell commands. Now, to set the title I can type in "swt 'My New Title'".