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:
Run-time error
-2147286789(800300fb): The File is not a valid compound file
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.
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.
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.
For additional information, click the article numbers below to
view the articles in the Microsoft Knowledge Base:
189680Â
(http://kbalertz.com/Feedback.aspx?kbNumber=189680/EN-US/
)
HOWTO: Use Data Link Files with ADO
286189Â
(http://kbalertz.com/Feedback.aspx?kbNumber=286189/EN-US/
)
HOWTO: Invoke OLE DB Data Link Properties Dialog Box in Visual Basic Code
283245Â
(http://kbalertz.com/Feedback.aspx?kbNumber=283245/EN-US/
)
HOWTO: Persist Data Links Programmatically