Solved

excel ADO connection string

Posted on 2014-03-05
7
851 Views
Last Modified: 2014-03-11
Hi All,
when attempting to read data from and encrypted xlsx using:
dbConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & SourceFile & "';Extended Properties=Excel 12.0;"
and dbConnection.Execute.

I get an error:
Error -2147467259, External table is not in the expected format. occurred in GetRecordsetFromClosedWorkbook

The error goes away when the file is not encrypted.

adding ;Database Password =test; to the connection string gives a different error:

Error -2147467259, Could not find installable ISAM. occurred in GetRecordsetFromClosedWorkbook

When I use Excel Open (with password) and copy/paste methods all is good

How does one add Excel encryption password to the ADO connection string?

thanks
0
Comment
Question by:COACHMAN99
  • 4
  • 3
7 Comments
 
LVL 41

Expert Comment

by:pcelba
ID: 39908656
Password parameter does not help here but you may use the work around described here: http://www.connectionstrings.com/how-to-open-password-protected-excel-workbook/
You just have to change JET.OLEDB for ACE.OLEDB etc.

Another possibility is to save decrypted workbook into a temporary file and then open it via ADO.

Yes, Microsoft could do it better...
0
 
LVL 7

Author Comment

by:COACHMAN99
ID: 39909870
Hi pcelba
thanks for the input. Unfortunately there are thousands of workbooks in this situation and inputting passwords at a prompt isn't an option. (and when I use workbook.open with a password param, to read data, I am able to work without any prompts; just wanted to use ADO).
cheers,
0
 
LVL 41

Assisted Solution

by:pcelba
pcelba earned 250 total points
ID: 39910388
It is not necessary to ask user for the password but you may provide it as a parameter when opening the Excel workbook.

I don't know the exact syntax but you may use something like this:
Dim xl As New Excel.Application
Dim xwb As Excel.WorkBook

Set xwb = xl.Application.WorkBooks.Open "YourXLSXfile", , , , "password", "password"

and now you should be able to use ADODB connection without any restrictions.

I've tested FoxPro variant of above code and it opens password protected workbook without user intervention.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 7

Author Comment

by:COACHMAN99
ID: 39910421
Hi,
I wasn't asking a question; just informing you of how I currently work around the password issue. (Workbooks.Open("L:\Backup\2014\PGT\BE.xlsx", , , , "test")
thanks
0
 
LVL 41

Expert Comment

by:pcelba
ID: 39910474
Yes, my English is not so good... you wrote "just wanted to use ADO" which I translated as you cannot use ADO even after opening the workbook via OLE automation...
0
 
LVL 7

Accepted Solution

by:
COACHMAN99 earned 0 total points
ID: 39911400
APPARENTLY THE BOTTOM LINE IS:
1. One cannot use a password in an ADO connection to an encrypted Excel workbook.
2. Instead, one must use the Excel 'workbook.open' functionality (which makes use of the optional password).

thanks pcelba for input.
0
 
LVL 7

Author Closing Comment

by:COACHMAN99
ID: 39919998
only workable option.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
Viewers will learn the basics of using filtering and sorting in Excel 2013.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now