Query MS Access DB from R with 64-bit Windows - r

Someone asked me to create a Shiny UI to allow them to read and write from their Microsoft Access database, created with MS Office 2010.
I was following this guide to connect to the Access DB with RODBC and -- while I can open this database in Access itself -- I get the following error from R:
> channel <- odbcConnectAccess("AD_Users.accdb")
Error in odbcConnectAccess("AD_Users.accdb") : `
odbcConnectAccess is only usable with 32-bit Windows
So, I found this solution and gave it a try:
> channel <- odbcDriverConnect("AD_Users.accdb")
Warning messages:
1: In odbcDriverConnect("AD_Users.accdb") :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2: In odbcDriverConnect("AD_Users.accdb") :
[RODBC] ERROR: state 01S00, code 0, message [Microsoft][ODBC Driver Manager] Invalid connection string attribute
3: In odbcDriverConnect("AD_Users.accdb") : ODBC connection failed
> channel <- odbcDriverConnect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=AD_Users.accdb")
Warning messages:
1: In odbcDriverConnect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=AD_Users.accdb") :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2: In odbcDriverConnect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=AD_Users.accdb") :
ODBC connection failed
>
but as you can see, there were some pretty serious warnings. It doesn't seem to work.
Is there any other work-around?
I am using 32-bit R when I receive these warnings and even though they're warnings and not technically errors, the database connection is unsuccessful.
Update
This seems to establish a successful connection, though I've been unable to query data from it thusfar:
channel <- odbcConnectDbase("AD_Users.accdb")

I use odbcConnectAccess2007 in RODBC and don't have any issues connecting to Access databases when using 64-bit windows. However, you should check the package manual (link to pdf) to make sure that you have the appropriate drivers installed on your computer. Once you have the right drivers you should be good to go!

Related

R: credentials dialogue prompted when connecting to access DB that is not otherwise protected

We have access databases (.accdb) for metadata from really old processes that are trying to die. I am trying to connect to these databases with R RODBC. When I navigate to the file path, I can open the database in Access without entering any credentials. When I try to load it in R, I am prompted a user authentication dialogue Box (R in Windows), and I can't seem to authenticate. There is a DSN file in the same directory, but when I try to connect to it, I get the following error:
ch <- odbcConnect("this.dsn")
Warning messages:
1: In RODBC::odbcDriverConnect("DSN=this.dsn") :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2: In RODBC::odbcDriverConnect("DSN=this.dsn") : ODBC connection failed
and ch returns -1

Problems with connection to Oracle from R

I want to connnect to Oracle with R. I use RODBC package for this connection. Following is my code to connect
library(RODBC)
con <- odbcDriverConnect("Driver={Microsoft ODBC for Oracle};
CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=123)(PORT=1521))(CONNECT_DATA=(SID=abc)));
uid=abc; pwd=abc;")
But I get the following error
1:
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2:
ODBC connection failed
It's really strange, because I use direct connection, it doesn't require no TSN nor DSN. Also I succesfully connect to Oracle with the same Hostname, Port, SID, Username and password, using Oracle SQL Developer.

Error in connecting R to Oracle database using RODBC

I am trying to connect R to an Oracle database. I am getting an error which I have already tried to trouble shoot but not able to find a solution.
I created a DSN and successfully tested the connection
I then tried to establish a connection in R.
con <- odbcConnect("DSNNAME", uid='ID', pwd='PWD')
But I receive an error.
Warning messages:
1: In RODBC::odbcDriverConnect("DSN=DSNNAME;UID=ID;PWD=PWD") :
[RODBC] ERROR: state IM014, code 0, message [Microsoft][ODBC Driver Manager]
The specified DSN contains an architecture mismatch between the Driver and Application
2: In RODBC::odbcDriverConnect("DSN=DSNNAME;UID=ID;PWD=PWD") :
ODBC connection failed
I have replaced my id and password with dummies.
Also I am using 64 bit R.

Could open accdb database (MS Access) from R and now I can't

I have a little R code that was working perfectly well until a few days ago and now, all of a sudden, it works on some PCs and it doesn't in others. Does anybody know if any update has been pushed by MS that could be causing the trouble?
I'm running R-32bit in all PCs and the ones not working seem to have upgraded MS Access 2010 to 2016.
This is my code:
library(RODBC)
testdb <- file.path("foo.accdb")
channel <- odbcConnectAccess2007(testdb)
tables_list=grep("foo_table", sqlTables(channel)[,3], value=TRUE) # list of tables with matching names
odbcCloseAll()
The error message I get is:
Error in sqlTables(channel) : first argument is not an open RODBC
channel
In addition: Warning messages: 1: In odbcDriverConnect(con, ...) :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver
Manager] Data source name not found and no default driver specified 2:
In odbcDriverConnect(con, ...) : ODBC connection failed
Mystery solved! Apparently the upgrade to MS Access 2016 deleted the 32-bit drivers for ODBC. Reinstalling the Microsoft Access Database Engine 2010 32-bit got things to work again.
Thanks to all for your help!

Connecting to MS Access Database from R (x64)

I am trying to access my Access database using R. I have tried the below options but I am not able to connect to the database. I am using 64 bit R and 64 bit Access. I am using windows 7 also.. :(
library(RODBC)
db <- "E:/testdb.accdb"
myconn <-odbcDriverConnect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=E:/test.accdb")
con2 <- odbcConnect(db)
channel <- odbcConnectAccess("E:/testdb")
I always get the error. Please help me.
1: In odbcDriverConnect("DSN=E:/testdb.accdb") :
[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=E:/testdb.accdb") : ODBC connection failed
I think the problem is as error message suggests - you don't have x64 Microsoft Access driver installed. Check it in Control panel - ODBC Data Sources (x64) on the Drivers tab. If it's not there, try to install Microsoft Access Database Engine 2010 Redistributable.

Resources