Trouble with using RODBC to access Northwind.accdb file - r

I'm trying to demo SQL queries from within R using the Northwind.accdb file. I visited http://office.microsoft.com/en-us/templates/desktop-northwind-2007-sample-database-TC001228997.aspx and was able to download the .accdt file. I've tried creating a database connection using RODBC with the following two lines, but both return the same error that R is unable to find the file, even though I am certain of its location (on the desktop).
Here are the lines of code that I'm using:
conn <- odbcConnectAccess2007("Nwind.accdt", uid = "", pwd = "")
conn <- odbcConnectAccess2007("Nwind.accdb", uid = "", pwd = "")
The error output I'm getting looks like this:
Warning messages:
1: In odbcDriverConnect(con, ...) :
[RODBC] ERROR: Could not SQLDriverConnect
2: In odbcDriverConnect(con, ...) : ODBC connection failed
Very grateful for any pointers you all might have.

There are some problems when using 32 bit drivers on 64 bit Windows. If you have ODBC 32 bit installed, coming with older versions of Office, make sure that you are running 32-bit R (easy with RStudio under Tools).
Or, with 64 bit drivers, use 64 bit R.

Related

Loading EXASOL data in R. Unknown ODBC error

R is unable to read the EXASOL Database due to some unknown ODBC error. Has anyone come across a similar instance. The problem occurs with Mac OS.
I have installed the ODBC driver for Mac OS.
library(exasol)
library(RODBC)
con <- dbConnect("exasol", **)
# removed the connection credentials
df1 <- dbGetQuery(con,paste("query", sep=""))
# removed the query
Error in try(.Call(C_asyncRODBCQueryFinish, slot, 1)) :
Unknown ODBC error
Error in exa.readData(conn, statement, ...) :
Could not allocate SQLAllocHandle (-2)
Error in exa.readData(conn, statement, ...) : Unknown ODBC error
The issue is at the moment unanswered here https://github.com/exasol/r-exasol/issues/32.
Can you tell more about the tools/drivers/components you use? Version numbers and the like?
I have some faint memories of seeing the same (or very similar error message) when I tried to use unixodbc. I had to remove it and use libiodbc. May it be the source of the issue in your case?
I had a similar issue, what helped me was to reinstall install.packages("RODBC", type="source")

Problems with connecting to local postgres database from R through RPostgreSQL

I have to following code
drv <- RPostgreSQL::PostgreSQL()
con <- DBI::dbConnect(drv, dbname = 'dbname', user = 'user',
host = 'host.name', port = 5432, password = 'password')
When I run it on server (Ubuntu server 16.04 with latest updates) running the database I get the following error:
Error in .valueClassTest(ans, "data.frame", "dbGetQuery") :
invalid value from generic function ‘dbGetQuery’, class “NULL”, expected “data.frame”
But when I run R from commandline with sudo, it works, when I run it from different my laptop connecting to the DB on the server it also works. So it shouldn't be connection problem. I am thinking about problem with access rights to some libraries/executables/configs on the system? Any help will be appreciated.
When I run the dbConnect multiple times and it ends with the error, when I run drv_info <- RPostgreSQL::dbGetInfo(drv), I still get multiple connectionIds in the drv_info:
drv_info <- RPostgreSQL::dbGetInfo(drv)
> drv_info
$drvName
[1] "PostgreSQL"
$connectionIds
$connectionIds[[1]]
<PostgreSQLConnection>
$connectionIds[[2]]
<PostgreSQLConnection>
$fetch_default_rec
[1] 500
$managerId
<PostgreSQLDriver>
$length
[1] 16
$num_con
[1] 2
$counter
[1] 2
Found a source of confusion, but not necessarily the root problem. (I was assuming RPostgres, while you are using RPostgreSQL (github mirror).)
If you check the source, you'll find that the method is calling postgresqlNewConnection, which includes a call to dbGetQuery. The problem you're seeing is that your call to dbConnect is failing (my guess is at line 100) and returns something unexpected, but postgresqlNewConnection continues.
I see three options for you:
try calling dbConnect(..., forceISOdate=FALSE) to bypass that one call to dbGetQuery (note that this doesn't fix the connection problem, but it at least will not give you the unexpected query error on connection attempt);
raise an issue for the package maintainers; or
switch to using RPostgres, still DBI-based and actively developed (it looks like RPostgreSQL has not had significant commits in the last few years, not sure if that's a sign of good code stability or development stagnation)
One lesson you may take from this is that you should check the value returned from dbConnect; if is.null(con), something is wrong. (Again, this does not solve the connection problem.)

how to read data from Cassandra (DBeaver) to R

I am using Cassandra CQL- system in DBeaver database tool. I want to connect this cassandra to R to read data. Unfortunately the connection takes more time (i waited for more than 2 hours) with RCassandra package. but it does not seem to get connected at all and still loading. Does anyone has any idea on this?
the code as follows:
library(RCassandra)
rc <- RC.connect(host ="********", port = 9042)
RC.login(rc, username = "*****", password = "******")
after this step RC.login, it is still loading for more than 2 hours.
I have also tried using RJDBC package like posted here : How to read data from Cassandra with R?.
library(RJDBC)
drv <- JDBC("org.apache.cassandra.cql.jdbc.CassandraDriver",
list.files("C:/Program Files/DBeaver/jre/lib",
pattern="jar$",full.names=T))
But this throws error
Error in .jfindClass(as.character(driverClass)[1]) : class not found
None of the answers are working for me from the above link.I am using latest R version 3.4.0 (2017-04-21) and New version of DBeaver : 4.0.4.
For your first approach, which I am less familiar with, should you not have a line that sets the use of the connection?
such as:
library(RCassandra)
c <- RC.connect(host ="52.0.15.195", port = 9042)
RC.login(c, username = "*****", password = "******")
RC.use(c, "some_db")
Did you check logs that you are not getting some silent error while connecting?
For your second approach, your R program is not seeing a driver in a classpath for Java (JMV).
See this entry for help how to fix it.

ODBC error running R script in cmd window

This is a follow-up question to:
Error in running R script in cmd window
I am still getting errors, but I switched from 64bit to 32bit R, and I think I am closer now, so I was hoping the following would jog someone's memory or tinfoil :)
Anyway, the paradox is that the following code runs instantly INSIDE of R :
library(RODBC)
myconn <- odbcConnect("****", uid = "*******", pwd = "*******")
test <- sqlQuery(myconn, "select * from tableAXd")
close(myconn)
summary(test)
But the very same code (in bat_test.R), sourced from a .bat file with this code:
C:\Users\********\Documents\R\R-3.3.1\bin\Rscript.exe "C:\schedule\bat_test.R"
generates the following error in the cmd window:
[RODBC] ERROR: state IM104, code 0, message [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and the Application...
So, why would the exact same code run sweetly from R, but choke on ODBC from a .bat file?
Thanks for listening...
isotope

The used command is not allowed with this MySQL version within R Studio

I have a MYSQL (which I'm very new to) database hosted on azure, which i'm trying to write data to from RStudio using the RMySQL package.
I am receiving the following message
> dbWriteTable(searchdb,"searchrecords",data, append = TRUE)
Error in .local(conn, statement, ...) :
could not run statement: The used command is not allowed with this MySQL version
Can anybody provide a suggestion as to why this may be?

Resources