Search code examples
rms-accessrodbc

How to connect to .accdb database from R


New to R and have having troubles connecting to Access databases. This is the code I am running (RODBC package loaded manually before running):

library(RDOBC)

conn <- odbcDriverConnect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ='C:/db/dbNorthwind.accdb'")
subset(sqlTables(conn), TABLE_TYPE == "TABLE") 
df <- sqlFetch(conn, "tblCustomer") 
df # 

I get the error-message:

Error in sqlTables(conn) : first argument is not an open RODBC channel.

Know any tips on how to fix?

environment:

  • 64-bit Windows
  • 32-bit MS Access 2013
  • 64-bit Microsoft R Open

Solution

  • The code you're using is fine, your setup isn't.

    You need to either use 64-bits R and 64-bits MS Access, or 32-bit R and 32-bit MS Access. You can try, however, to install 64-bits Access Database Engine, found here (2016 version) or here (2010 version).

    I have had varying results with installing both the full version of Access and the database engine (currently got Access 32-bits 2016, and couldn't install Access database engine 64-bits 2016, but could install the 2010 version by using the /passive command on the installer).

    See this blog for some details on how to install the 32-bits full version and the 64-bits database engine on one machine. But as noted, results may vary.