I try to do a simple connect to an Oracle database via DBI and ROracle package following instructions from R to Oracle Database Connectivity: Use ROracle for both Performance and Scalability.
When I test the connection via Windows7 > ODBC Data Source Administrator (32bit), the connection is successful. It uses the installed Oracle client OraClient11g_home1 which resides in C:\oracle\Client112_32. ORACLE_HOME environment variable is set to C:\oracle\Client112_32.
I am guessing it may be connected to some 32bit/64bit issue? But even after quite some research I did not find any solution. I also tried running the same in R 32bit but fails as well. BTW, the connection via SQL Developer is also successful.
drv <- DBI::dbDriver("Oracle")
#>Error: Couldn't find driver Oracle. Looked in:
#>* global namespace
#>* in package called Oracle
#>* in package called ROracle
I've had this issue as well. I found that loading the ROracle library beforehand fixes the problem.
library("ROracle")
drv <- DBI::dbDriver("Oracle")
I don't know why though.
Building on user11227405 answer: it is actually enough to load ROracle without attaching it on the search path; library() does both instead:
loadNamespace("ROracle")
drv <- DBI::dbDriver("Oracle")
that might be preferred e.g. in packages, where changing the search path should be avoided
Related
I am using an R Script which connects to a local Access database. For that, I used the 'odbc' package in R and created an odbc Driver in Windows. It works well on my machine.
The issue I have is, that it can't connect to the database when running the script on a foreign computer with different language settings than English. Both machines are running Windows 64-bit with Access and R on 64-bit. Running following Code:
library(odbc)
con <- dbConnect(odbc::odbc(), "AccessDB")
results in following error message:
Error in connection_info(ptr) : nanodbc/nanodbc.cpp:1072:
I didn't find a solution yet, I am thinking of using another database.
I received the same error today on a setup that usually works. After downgrading the odbc-package to 1.1.6, it works fine again.
I'm having issues connecting to my MongoDB via Mongolite, and I'm not sure if it is an issue on my side, or if I need to use a different package to connect to the database. Please keep in mind that I cannot change the software being run by the MongoDB server, and I am a novice when it comes to all of this, so it could just be a silly error on my part.
I've run the following code:
m <- mongo(collection = "test", url="mongodb://22.92.59.149:27017")
As far as I can tell from the Mongolite tutorial (https://jeroen.github.io/mongolite/), this is the correct syntax to connect to the database, but I'm not 100% sure. Regardless, I get the following error:
Error: Server at 22.92.59.149:27017 reports wire version 2,
but this version of libmongoc requires at least 3 (MongoDB 3.0)
From what I can tell, this means that mongolite won't work with my database. If that is the case, what other package should I try to use to connect, or if it is not the issue what am I doing wrong?
Thanks in advance!
As the message says, there is a mismatch between versions of the client and the server.
More precisely, mongolite relies on a more general driver written in C, libmongoc, and it seems the version automatically installed by the install.packages("mongolite") statement is too recent towards the server's version.
If you can't change anything server-side, maybe you could try to manually install an older version of libmongoc before installing mongolite, but I'm not confident about the compatibility with that R package afterwards.
Maybe you can use RMongo, an older and archived package to interact with Mongo in R, but I'm afraid what you're going to develop won't be stable in further R versions.
I'd rather recommend you to look at the problem server side.
Prior to upgrading to Windows 10, I was using RODBC to establish a connection within RStudio to a MS Access database.
After upgrading to Windows 10, my workflow is halted when I try to make the same connection to the same MS Access database.
db <- "//svr/userdatabases/database.accdb"
Make a connection to the database
con2 <- odbcConnectAccess2007(db)
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specifiedODBC connection failed>
I have confirmed that the database is located in the correct path (db).
Several sources have suggested that there is an issue with LD_LIBRARY_PATH, but I do not know how to implement the solutions discussed in these threads:
https://support.rstudio.com/hc/en-us/community/posts/200654626-odbcDriverConnect-works-in-R-but-not-RStudio
https://support.rstudio.com/hc/en-us/community/posts/211021467-Can-t-connect-to-SQL-database-using-RODBC-through-Rstudio-but-can-using-R-in-shell-
How do I implement the solution described in the second link? Specifically, how do I I had create a file "~/.Renviron" and add the following line:
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/nz/lib64/
According to that link, my issue is the ld library path within my rsession is not the same as my bash.
You might be missing the driver for the correct bit version of your database for RStudio to make the system connection. If your system connection works in R, but not R Studio, installing the correct driver from https://www.microsoft.com/en-us/download/confirmation.aspx?id=23734 might solve your issue.
We are moving away from RODBC which seems to have a limited error handling system (sometimes to query goes through even though there was an error, and there is no way to get the error message. we have tried all RODBC functions)
However there seem to be 2 packages similar: odbc and DBI, Can someone explain what is the difference between the two? Both seem to work well.
look at the odbc github
https://github.com/r-dbi/odbc#reading
They compare with the RSQLServer package and the odbc package seems to be faster.
I'm having an issue figuring out why I can't connect to a PSql DB from R. I am able to access the database from the terminal using the psql command, but when connecting through DBI and R I get the following message [with some information redacted]:
RS-DBI driver: (could not connect [username]#[database URI] on dbname "[dbname]"
The database string works fine both the terminal and this code works fine on the machine I am porting it from. I have reinstalled the versions of the libraries that match what was on the dev machine, and am still having problems.
Any advice?
Edit:
I was able to get it working by fiddling around with the library(...) statements. It seems changing the order of the DBI and RPostgreSQL libraries have an effect. RPostgreSQL requires DBI, but importing just RPostgreSQL still produced the could not connect error.
To future readers with this issue: fiddle with the order, it may help!
Just an educated guess: your psql is from the same machine, so uses the local connection. The DBI-based methods using the Postgresql library will use network connection so you actually have to open that the corresponding config file.
See eg here about pg_hba.conf.