[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

ADODB Connection to Excel fails to read data for second (read-only) user

Posted on 2014-01-09
3
Medium Priority
?
1,166 Views
Last Modified: 2014-01-13
I have an Excel workbook with a user defined function to retrieve data from closed workbooks using ADODB. The function works for the first user that opens the main workbook, however when a second user opens the file, accepting the message that the workbook can only be opened Read-only, the retrieve function fails. The connection object is established correctly but the SQL to retrieve the recordset fails.

Windows 7
Main workbook native Excel 2010
Source workbook - 97-2003

Connection string as follows:
Provider=Microsoft.ACE.OLEDB.12.0;
User ID=Admin;
Data Source=U:\Clients\********\Dec 2013\ReadOnlyCrashInvestigation8Jan2014\***.xls;
Mode=Share Deny None;
Jet OLEDB:System database="";
Jet OLEDB:Registry Path="";
Jet OLEDB:Database Password="";
Jet OLEDB:Engine Type=35;
Jet OLEDB:Database Locking Mode=0;
Jet OLEDB:Global Partial Bulk Ops=2;
Jet OLEDB:Global Bulk Transactions=1;
Jet OLEDB:New Database Password="";
Jet OLEDB:Create System Database=False;
Jet OLEDB:Encrypt Database=False;
Jet OLEDB:Don't Copy Locale on Compact=False;
Jet OLEDB:Compact Without Replica Repair=False;
Jet OLEDB:SFP=False;
Jet OLEDB:Support Complex Data=False;
Jet OLEDB:Bypass UserInfo Validation=False;

SQL is simple "Select * FROM [SHEETNAME$Range]"

Any pointers would be greatly appreciated.

Attaching file will require a lot of anonymising.
0
Comment
Question by:ExcessAxel
[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
3 Comments
 
LVL 40
ID: 39769656
ADODB need to open the file to retrieve the data, and by default, ADODB needs to keep the connection as long as the recordset is alive, meaning that the file stays opened.

Just as happens when a user opens the file in Excel, is then shows up as ReadOnly for anybody who tries to open again it a second time.

If the Recordset is use only to get the data with no interaction with it afterward, get rid of it as soon as you have the data.

Otherwise, lookup "disconnected recordsets" on the web to know how to work with a recordset without keeping the connection opened.
0
 
LVL 16

Accepted Solution

by:
Jerry Paladino earned 2000 total points
ID: 39770638
Change:    Mode=Share Deny None  to   Mode=Read
Make sure you are closing the connection before the macro terminates...

Assuming your Connection variable is called "Cn"...  after you have retrieved the data use...

Cn.Close
Set Cn = Nothing


I don't think you are specifically opening a Recordset but if you are make sure you close it properly as well.

Assuming your RecordSet variable is called "rs"...  after you have retrieved the data use...

rs.Close
Set rs = Nothing
0
 

Author Closing Comment

by:ExcessAxel
ID: 39777058
Many thanks to ProdOps - worked a treat.
In a previous version, it didn't seem to matter that the Mode was set to Share Deny None but in the current Workbook, setting it to "Read" did the trick. We had been tidying up the connection and recordset objects.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

650 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