Microsoft KB Archive/189680

= How To Use Data Link Files with ADO =

Article ID: 189680

Article Last Modified on 7/15/2004

-

APPLIES TO


 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.1 Service Pack 2
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q189680



SUMMARY
ODBC includes the ability to save Data Source Name (DSN) information (which basically amounts to persisted connection strings) in a simple file rather than in the registry.

ActiveX Data Objects (ADO)provides similar functionality in the form of a Data Link file (*.udl).



Create a Data Link File
 Right-click the directory where you want to store the file, point to New, and then click Microsoft Data Link. A new file appears in the directory with the name New Microsoft Data Link.udl. Rename the file to Pubs.udl. Note: If using Windows 2000, right-click where you want to store the file, point to New, and then click Text Document. Change the txt filename extension to udl.

 Double-click the newly created file to set the properties for the Data Link. You see the following tabs:

Provider | Connection | Advanced | All

 The Provider tab allows you to specify the provider (the default is Microsoft OLE-DB provider for ODBC drivers). Use the Default provider, and then click Next. The Connection tab allows you to specify either the data source name that is designated in the ODBC Administrator, or allows you to provide the connection string.

You can provide information with one of the following two methods:  Use a predefined DSN name for the connection (it has all the information to connect to the Data source) Build a connection string, or use a known connection string.</ul>

Assuming that you have already created a System DSN for the pubs database, you see the DSN in the drop-down list box (Use Data source). Choose the DSN for Connection and test it by clicking Test Connection. You can also build your connection strings.</li> To complete the settings, click OK. To learn more about Data Link files, see the Msdasc.hlp Help file, that you can find in the following directory: C:\Program Files\Common Files\System\ole db.</li> Open a text editor, such as Notepad, and then drag the DataLink icon to a blank document. You see the connect string that the data link represents. You can use this connect string in your code.</li></ol>

Use a Data Link File in Code with an ADO Connection
Using a Data Link file for an ADO connection is fairly simple. The following is the syntax, using an absolute path:

cnPubs.ConnectionString = "File Name=C:\Path\To\Pubs.UDL;"

<div class="references_section">