How To Use Data Link Files with ADO


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).

More Information

Create a Data Link File

  1. 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

  2. Double-click the newly created file to set the properties for the Data Link. You see the following tabs:
    Provider | Connection | Advanced | All
  3. 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.
  4. 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.
    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.
  5. 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.
  6. 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.

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;"


For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
308075 How To Use Data Link Files with the OleDbConnection Object in Visual Basic .NET
For additional information, see the following Microsoft Web sites:

รหัสบทความ: 189680 - การตรวจสอบครั้งสุดท้าย: 17 ธ.ค. 2008 - ฉบับแก้ไข: 1