Home arrow Delphi-Kylix arrow Creating Data Link (UDL) Files in Delphi

Creating Data Link (UDL) Files in Delphi

The connection string required to connect to a database server may be created during design time or run time. There are circumstances under which you may want to store the connection string entirely outside the application, however. In those instances, Microsoft Data Link files are useful, as this article will explain.

Author Info:
By: Danish Ahmed
Rating: 5 stars5 stars5 stars5 stars5 stars / 8
August 06, 2007
  1. · Creating Data Link (UDL) Files in Delphi
  2. · Section 1: Adding a new ODBC Data Source
  3. · Section 2: Connecting with SQL Server Drivers
  4. · Section 3: Creating Data Link files programmatically
  5. · Section 4: More undocumented routines in ADODB

print this article

Creating Data Link (UDL) Files in Delphi
(Page 1 of 5 )

In my last few articles I have been using ADOConnection component to connect to the database server. I have also explained the role of ConnectionString in an ADOConnection and demonstrated how to create one. The ConnectionString created during design time (like the one we created in my last article) is stored in the Form file (.dfm). Alternatively, we may decide to create it during runtime by hard coding the connection parameters.

In both instances the ConnectionString can only be modified if the source is available. This may at times be undesirable, especially if the connection string needs to be modified, for example, when distributing the binary. In circumstances where hard-coding the connection parameters are not desirable, you can always fall back on Microsoft Data Link (.UDL) files or .INI files to store connection parameters outside the application. In this article I will discuss the methods to create UDL files to store and later retrieve the information required by ADO to connect to a database server.

From information available on the Internet, one is inclined to think that Borland encourages developers to use ADO but conspicuously enough the Borland Developer Studio 2006 documentation (as well as the documentation for previous versions) says absolutely nothing about Data Link properties and creating .UDL files. However, there are features in the IDE to make it easy to create Data Link (..udl) files; we will come back to address these later in this article. Let us first create a UDL file manually and specify the Connection object to use it instead of using a hard-coded Connection String.

To create a new Data Link file, browse to the project folder or DataLink folder in explorer, right-click and from the context menu select New|Text Document. Name it Test1.txt. Rename the file to change the extension to .udl instead of .txt; the file name should now be ADOConnectProj.udl. Make sure that the extension has actually been changed; often, when you try to change the file extension from within Windows what happens is that the file name (the first part ) is changed and the desired extension is added to it while the real extension remains unchanged. This would mean that you end up with something like ADOConnectProj.udl.txt so that the file type never changes. In such circumstances I always go back to the Command prompt and use "Ren" to not only change the filename but the extension as well.

Double-click on the file to bring up the Data Link Properties dialog. The Microsoft OLEDB Provider for ODBC Drivers is selected by default in the Providers tab. Click on the Connection tab; you will require a valid ODBC DSN (Data Source Name) to connect to the database. If you haven't already created a DSN for the database, read the next section which demonstrates how to create a new DSN from the ODBC administrator in the control panel.

blog comments powered by Disqus

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials