Click here to Skip to main content
15,867,986 members
Articles / Programming Languages / VBScript
Article

Connection String Editor

Rate me:
Please Sign up or sign in to vote.
4.88/5 (21 votes)
9 Oct 20033 min read 105.3K   2.5K   52   11
A tiny HTML application that will make your life easier

Image 1

Introduction

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 DataLinks object's 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).

Conclusion

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Ireland Ireland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Use .udl file, forgot to mention Pin
Igor Vigdorchik13-Oct-03 11:17
Igor Vigdorchik13-Oct-03 11:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.