DBI or odbc package for SQL server - r

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.

Related

R Connect to Database WITHOUT Java?

I use the RJDBC package to connect to Amazon Redshift and it works ok. But very often I get a Java Heapsize error and it's really frustrating and not consistent. Sometimes it works fine, sometimes it doesn't. My problem is that my computer can ONLY use 32bit Java, which also forces me to use 32bit R, which means I can't use all my RAM.
Is there a package that can do this WITHOUT Java?

Error connecting to mongoDB using Mongolite

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.

R Oracle connect via DBI::dbDriver("Oracle") throws error

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

"Invalid BXL stream" in MS-SQL server while executing R scripts

I am executing an R script as ms-sql stored procedure. I'm trying to use the "geosphere" package, however when I execute the stored procedure, I'm getting the error "Invalid BXL stream" and the execution halts. The package is already installed on the machine and simply loading the package causes this error i.e library("geosphere") causes the error.
I can however, use this package independently with R Studio, so there doesn't seem to be any issue with the package.
I know this question is dated but I've run into the same issue multiple times so I wanted to leave my results here.
What I've found in using sp_execute_external_script to run R and Python scripts in MS-SQL 2016/17 is that the BXL error comes for 2 different reasons
Bad data types - Often, SQL doesn't understand the data types being sent out of the script. Usually explicitly casting the data as a certain datatype helps here.
Bad package configuration - Certain packages in the R and Anaconda distributions don't sync well with the stored procedure since the database blocks certain dependencies in these packages. Try reinstalling the package in the SQL installed instance of R or Python.
It seems that your problem falls in the latter category. I hope that helped!
Had a similar issue today but with a different package. Getting "invalid BXL stream from MSSQL stored procedure. However, i found that If i opened up Rterm.exe and typed the command 'require(packagename)' then Rterm crashes with "Rterm frontend has stopped working". This looks like a memory issue - which has also been suggested causes the "invalid BXL stream" error.
However, my issue turned out to be the fact that the dependencies for the packages had not been installed correctly (perhaps you are working through a proxy?).
I basically removed all the library packages that had been created when I first installed the problem package and did a install.packages("packagename"). All started working!
Apologies - just noticed that you stated that the package worked independently with R studio - this is probably an issue with R Memory allocation with SQL - See http://henkvandervalk.com/introducing-microsoft-sql-server-2016-r-services

Issues with RS-DBI driver in R

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.

Resources