Thursday, May 22, 2008

Creating Connection Strings in 30 Seconds with UDL Files

I did this once in a training session and the class was amazed.  For years, I've been whipping out connection strings using a little-known technique involving UDL (Universal Data Link) files.  Here's the trick:

1. Create a new text file on your desktop and rename it to "Test.UDL" instead of the default  ".TXT" extension.  You'll need to show file extensions for this.

2. Next, double-click on this file to open up a connection string editor called "Data Link Properties."

3. Change to the Provider tab and choose the provider (OLE DB Provider for SQL Server in this example).

image_8_6A764D87.png (377×471)

4. Change to the Connection tab and set your basic connection settings.  You can also test your connection at this point if you want.

image_10_6A764D87.png (377×471)

5. Set any additional settings in the Advanced and/or All tabs, such as Connection Timeout.  Then click OK to save the file.

image_12_6A764D87.png (377×471)

6. Open the .UDL file with notepad and there you go...

Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TestDB;Data Source=localhost

You can remove the property called "Persist Security Info" because it's only used by the tool itself.  Enjoy.

No comments:

Post a Comment