Click here to Skip to main content
13,300,654 members (54,747 online)
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 30 Sep 2005


, 30 Sep 2005
Rate this:
Please Sign up or sign in to vote.
Using Data Link files with SQLClient and OracleClient.


I used to love the simplicity of making connection strings by referring to a Data Link file while using OLE DB. This was a flexible way and it reduced the hassle of making packaged installations that refers to the development server. Then ADO.NET introduced the concept of optimized connectors for both SQL Server and Oracle. To my surprise, these optimized connecters are not able to read connection string stored in the data link file. Then I had to resort to saving the connection string to a text file which can then be edited by hand whenever a change in the connection is needed. This is re-invention of the wheel. Unacceptable!

Using the code

To use the code, import the cConnection class in your project. Then create an instance of the object like this:

Friend WithEvents oConnection As New _

If the name of the data link file is not included, the default name is used. The data link file is created in the same directory as the calling assembly.

The next step is to pass the connection string to the connection object.

m_cnAuthors.ConnectionString = oConnection.GetSQLConnectionString()

Data Link File Creation

Some times, one forgets to package the data link file or forgets to change the connection to the appropriate server. One has to go through the agony of navigating to the installation directory and creating it in front of the customer. They don't like it. They expect the usual next, next, next ... finish way of installation. It is with this in mind that the data link file creation was included.

To create a Data Link file, create a new empty text file, change its extension to .udl and then ask the operating system to call for you the Data Link app by double clicking over the file. This is translated to:

'Create an empty text file
Dim fs As New System.IO.FileStream(strFileName, System.IO.FileMode.CreateNew)

'Call Data Link App and write information to it
Dim psiProcess As New ProcessStartInfo
psiProcess.FileName = strFileName
Dim pProcess As Process = Process.Start(psiProcess)

The trick here is to close the filestream before starting the data link app process. Otherwise we will get errors.

Reading a Data Link file

The Data Link app writes all sorts of delights for parameters but only a few of them are essential to make a successful connection. To find all those appropriate parameters, I had to split the connection string and put it in an array. Searching had to be done in a loop as parameters are not always in a special order.

For Each strString In strArray

            If strString.IndexOf("Provider") > -1 Then
                strProvider = strString.Substring(strString.IndexOf("Provider"))
            End If

            If strString.IndexOf("Password") > -1 Then
                m_strPassword = strString
            End If

The searched parameters are then reconstructed and passed to to the appropriate connection object.


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


About the Author

Web Developer
South Africa South Africa
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 30 Sep 2005
Article Copyright 2005 by ra1234567890
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid