Connecting to MS Access Database from R (x64) - r

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.

Related

Error when trying to connect to Teradata as source using Attunity

I am getting the following error when I try to connect to Teradata as source using attunity
"SYS-E-HTTPFAIL, Cannot connect to ODBC provider Fatal error has occurred."
I have restarted Attunity console and server
screenshot of the error
I confirmed that Teradata ODBC is installed and I can connect to Teradata
There are multiple reasons for these errors:
1- In my case I needed to update the environment variable and ensure to enter the correct path to Teradata ODBC driver
2- Other reasons for the error is ensure you are running a 64 bit ODBC driver matching Attunity 64 bit download

Connect R to MS Access 64bit Windows

I'm trying to connect R with an MS Access database on a Windows 7 64bit machine.
library(RODBC)
con <- odbcConnectAccess2007("M:/path/to/mydatabase/my.database.accdb")
# [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specifiedODBC connection failed
I've also tried package odbc using connection strings specified at https://www.connectionstrings.com/access/ but similarly cannot connect
library(DBI)
con <- dbConnect(drv = odbc::odbc(), dsn = "Microsoft Access Driver", driver = "Microsoft Access Driver (*.mdb, *.accdb)", database = "M:/path/to/mydatabase/my.database.accdb")
# Error: nanodbc/nanodbc.cpp:950: IM002: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
What am I doing wrong?
You can use my AceOdbcCheck script to test your machine for a valid install of Access "ACE" ODBC. If you don't have it installed you can download the drivers here.
Note that the "bitness" (64-bit or 32-bit) of the Access ODBC driver must match the version of R you are running. That is, if you are running 32-bit R then you need the 32-bit drivers even though you are running 64-bit Windows.

Connecting 32-bit R to a 32-bit Access database

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.

Query MS Access DB from R with 64-bit Windows

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!

Connect R and Vertica using RODBC

This is my first time connecting to Vertica. I have already connected to a MySQL database sucessfully by using RODBC library.
I have the database setup in vertica and I installed the windows 64-bit ODBC driver from https://my.vertica.com/download-community-edition/
When I tried to connect to vertica using R, I get the below error:
channel = odbcDriverConnect(connection = "Server=myserver.edu;Database=mydb;User=mydb;Password=password")
Warning messages:
1: In odbcDriverConnect(connection = "Server=myserver.edu;Database=mydb;User=mydb;Password=password") :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2: In odbcDriverConnect(connection = "Server=myserver.edu;Database=mydb;User=mydb;Password=password") :
ODBC connection failed
Can someone tell me how to fix this? Or is there any other ways to connect to vertica using R?
It may not be the fastest, but I prefer to use the Vertica JDBC driver from R. Getting the ODBC drivers working is a little messy across different operating systems. If you already have a Java Runtime Environment (JRE) installed for other applications then this is fairly straightforward.
Download the Vertica JDBC drivers for your Vertica server version from the MyVertica portal. Place the driver (a .jar file) in a reasonable location for your operating system.
Install RJDBC into your workspace:
install.packages("RJDBC",dep=TRUE)
In your R script, load the RJDBC module and create an instance of the Vertica driver, adjusting the classPath argument to point to the location and filename of the driver you downloaded:
library(RJDBC)
vDriver <- JDBC(driverClass="com.vertica.jdbc.Driver", classPath="full\path\to\driver\vertica_jdbc_VERSION.jar")
Make a new connection using the driver object, substituting your connection details for the host, username and password:
vertica <- dbConnect(vDriver, "jdbc:vertica://host:5433/db", "username", "password")
Then run your SQL queries:
myframe = dbGetQuery(vertica, "select Address,City,State,ZipCode from MyTable")
You have to use double slash in the classPath arguement in JDBC function.
for example,
vDriver <- JDBC(driverClass="com.vertica.jdbc.Driver",
classPath="C:\\Program Files\\Vertica Systems\\JDBC\\vertica-jdk5-6.1.2-0.jar")
worked for me, while just copying and pasting the route failed.

Resources