ODBC works fine in MS Excel, but not in R

Tom picture Tom · Jun 5, 2014 · Viewed 7k times · Source

I've set up my ODBC driver so that MS Excel can import the data into a spreadsheet just fine.

However, when I try to establish the connection with R, using

ch <- odbcConnect(leprosyDHISdb, uid = leprosyDHISid, pwd = leprosyDHISpw)

Then I get the error

Warning messages:
1: In odbcDriverConnect("DSN=dhis2;UID=dhis2_viewer;PWD=*********") :
  [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2: In odbcDriverConnect("DSN=dhis2;UID=dhis2_viewer;PWD=*********") :
  ODBC connection failed

What could make odbc fail for R, but not for Excel?

Answer

Daniel Gardiner picture Daniel Gardiner · Jun 23, 2014

Check if you are using a 32/64bit version of R, also check if your ODBC connection is 32/64bit.

To setup a 32bit DSN using windows navigate to the following folder C:\Windows\SysWOW64

To setup a 64bit DSN using windows navigate to the following folder C:\Windows\System32

EDIT: The following blog is an excellent guide you might find useful

http://sandymuspratt.blogspot.co.uk/2013/01/getting-access-data-into-r.html