I am using 32-bit R with RStudio to try and connect to an .accdb file. I have 32-bit MS Access running on my machine.
R version:
platform i386-w64-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 3
minor 1.2
...
language R
version.string R version 3.1.2 (2014-10-31)
nickname Pumpkin Helmet
I'm trying to use the RODBC package to connect to an MS Access database. I cannot use odbcConnectAccess("location_of_database.accdb") to connect to a database provided by a client. This particular database was created with Access 2013. When I try to connect, I get a variety of warning messages:
Warning messages:
1: In odbcDriverConnect(con, ...) :
[RODBC] ERROR: state HY000, code -1028, message [Microsoft][ODBC Microsoft Access Driver] Cannot open database '(unknown)'. It may not be a database that your application recognizes, or the file may be corrupt.
2: closing unused RODBC handle 12
3: In odbcDriverConnect(con, ...) :
[RODBC] ERROR: state 01000, code 1, message [Microsoft][ODBC Microsoft Access Driver]General Warning Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x11a4 Thread 0x798 DBC 0x88e0064 Jet'.
4: In odbcDriverConnect(con, ...) :
[RODBC] ERROR: state 01000, code 1, message [Microsoft][ODBC Microsoft Access Driver]General Warning Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x11a4 Thread 0x798 DBC 0x88e0064 Jet'.
5: In odbcDriverConnect(con, ...) : ODBC connection failed
Interestingly, I can use odbcConnectAccess2007() to connect successfully to databases that were created with Access 2010; however, when I try to use odbcConnectAccess() to connect to those same databases, I get the same errors above.
A Google search of the Error: state 01000, code 1 message above suggests that this page may be helpful, but even after following the steps to alter the HKEY_LOCAL_MACHINE does not work.
While I originally thought that this question was promising, the warning message there relates to "ACE DSN" while the error messages I'm seeing relate to "Jet DSN."
I cannot open the databases I'm trying to access with RODBC with my version of Access as the databases were created with Access 2013 and I have Access 2010 installed.
Can anyone help me trouble shoot why I can't open this database with odbcConnectAccess()?
why I can't open this [Access 2013] database with odbcConnectAccess()?
I'm fairly certain that
odbcConnectAccess(<fileSpec>)
is simply shorthand for
odbcDriverConnect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ=<fileSpec>')
(i.e., the older "Jet" ODBC driver), and
odbcConnectAccess2007(<fileSpec>)
is simply shorthand for
odbcDriverConnect('DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=<fileSpec>')
(i.e., the newer "ACE" ODBC driver).
The older "Jet" driver cannot work with .accdb files, so odbcConnectAccess2007() would be required. If that throws an "Unrecognized database format" error then it's likely that the database file is damaged.
Related
I am trying to run some queries in Oracle SQL through R using RODBC but it doesn't work, not matter what I try.
I installed the "basic", "sqlplus", "odbc" and "sdk" packages from Oracle (yes, I know sdk and sqlplus aren't strictly needed), did all the path settings needed, copied libodbcinst.2.dylib to the instant client folder, installed the odbc driver in odbcinst.ini, tried changing dynlib locations through install_name_tool, even tried adding "arch -x86_64" before the driver name on odbcinst.ini - all to no avail.
I am using a MacBook Air M1, macOS Monterey 12.3.1, unixodbc installed on opt/homebrew from homebrew...
The connection string is:
sqlDriver <- 'Oracle 19 ODBC driver'
connectionStringSQL <- paste0(
"Driver=", sqlDriver,
";Server=", sqlServer,
";Database=", sqlDatabase,
";Uid=", sqlUser,
";Pwd=", sqlPassword,
";Encrypt=yes",
";Port=1521")
conn <- odbcDriverConnect(connectionStringSQL)
But I don't think the connection string matters, because the error I get is:
Warning messages:
1: In odbcDriverConnect(connectionStringSQL) :
[RODBC] ERROR: state 01000, code 0, message [unixODBC][Driver Manager]Can't open lib 'arch -x86_64 /Users/*****/instantclient/libsqora.dylib.19.1' : file not found
2: In odbcDriverConnect(connectionStringSQL) : ODBC connection failed
I might be re-asking the question but I am having difficulty creating connection to Oracle DB which is on a remote server. I am new to R and Oracle DB so I do not have much experience. I am using RStudio. I have installed RODBC package successfully. I am using Ubuntu 14.04 Operating System.
Firstly I use library RODBC
library("RODBC", lib.loc="~/R/x86_64-pc-linux-gnu-library/3.0")
Then I have entered following command:
odbcConnect(dsn = "DatabaseName", uid = "UserID", pwd = "Password")
I get the following error:
[1] -1
Warning messages:
1: In RODBC::odbcDriverConnect("DSN=DatabaseName;UID=UserID;PWD=Password") :
[RODBC] ERROR: state IM002, code 0, message [unixODBC][Driver Manager]Data source name not found, and no default driver specified
2: In RODBC::odbcDriverConnect("DSN=DatabaseName;UID=UserID;PWD=Password") :
ODBC connection failed
I have searched but I am not getting to anywhere. Please tell me process or steps to how I can make a connection.
Thank You!
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!
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!
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.