I am trying to query an excel file from VBA using SQL queries; I am working on a windows 7 machine 64 bit with office 2007 installed. I am using the connection string below taken from here
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\TradeLogSettings.xlsm;Extended Properties=Excel 12.0 Macro;HDR=YES;
However when I try to open the connection as follow
'ConnDbString is the above connection string
If (Glob_Conn.State = 0) Then
Glob_Conn.Open (ConnDbString)
End If
I get the error as per the attached screenshot
any idea about what I am doing wrong with the connection string ?
error on Glob_Conn.Open
UPDATE 1
The solution that I found is to use this connection string
Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm,*.xlsb)};DBQ=C:\TradeLogSettings.xlsm
if anyone knows a better connection string for my purpose is welcomed.
I think the quotation marks are missing. Try this.
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\TradeLogSettings.xlsm;Extended Properties="Excel 12.0 Xml;HDR=YES";
The solution that I found is to use this connection string
Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm,*.xlsb)};DBQ=C:\TradeLogSettings.xlsm
Related
I am using Windows 10, Excel 2016 and I'm trying to create an ADODB connection to a MYSQL80 instance on my laptop in Excel using VBA.
I get an error "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified." I have tried this with both MYSQL ODBC 8.0 ANSI Driver and MYSQL ODBC 8.0 Unicode Driver. Run-time error '-2147467259 (80004005)'
I have both ODBC connections established and a test is successful on both. Note they are 64bit versions as my OS is 64bit.
ODBC Connection
My code includes
Public oSConn As New ADODB.Connection
Public Function GetSQLConnectionString() As String
GetSQLConnectionString = "Driver ={MYSQL ODBC 8.0 Unicode Driver};Server=localhost;Port=3306;Database=hstest;Uid=xxxx;Pwd=xxxx;"
End Function
and have tried with
GetSQLConnectionString = "Driver ={MYSQL ODBC 8.0 ANSI Driver};Server=localhost;Port=3306;Database=hstest;Uid=xxxx;Pwd=xxxx;"
have also tried this excluding the port=3306
have also tried changing localhost to 127.0.0.1
Sub UpLoadData()
oSConn.Open GetSQLConnectionString()
...
end sub
The error occurs when running the OSConn.Open line.
What am I doing wrong?
A friend of mine found the answer.
GetSQLConnectionString = "Driver ={MYSQL ODBC 8.0 U
should be
GetSQLConnectionString = "Driver={MYSQL ODBC 8.0 U
note the removal of the space after the word Driver.
I have been asked to check at an issue on an "old" excel file, that have been moved to a new server and which is "no more working".
Before I was granted to access on the new server, I have tested on my laptop (Win10/office 64/oracle client 64/ODBC 64).
The VBA connection string is :
strConOracle = "Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
strConOracle = strConOracle & "(HOST=" & HOST & ")(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=" & DATABASE
strConOracle = strConOracle & "))); uid=" & USER & " ;pwd=" & PASSWORD & ";"
Set oConOracle = CreateObject("ADODB.Connection")
Set oRsOracle = CreateObject("ADODB.RecordSet")
After several tests, I think , I have understood that the string "{Microsoft ODBC for Oracle}" refers to an ODBC 32bits pilot. In my 64bits ODBC, the name is "Oracle in OraClient19Home1".
If I just change {Microsoft ODBC for Oracle} by {Oracle in OraClient19Home1} , it's not working (too quick to win :) )
So I'm just wondering If you know if ADODB connection is still possible on a 64 bits ?
And if there's some tricky thing we got to add in the VBA code.
Yes, I know there's a feature in excel called "getdata" that use external ODBC DSN connection, but it's too invasive. It needs to rework all the mechanism of the VBA code, and it's too long.
So I first want to check at VBA ADO connections.
Just for information , when I finally get in the issuing server (Windows ServerĀ® 2008 Standard/Office 32bits/Oracle 32bits/ODBC 32bits). I just need to add some trusted locations and buttons in FORM mode to get it work back again. I guess that's because in the ODBC 32bits, there is a pilot called "Microsoft ODBC for Oracle" or because there's a registry keys at this name :
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI\Microsoft ODBC for Oracle]
But I feel that, one day we won't be able to work in 32bits.
And it's may be a good warning for upgrading to 64bits.
regards
G
I am accessing an excel file stored on a shared drive for now a couple of months without errors. All of a sudden, we have this issue popping out:
Cannot update. Database or object is read-only.
My original connection string looked like this:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source="<FileName>";Extended Properties="Excel 12.0 Xml;HDR=Yes;".
I have tried the following one:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source="<FileName>";Extended Properties="Excel 12.0 Xml;HDR=Yes;Readonly=0;"
and
Provider=Microsoft.ACE.OLEDB.12.0;Data Source="<FileName>";Extended Properties="Excel 12.0 Xml;HDR=Yes;READONLY=FALSE;"
but nothing provides good results.
I need to connect to this excel workbook and get the data in order to perform some business critical process, but nothing works so far as it always provides me with the mentioned error.
Any recommendation?
A solution that worked for me in that case was adding IMEX=1 at the end of the connection query.
I have successfully connected to an as400 server. But whenever i execute an sql statement
select * from nosd0
It doesn't work, because nosd0 is in lib1/fil1(nosd0)
it gives an error saying nosd0 is not in lib2.
When I execute the query on STRSQL on as400 it works fine.
I tried creating an alias and it's malfunctioning. Please I really need some help on this one
Alias is working, I am accessing the wrong file.
Ok I figured out the problem, this will also help all those who wants to connect to their AS400 iSeries using VBA. ;)
My problem above is that when I try my Query on the box, it accesses lib1/nosd0, and in VBA, I was trying to get lib2/fil1(nosd0) which is a description of the table nosdo itself. The simple solution is to query
select * from lib1.nosd0
More on that when connecting to an AS400 iSeries using ODBC, there is a parameter called DBQ
Connection String Parameters
My final connection string would be.
ConnectString = "Driver={ISeries Access ODBC Driver};System=" & DCServer(I) & ";Uid=--;Pwd=--;NAM=0;DBQ=lib1,*ALL;"
The sqlbulkcopy function works fine in my local environment but when I deploy it to IIS it only imports 17837 out of the 67K odd rows. Does anybody know what can cause this issue?
Actually the problem was with the Excel connection string I was missing the 'IMEX=1' at the very end. The correct connection string is - Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\uploaded.xlsx;Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1'"