How to connect to .accdb database from R

Viewed 3825

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
3 Answers

This worked fine for me.

library(RODBC)

# for 32 bit windows
# Connect to Access db
# channel <- odbcConnectAccess("C:/Users/Excel/Desktop/Coding/Microsoft Access/Northwind.mdb")

# Get data
# data <- sqlQuery( channel , paste ("select * from Name_of_table_in_my_database"))


# for 64 bit windows
channel <- odbcDriverConnect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:/Users/Excel/Desktop/Coding/Microsoft Access/Northwind.mdb")

data <- sqlQuery( channel , paste ("select * from CUSTOMERS"))

odbcCloseAll()
Related