Y'herd thisun? 

“I’m nauseatingly pro-American. It is where great things are possible.”

by Elon Musk

DataLink tips

TaggedCoding, Database, DotNet

I find it interesting how many folks have never heard of Datalink files or only know of them as part of the VisualStudio wizards.

A data link is nothing more than a file-based connection like a file-based DSN; what's more making a data link is as easy as right-clicking on your desktop, choosing to create a new text file then changing the file's extension from .txt to .udl. Voila, power!

I was not at first a fan of using UDLs. But they do have their place (esp to replace FileBased ODBC connections with ADO provider connectivity). However, the real thing I have always liked about the Data Link GUI is that it makes generating connection strings soooooo easy ... and they are pre-tested before I stick them in my apps.

If you haven't ever tried this technique, you should at least try it once. Just create a data link (right click on your desktop and create a new empty text file, save it, then rename it to have the extension ".udl", see how the icon changes? it's now a mini program). Double click on the udl file and run through the wizard to make and test your connection, then save it.  Now drop the file on NotePad ... and copy the Provider string right into your app.

It's a heck of a lot easier than the documented advice of putting an ADO Data control on a form and copying the settings then removing the control (dumb) or using the DE and manually copying the full text from the read-only Properties list.

If you don't want the UDL hanging around after you have made the connection string, just delete it ... or play with the feature of using the file as a dynamic connection system by putting the file in a shared location and passing the path to your Connection object as needed like:

Dim cn as ADODB.Connection
Set cn = New ADODB.Connection
cn.ConnectionString = "File Name=" & App.path & "\MyUDL.UDL"

(Note, you have to use the File Name technique carefully, it is "File Name=" & ... with each word Proper-Cased, a single space between and No space between the words and the Equal sign)

Another tip is similar to the SmithVoice Jet File Security page ... a Data Link does not have to have the UDL extension to be used by your app. You only need it to call up the Data Link wizard GUI; After that you can rename the file to anything (Such as "boringthing.xxy" so that your users will not be tempted to look at it. Your Connection objects don't care what the file name is, they only care that the contents are in the expected format.

Hope this Helps!

Robert Smith
Kirkland WA

home     who is smith    contact smith     rss feed π
Since 1997 a place for my stuff, and it if helps you too then all the better