473,414 Members | 1,711 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,414 developers and data experts.

How to Create a Data Link File

ADezii
8,834 Expert 8TB
Rather than using CurrentProject.Connection or entering your own Connection information, ADO supports storing Connection information in an external file called a Data Link File (which normally has a *.UDL extension). Data Link Files provide two very important capabilities:
  1. They implement a graphical interface for constructing what can be complex and confusing OLE DB Connection Strings.
  2. They offer a way to allow Users to edit Connection information, for example, by entering their own User Name and Password, without the necessity of writing code to capture this information.
-----------------------------------------------------------------------------------------------------------------------

The process of creating a new Data Link File is simple and straightforward:
  1. Right Click in Windows Explorer and choose New ==> Text Document. Doing so will create a New Text Document (*.TXT) in the current Folder.
  2. Rename the file to any name you like, changing the extension to .UDL. Windows will warn you that changing the file name extension may make the file unusable; respond Yes to this warning.
  3. Double-Click the file to edit the Data Link properties.
  4. Select the Provider tab and choose the appropriate Provider.
  5. Select the Connection Tab and fill in the Database Name and Log in information.
  6. Click the Test Connection button to verify that the information entered is correct, and then click OK to save the file.
-----------------------------------------------------------------------------------------------------------------------

Once you've created a Data Link File, you needn't supply any information when opening the Connection in code other than the location of the *.UDL file. This process makes it simple for you to manage changing Data Sources without having to modify any code. When you want to open a Connection based on a UDL file, you simply specify the *.UDL file name as the ConnectionString property, or specify this information when you call the Open Method.
For the purpose of this Tip, I'll create a Data Link File (SQLServer.udl) that will establish a Connection to the Northwind Database residing in a Local installation of SQL Server. A Connection will be opened via the Northwind.udl Data Link File, a Recordset will be created based on the Employees Table, and the First and Last names of Northwind Employees will be printed to the Immediate Window.

-----------------------------------------------------------------------------------------------------------------------

Relevant information regarding the creation of the Data Link File is as follows:
  1. Provider Tab
    1. Provider: Microsoft OLE DB for SQL Server
  2. Connection Tab
    1. Server Name: (local)
    2. Select a specific User Name and Password Log on option
    3. User Name: sa
    4. Password: none
    5. Select Database on Server: Northwind
-----------------------------------------------------------------------------------------------------------------------

Now, the code segment that ties it all together. Pay particular attention to Line #6:
Expand|Select|Wrap|Line Numbers
  1. Dim cnnSQL As ADODB.Connection
  2. Dim rstEmployees As New ADODB.Recordset
  3.  
  4. Set cnnSQL = New ADODB.Connection
  5.  
  6. cnnSQL.Open "File Name=" & "C:\Test\SQLServer.udl"
  7. Debug.Print cnnSQL.ConnectionString
  8.  
  9. rstEmployees.Open "Employees", cnnSQL, adOpenKeyset, adLockOptimistic
  10.  
  11. Do While Not rstEmployees.EOF
  12.   Debug.Print rstEmployees![FirstName] & " " & rstEmployees![LastName]
  13.   rstEmployees.MoveNext
  14. Loop
  15.  
  16. rstEmployees.Close
  17. cnnSQL.Close
  18.  
  19. Set rstEmployees = Nothing
  20. Set cnnSQL = Nothing
-----------------------------------------------------------------------------------------------------------------------

Connection String generated from code line #7:
Expand|Select|Wrap|Line Numbers
  1. Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;
  2. Initial Catalog=Northwind;Data Source=(local);Use Procedure for Prepare=1;
  3. Auto Translate=True;Packet Size=4096;Workstation ID=DEZII;
  4. Use Encryption for Data=False;Tag with column collation when possible=False
Dec 3 '07 #1
0 14228

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Lauren Quantrell | last post by:
Is there a way to create a text file (such as a Windows Notepad file) by using a trigger on a table? What I want to do is to send a row of information to a table where the table: tblFileData has...
3
by: G rumpy O ld D uffer | last post by:
This is probably a 'Low-Level' question to all the ACCESS experts but I've only been using ACCESS for a couple of weeks. I've been given 30+ (and counting) separate 'Weekly' Databases which all...
18
by: Al | last post by:
I'm still trying to do this but it never worked! In a .cpp file, I write the code, and at the beginning, I write: #ifndef MYLIST_H #define MYLIST_H ....to end: #endif What's wrong with it for...
11
by: mesut demir | last post by:
Hi All, When I create fields (in files) I need assign a data type like char, varchar, money etc. I have some questions about the data types when you create fields in a file. What is the...
6
by: windandwaves | last post by:
Hi Folk Some of my clients asked me to create "fancy emails" for them (aka html formatted emails). I know how to make a nice html document, but I had trouble creating a simple way to provide...
5
by: nephish | last post by:
Hello there, i have an app that i need to be able to publish a link to download a csv file. i know that i can use php to make the file, but how to i link to it through php. like if i have an...
3
by: shapper | last post by:
Hello, I need to add a XML file from an Access database. Could someone tell me what would be the best approach? Thanks, Miguel
4
by: Billy Barth | last post by:
I would like to create a RSS feed from my Access Database. I have an Access table for news which has the article title, date, and story in it. What I would like to do is pull the data from there...
15
by: Killer42 | last post by:
Hi all. Ok, I'm using VB6 but I think the answer to this (if there is one) is more likely to be found in the Access forum. I have a situation where I've got tens of millions of records, spread...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.