Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

excel ADO connection string

Posted on 2014-03-05
7
Medium Priority
?
983 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 43

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 43

Assisted Solution

by:pcelba
pcelba earned 750 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
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 43

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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Viewers will learn how to customize the ribbon and quick access toolbar in Excel 2013.
Video by: Zack
Viewers will learn about various customizable options in Excel 2013.

886 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