Error Trying to Connect R to MySQL using RODBC - mysql

I am attempting to connect R to a MySQL database via RODBC (in Win 7 environment), but cannot get past the following error:
[RODBC] ERROR: state IM014, code 0, message [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application
After entering the following command:
odbcConnect(dsn,uid="My_UID",pwd="My_PWD")
I have successfully created a driver for the database by following the odbc wizard, and have installed the RODBC package into RStudio (ver 0.98.490). The MySQL is running on 32bit, I have the 32bit driver installed and working, and my RStudio is also 32bit. I know that the driver is working since both the test connection in config. works, as do queries run on excel using the driver.
What can I do to get the connection to work in R?
(Previous responses to this question seem to have been removed.)
Thanks in advance!

I faced a similar RODBC connectivity issue using DSN, where R was crashing abruptly without any logs/error trace. I tried with DSN-less ODBC connection API, it works fine.
odbcDriverConnect("SERVERNAME=;DRIVER={};DATABASE=;UID=;PWD=;")
Steps:
1. Install ODBC driver
2. Define VNode (host, listen address, protocol)
3. Use the odbcDriverConnect API
Docs:
http://cran.r-project.org/web/packages/RODBC/RODBC.pdf
http://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf
Hope this helps.

Related

Access MySQL database in R on Mac OS X

I am having problems accessing my MySQL database from R on mac (Mac OS X 10.11.2). The following code:
library("RODBC")
mycom <- odbcConnect("wsn_mysql_5", uid="root", pwd="*****")
Gives this error:
1: In RODBC::odbcDriverConnect("DSN=wsn_mysql_5;UID=root;PWD=****") :
[RODBC] ERROR: state 00000, code 15509574, message
[iODBC][DriverManager]dlopen(/usr/local/lib/libmyodbc5a.so,
6): no suitable image found. Did find:
/usr/local/lib/libmyodbc5a.so: mach-o, but wrong architecture
2: In RODBC::odbcDriverConnect("DSN=wsn_mysql_5;UID=root;PWD=****") :
[RODBC] ERROR: state IM003, code 15509574, message
[iODBC][Driver Manager]Specified driver could not be loaded
What I have tried so far:
I installed iODBC driver manager 3.52.12.
I installed MySQL connector odbc-5.3.6-osx10.11-x86-64bit and created a DSN (server=localhost, user=root, password=*****,database=wsn_db).
I was getting this error when testing it in iODBC Administrator:
[iODBC][Driver manager]dlopen(/usr/local/lib/libmyodbc5w.so, 6): no suitable image found.
Did find: /usr/local/lib/libmyodbc5w.so: mach -o, but wrong architecture.
How to add ODBC to MAMP on OSX led me to think that is was a 32-bit vs 64-bit problem.
So I installed MySQL connector odbc-5.2.7-osx10.7-x86-32bit which is the most recent 32-bit version I found. When I test this with iODBC Administrator, it seems to work, but I get the error mentioned at the beginning when I try the code in R.
The FAQ of iODBC says the following regarding this type of error:
[iODBC] [Driver Manager]Specified driver could not be loaded
There are a few reasons why this could occur, and thinking through the architecture helps. Your application has loaded libiodbc successfully, and it has found an odbc.ini file (or equivalent through the ODBCINI environment variable), and it has found a DSN within that odbc.ini that matches the name requested in your connection.
However, the driver manager has had problems loading the library specified in the `Driver=' line of that DSN definition. Either it doesn't exist, or its permissions are insufficient to allow your application to load it (it must be readable and executable, and the directories leading down to it must be executable), or maybe the file is not a dynamic library - it could be a static library (a *.a file except on AIX) or is otherwise corrupted. These are all things to check, or you may be best off reinstalling the driver if all the permissions check out.
So I checked the permission, but they were correct.
I also reinstalled the driver, but it didn't change anything.
After reading this, I checked odbc.ini and obdcinst.ini.
I changed odbc.ini to:
[ODBC Data Sources]
wsn_mysql_7 = wsn_mysql_7
[ODBC]
TraceLibrary=
[wsn_mysql_7]
Driver = /usr/local/lib/libmyodbc5w.so
DATABASE = wsn_db
DESCRIPTION = DSN for wsn_db in R
SERVER = localhost
UID = root
PASSWORD = *****
and odbcinst.ini to
[ODBC Drivers]
MySQL ODBC 5.2 ANSI Driver=Installed
MySQL ODBC 5.2 Unicode Driver=Installed
[ODBC Connection Pooling]
PerfMon=0
Retry Wait=
[MySQL ODBC 5.2 ANSI Driver]
Driver = /usr/local/lib/libmyodbc5a.so
Description = mySQL driver
Threading = 0
[MySQL ODBC 5.2 Unicode Driver]
Driver = /usr/local/lib/libmyodbc5w.so
Description = mySQL driver
Threading = 0
But it didn't seem to change anything.
I also tried an alternative RODBC code based on this question.
mycom <- odbcDriverConnect("Provider=MSDASQL;Driver={MySQL ODBC 5.2 UNICODE Driver};
Server=localhost;database=wsn_db;Uid=root;Pwd=*****;Option=3")
I am not sure what to do next? Even a completely different way to access the mySQL data in R would help.
I finally manage to have a working configuration by using unixODBC and using a 64-bit ANSI connector. If you are trying to connect to a MySQL database with RODBC I recommend:
To follow this tutorial to install unixODBC and RODBC
Install the latest MySQL ODBC connector. I installed mysql-connector-odbc-5.3.6-osx10.11-x86-64bit. I had to install from tar since the installer didn't work. The instructions are here.
I used ODBC Administrator to configure the DSN, but I guess the instruction from [Hiltmon's tutorial] might work as well.
I first used the Unicode driver, but got the following error:
Warning messages:
1: In RODBC::odbcDriverConnect("DSN=wsn_db_dsn;UID=root;PWD=****") :
[RODBC] ERROR: state H, code 0, message [unixODBC][
2: In RODBC::odbcDriverConnect("DSN=wsn_db_dsn;UID=root;PWD=****") :
ODBC connection failed
I corrected this by selecting the ANSI driver as suggested in RODBC error - ODBC connection failed - can't connect to MySQL with my mac (mavericks).
I hope this can save time to someone.

SQL Server 32-bit easysoft IB6 odbc SSIS package failing with validation error: codes 0x80004005 and 0xC0014009 when run by a sql server agent job

I have a SSIS package on sql server 2012.
It utilizes an easysoft odbc connection to access and optima attendance controller. In my project, I have
Run64BitRuntime is false. My SQL Agent Job is also set for 32 bit run time.
I use and SSIS proxy account and it is an admin account.
I have another package running on the same server using a different odbc provider, timebersoft, but it runs without issue.
If you need more details please let me know what you need to know.
The following errors only occur when the package is exacuted by a sql server agent job.
Data Flow TAsk: Error: ODBC source failed validation and returned error code 0x80004005
attnd: Error: There was an error trying to establish and Open Database Connectivity (ODBC) connection with the database server.
Data Flow Task: Error: The AquireConnection method call to the connection manager Attnd failed with error code 0xC0014009.
I have attempted to create a hello world version and every time the only thing to cause it to crash is when i try to connect to the easysoft odbc. the driver is installed (Name{Easysoft IB6 ODBC}; Version{1.00.01.70}; Company{Easysoft Limited}; File{IB6ODBC.DLL}; Date{6/5/2002}) the user is the same administrator for the successful and unsuccessful attempts
Update: July 21:
1. Tried the installation that wasn't it.
2. Tried Operation system(cmdline) for using 32 bit detexec.exe failed again. (double checked and the command I used did work in the cmdline)
Here are a couple of things you must check (going from front end to back end). See what you are missing.
Run64BitRuntime is set to false in the project setting.
The same configuration setting (having Run64BitRuntime set to false) should be used for deployment.
If you are using an external configuration file, and that has this property, see that it is set to false.
SQL Server > Database Engine > SQL Server Agent > Jobs > Your job's properties > Select the step where you run the SSIS and click Edit> In the 'Execution Options' tab check 'Use 32 bit runtime'
Hope this helps!
"You can use our Interbase ODBC driver from SQL Server Agent or any ODBC enabled application. You will however need to install a 64-bit Interbase client that is compatable with your Interbase server before you install the Easysoft ODBC driver. This can be obtained from Embarcadero"
the issue appears to be with the software. In order to use easysoft on a 64 bit system i need the 64 bit driver properly installed.
Thank you #billinkc for pointing out the installation issue.

pyodbc + MySQL + Windows: Data source name not found and no default driver specified

I am trying to connect to MySQL 5.6 on a Windows Server 2008 R2 localhost with pyodbc. I used the full installation for the MySQL instance on the localhost, including the ODBC connector. I have it connecting to a remote SQL Server instance beautifully, but for the life of me I can't get it to connect to the local MySQL instance. I am using this guide from connectionstrings.com as reference.
Here's some code:
import pyodbc
def create_mssql_conn():
return pyodbc.connect(r'Driver={SQL Server};Server=MSSQLSRV;Database=ecomm;Trusted_Connection=yes;')
def create_mysql_conn():
return pyodbc.connect(r'Provider=MSDASQL;Driver={MySQL ODBC 5.6 UNICODE Driver};Server=127.0.0.1;Database=ecomm;User=root;Password=myP#$$w0rd;Option=3;')
# conn = create_mssql_conn() # This one works
conn = create_mysql_conn() # This one breaks
cursor = conn.cursor()
cursor.execute('SELECT * FROM inventory')
while 1:
row = cursor.fetchone()
if not row:
break
print row
Here is the error:
pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
I tried everything from adding Provider=MSDASQL; to changing ANSI to UNICODE in the connection string. Any suggestions?
I was having a similar issue. I am using windows 8, and mysql.
The way I solved the problem was by going into my
control panel>Systems and Security>Administrative Tools.>ODBC Data Sources
Either the 32 bit or 64 bit version depending on your computer.
Then you click on the System DNS file. If you do not see any MySQL driver you have to click ADD. It brings up a list, from that list select the MySQL driver.
For me it was MySQL ODBC 5.3 ANSI(they have a unicode driver also). Click finish. Once you do that then you have to change your connection line in your code to the corresponding Driver that you just filled out.
Ex:
def create_mysql_conn():
return pyodbc.connect(r'Driver={MySQL ODBC 5.3 ANSI Driver};Server=MSSQLSRV;Database=ecomm;Trusted_Connection=yes;')
This should work, or at least it solved my connection issue because I was getting all sorts of different errors with everything I tried. This was what solved the issue for me.
In Win64 there are two ODBC environments: 32 and 64 bit and you can work with Python 32 bit or Python 64 bit. Check what version of Python you use and then use proper version of odbcad32.exe (32 bit version is located in the SysWoW64 directory) to create SystemDSN. With SystemDSN you can check if you can connect to the database. Then try to connect to DB from Python code.
You can list ODBC datasources available to pyodbc via my code recipe: https://code.activestate.com/recipes/578815-printing-list-of-odbc-data-sources-with-pyodbc-mod/
Head to Administrative Tools and the ODBC Data Sources. You should click on the DNS file. Most likely you'd see Microsoft Access and excel as the only data sources available, so you need to add your SQL Server. Mine was SQL Server 2008 R2, and so far, it has worked.
For the error mentioned
"pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')"
I installed the 'Microsoft Access Database Engine 2010 Redistributable 64-bit' as I have 64-bit system and then added the DSN in the directory of MS Access database and it's working now.
Here is the link of the video for how to create DSN and connect to python.
https://www.youtube.com/watch?v=zw9P2wSnoIo

Getting DSN architecture mismatch between Excel and ODBC MySql Connector

I'm getting the following error using Excel trying to add an external data source to the spreadsheet.
[Microsoft][ODBC Driver Manager]The specified DSN contains an architecture mismatch between the Driver and Application.
I can't find a compatibility chart between MySql and the MySql-ODBC Connector versions, but I got the latest that I could find. This is what I'm using:
mysql: 5.6.16 winx64
ConnectorODBC: 5.3.2x64
I've tried both the Ansi and Unicode versions of the driver. When adding it using the Windows Administrative Tools->Data Sources (ODBC) link the Test button says it connected successfully.
Data Source Name: Loans
TCP/IP server: localhost
Port: 3306
User:
Password:
Database: Loans
Thanks,
Ben
Your problem is that your client, Excel, is 32bit and needs to connect to a 32bit ODBC driver. Your 32bit ODBC driver will connect to a 64bit app just fine, what's important is that the client connects to a driver with the same architecture. On %windir%\syswow64 you'll find a file called odbcad32.exe, it's your 32bit ODBC control panel, add your 32bit MySQL ODBC driver there and use that to connect.

Mysql table on Excel sheet?

I am using Windows7 and Microsoft office 2010 and mysql5. I want to connect Microsoft excel with my database mysql. I have installed all the drivers. I have created a data source as well. I am going step-by-step to connect, but at the end when i click on test connections, I receive this error message
Test connection failed because of error in intializing provider unspecified error.
You probably are not using the right ODBC driver.
Please check if you downloaded the one that matches your MySQL database. (not only version number, but especially if it is a 32-bit server or a 64-bit server).