ExcessAxel
asked on
ADODB Connection to Excel fails to read data for second (read-only) user
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.OLE DB.12.0;
User ID=Admin;
Data Source=U:\Clients\******** \Dec 2013\ReadOnlyCrashInvestig ation8Jan2 014\***.xl s;
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.
Windows 7
Main workbook native Excel 2010
Source workbook - 97-2003
Connection string as follows:
Provider=Microsoft.ACE.OLE
User ID=Admin;
Data Source=U:\Clients\********
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
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.