Solved

excel ADO connection string

Posted on 2014-03-05
7
898 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 42

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 42

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 42

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] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

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…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Viewers will learn various types of data validation for different data types in Excel 2013.
Viewers will learn the basics about Excel 2013’s new Flash Fill feature.

738 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