Excel VBA connect to MySQL - architecture mismatch error

Ramesh picture Ramesh · May 25, 2013 · Viewed 7.4k times · Source

I am trying to connect to MySQL from my local machine located on a server using VBA. Initially I was receiving the below error.

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.

After some research, I figured out that the MySQL ODBC driver should be installed first. I installed the driver from the below location.

http://dev.mysql.com/downloads/connector/odbc/

I have a 64 bit machine and so I installed the driver for 64 bit and tried to establish the connection. Even then I was receiving the same data source name not found error. However from the ODBC data source administrator, if I select System DSN, I am able to see MySQL driver installed and I am able to create a new data source for my database in the server.

However from VBA, if I call the data source I receive another error.

[Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application.

This is how I am calling the data source from my VBA.

Dim oConn As ADODB.Connection
Set oConn = New ADODB.Connection
oConn.Open "data_source_name"

Also,for the 64 bit ODBC connector I am able to see two drivers as below in my System DSN.

  • MySQL ODBC 5.2 ANSI Driver
  • MySQL ODBC 5.2 Unicode Driver

For both of the drivers, my connection is successful from the ODBC data administrator.

I tried to figure out a solution for the architecture mismatch problem and I read if I create the DSN by running the ODBC application from the below location on a 64 bit machine, it might work.

C:\Windows\System32\odbcad32

However for this scenario too, I received the same architecture mismatch error.

I even tried installing MySQL Connector/ODBC 5.2.5 32 bit in my machine. For this case, I am not able to see the driver listed in the system DSN.

Can someone help me figure out what am actually doing wrong?

Answer

Drew picture Drew · May 25, 2013

I can select and loop thru results sets and do inserts. data verified in db. let me know if you need help

windows 7 Ultimate
version 6.1 (build 7601: service pack 1)
64 bit
************************************************************************
ODBC Data Source Administrator
run by command:    %windir%\system32\odbcad32.exe

2 drivers:
MySQL ODBC 5.2 ANSI Driver , 5.02.05.00, Oracle, MYODBC5A.DLL, 4/4/2013
MySQL ODBC 5.2 Unicode Driver , 5.02.05.00, Oracle, MYODBC5W.DLL, 4/4/2013
************************************************************************
create System DSN, named hp
using Unicode Driver
dsn=hp
descr=hp
tcpip server=192.168.1.11
user=root
password=xxxxx
Database=test
************************************************************************
ODBC Data Source Admin tool
far right tab called About
Admin, Control Panel, Cursor Library, Driver Mgr, Localized R DLL, Unicode Cursor Lib all Version 6.1.7601-ish
************************************************************************
MSFT Office Professional Plus 2010
Version 14.0.6129.5000 (64 bit)
VBA 7.0
Tools Menu / References / References - VBAProject, scroll down, click on:
Microsoft ActiveX Data Objects 6.1 Library
References Location= c:\program files\common files\system\ado\msado15.dll
************************************************************************
code same, get into an excel Macro:
Sub Macro1()
'
' Macro1 Macro
'

Dim oConn As ADODB.Connection
Dim rsPass As ADODB.Recordset
Dim sql As String

Set oConn = New ADODB.Connection
oConn.Open "hp"
Set rsPass = New ADODB.Recordset
sql = "select * from charlie1"
rsPass.Open sql, oConn
rsPass.Close


sql = "insert into charlie1 (billybob,birthdate,funny_num) values (5,now(),383.111)"
rsPass.Open sql, oConn


End Sub