Article ID: 296853
Article Last Modified on 6/29/2004
APPLIES TO
- Microsoft OLE DB 2.0
- Microsoft OLE DB 2.1
- Microsoft OLE DB 2.5
- Microsoft OLE DB 2.6
- Microsoft ActiveX Data Objects 2.0
- Microsoft ActiveX Data Objects 2.1
- Microsoft ActiveX Data Objects 2.1 Service Pack 1
- 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 Enterprise Edition
- Microsoft Visual Basic 6.0 Enterprise Edition
- Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 3
- Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 4
- Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 5
- Microsoft Visual Basic 5.0 Professional Edition
- Microsoft Visual Basic 6.0 Professional Edition
This article was previously published under Q296853
SYMPTOMS
If you try to open an ADO connection using a data link file (which is commonly referred to as a universal data link file, or UDL file), you may receive the following error message:
CAUSE
There are two causes for this behavior:
- The database connection information in the UDL file is in an invalid format.
- The UDL file may be corrupted.
RESOLUTION
To resolve this problem, use one of the following methods:
- In the OLE DB Data Link Properties dialog box, re-create the UDL file.
- In Notepad, open the UDL file manually to verify its format and make any required changes. For additional information, see the "More Information" section.
MORE INFORMATION
Data link files provide a convenient way to create and verify an ADO connection string that is used to connect to an OLE DB data source. The connection string information is persisted in a specific format to a data link file with the .udl extension. The data link file is a unicode text file that you can edit using a unicode text editor such as Notepad. For more information on how to create UDL files using the OLE DB Data Link Properties dialog box, see the "References" section.
A UDL file is comprised of three lines of text. For example:
[oledb] ; Everything after this line is an OLE DB initstring Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\testdb.mdb
The first two lines (the OLE DB section declaration and the following comment line) are constant and must be present in all UDL files. If you delete or modify either of these lines, you receive the above-mentioned error message when you try to use the UDL file to connect to a data source.
The third line is the ADO connection string that is used to open a connection to the data source. This line changes when different UDLs are created to connect to different data sources or when a different set of options is specified to connect to the same data source.
Steps to Reproduce Behavior
This sample uses an ADO connection string to connect to the SQL Server PUBS sample database. You can modify the connection string to point to one of your SQL Server databases, or you can specify a string that connects to an alternate data source.
- In Notepad, create a new file named Test.udl, and paste the following text.
Note Make sure that <UID> has the appropriate permissions to perform the operation on the database.[oledb] ; Everything after this line is an OLE DB initstring Provider=SQLOLEDB;Data Source=SQLServer;Initial Catalog=pubs;User Id=<UID>;Password=<strong password>
- Modify the connection string parameters as necessary, and save Test.udl.
- Create a new Standard EXE project in Visual Basic. Form1 is created by default.
- On the Project menu, click Reference, and then click Microsoft ActiveX Data Objects 2.x Library.
- Add a CommandButton control to Form1.
Copy and paste the following code in the Click event procedure of the Command button:
Dim cn As ADODB.Connection Set cn = New ADODB.Connection cn.Open "File Name=c:\Test.udl" MsgBox "Connection opened !" cn.Close Set cn = Nothing
- Modify the path to Test.udl in the cn.Open statement as necessary.
- Save the project. Press the F5 key to run the project.
- When Form1 is displayed, click Command1 to open an ADO connection using Test.udl. If you specified the correct connection string attributes in step 2, a "Connection Opened !" dialog box appears. This indicates that the connection to the data source is successfully established.
- Stop running the project.
- In Notepad, open Test.udl. On the second line, remove the space between the semicolon (";") and "Everything", and save the changes.
- Press F5 to run the Visual Basic project again.
- When Form1 is displayed, click Command1. You receive the above-mentioned error message.
REFERENCES
For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:
189680 HOWTO: Use Data Link Files with ADO
286189 HOWTO: Invoke OLE DB Data Link Properties Dialog Box in Visual Basic Code
283245 HOWTO: Persist Data Links Programmatically
Additional query words: -2147286789(800300fb)
Keywords: kbprb KB296853