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.
Related
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 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
I'm trying to connect my Excel to Oracle with this connection string in VBA:
And I get error msg below:
Run-time error '-2147467259 (800004005)':
ORA-12154: TNS:could not resolve the connect identifier specified
Using:
- Excel 2016 64-bit
- Windows 10 64 bit
- Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit
- PL/SQL Release 12.1.0.2.0
- CORE 12.1.0.2.0
- TNS for Linux: Version 12.1.0.2.0
- NLSRTL Version 12.1.0.2.0
Excel 64-bit & oracle is provided by company, hope can settle it without change excel to 32-bit. Any help will be appreciated. I actually already tried to settle it for two days and see no hope at all. Thanks for your time.
Not sure if is the driver i used is 32-bit?
Microsoft ODBC for Oracle, MSORCL32.DLL
Oracle in Client_11_Std_x86_1, SQORA32.DLL
Dim cnPubs As ADODB.connection
Set cnPubs = New ADODB.connection
Dim strConn As String
With cnPubs
strConn = "Provider=OraOLEDB.Oracle;" & _
"Data Source=" & sSource & ";" & _
"User ID=" & sAC & ";Password=" & sPW & ";"
.Open strConn
.CommandTimeout = 0
End With
Looks like you missed some basics, let's explain. When you want to connect to an Oracle database, no matter whether sqlplus or VBA or anything else then actually you would have to do it like this:
sqlplus MyUserName#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.0)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORA12)))
However, nobody is willing or able to remember such a long and complex database name.
So, you would prefer to use an alias, i.e. a shortcut for (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.0)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORA12)))
There are different methods to define and resolve such aliases (see Managing Network Address Information), the most common and easiest way is to use a local tnsnames.ora file.
In your tnsnames.ora file you can add a line like this:
MY_DB=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.0)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORA12)))
Then you can connect to your database simply with
sqlplus MyUserName#MY_DB
Now the next question is: How does my application find the tnsnames.ora file on my system? The answer is not as trivial as you might assume, see Determining location of relevant tnsnames.ora file
The most secure solution is: Define an environment variable TNS_ADMIN and put as value the directory name where your tnsnames.ora file is located.
Provider "msdaora" uses a different pattern to find the tnsnames.ora file than "Oracle OLE DB" provider does. msdaora finds your file, Oracle OLE DB does not. Settings an environment variables TNS_ADMIN makes it working for both.
I downloaded and installed the MariaDB ODBC Driver 3.0.6 and installed it on my computer. Then I wrote a small piece of VBA in EXCEL 2016 which connects to the DB, which seems to work, and tries to query some entries.
Here is where the problems start:
The recordset allways returns a RecordCount of -1
EXCEL crashes when executing any rs cursor command (MoveLast etc.), but that is probably because I don't have any recors
If I use CursorLocation adUseClient, as suggested in many posts I could find, instead of asUseServer VBA throws the following error: Runtime error '-2147467259 (80004005)' ... returned Status E_FAIL
Edit:
The issue was officialy fixed in the following versions: 3.0.7, 2.0.19, 3.1.0
Link to Issue
I found the Solution: use MariaDB ODBC Driver 3.0.5 instead of 3.0.6. Then everything works fine with the adUseClient Cursor...
Perhaps it saves someone a little time... :-)
I am trying to connect to Oracle XE 11.2 using VBA and Excel. Oracle is installed on the same machine as Excel. I have also installed the 32 bit client tools. I have tried various methods found online but none of them seem to work.
Per the suggestion on the post OleDB Data provider can not be found VBA/Excel I was able to create an ".udl" file that successfully connected. However when I used the connection string in my code I get the error "Provider cannot be found. It may not be properly installed".
Sub test2()
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.ConnectionTimeout = 99000
cn.CommandTimeout = 99000
cn.Open "Provider=OraOLEDB.Oracle.1;Password=Oracle!;Persist Security Info=True;User ID=SYSTEM;Data Source=DESKTOP-NAME"
End Sub
I believe the problem is I don't have the right references selected but I have tried many combinations and can't find any that work. Any help would be appreciated. If I need a reference please list out the exact reference(s) names.
Thanks,
Scott
I finally got this to work by uninstalling the 64 bit XE SERVER and then installing the 32 bit version. I then installed the administration software (32 bit).