Have you ever had to create or change a connection string for one of your applications? It can be a very difficult thing to do, especially when on-site and/or you have no development environment handy. Well this should make your life a bit easier.
Using the Application
Just extract the file Connection String Editor.hta to somewhere on your PC and run it, by double clicking on the file.
You will be presented with a window containing a textbox and a couple of buttons.
- Text Box: This is where your connection string goes.
- Edit Button: Clicking this prompts for a new connection if the text box is empty. Otherwise it prompts you to edit the current connection string.
- Copy Button: Clicking this copies the contents of the text box to the clipboard.
And that's just about all it does.
How Does It Work?
This little application is an "HTML Application" (HTA) - which is basically a HTML web page that runs as a local application in a window of its own. If you don't believe me, then just find some text file, change the extension to .hta, and double-click on it.
You can do anything with HTAs that you can with a local VBScript, except you get an easy way to implement a user-interface with your scripting. For more information on HTAs, just search for "HTA Application" on Google, there loads there.
But What About the Other Dialog That Comes Up?
That's the bit that makes this application worthwile, but it wasn't hard to do at all. Along with all the things that MDAC installs (they're the database access components), you get something called "Microsoft OLE DB Service Component". The actual DLL is oledb32.dll.
This object called "DataLinks" hides in there, and it seems the sole purpose of this object is to edit connection strings. If only has two methods:
- PromptNew: This does exactly what it claims to, and returns the new connection string. As a string. Cool.
- PromptEdit: This takes in an ADO Connection object, whose connection string you will be prompted to edit.
So to edit a connection string just create an ADO Connection object, populate the ConnectionString property and pass it as a parameter to a
PromptEdit method. Bob is everyone's uncle. Hurrah!
This "DataLinks" class can be a really useful one to use in your application installers as custom actions and stuff. As easy as setting up a DNS, but you can control where the result goes.
As for the copy to clipboard thing, well I take no credit for that sneaky bit of scripting. That method was posted to the microsoft.public.scripting newsgroup by Christoph Basedau (do a Google Group search for "about:clipdata" to find the actual post).
This is my first attempt at HTAs and I think they're pretty cool. I know the HTML and stuff isn't that nice, but it took me longer to write the article than the code. This is more about what it does than how it does it, so I hope yous get some use out of this. Cheers.