How To Use Data Link Files with ADO
This article was previously published under Q189680
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.
- 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.
- 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 ConnectionUsing 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 .NETFor additional information, see the following Microsoft Web sites:
رقم الموضوع: 189680 - آخر مراجعة: 07/15/2004 20:01:24 - المراجعة: 3.6
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 Enterprise Edition for Windows 6.0
- kbdatabase kbfaq kbhowto KB189680