Shiny Server cannot use RODBC to connect to DB2 but RStudio can in a Docker Container - r

I am working on deploying a shiny application in a Docker container onto Bluemix. I am using the rocker/shiny Docker image (https://hub.docker.com/r/rocker/shiny/) as my initial starting point. I have installed unixODBC-dev, RODBC, ibm data server driver package, the ibmdbR library for R, and all needed dependencies. My only problem is that when I try to access the shiny app from a web browser it fails to execute, the error is:
Warning in odbcDriverConnect("DSN=BLUDB", :
[RODBC] ERROR: state 01000, code 0, message [unixODBC][Driver Manager]Can't open lib '/root/db2_cli_odbc_driver/dsdriver/odbc_cli_driver/linuxamd64/clidriver/lib/libdb2o.so' : file not found
Warning in odbcDriverConnect("DSN=BLUDB; :
ODBC connection failed
Error in idaInit(con) : con is not an open connection, please use idaConnect() to create an open connection to the data base.
Initially I had this same problem whenever I would try to use isql to connect to the database or try to connect from RStudio, I used ldd on that library file and found what was missing and that fixed making connections from the command line and RStudio, however my Shiny-Server still gives me the same error, is there anything I am missing?

I ended up solving the problem myself, turns out the libraries were not accessible by the shiny-server which was running as a service. I moved the db2 odbc drivers over to /usr/local/lib to make it accessible, I also ran the "ldd" command on the library mentioned in the error message and found that I had to install libxml2 as well. After doing that I simply changed my odbcinst.ini file at /etc to reference the new location of the db2 library and now it all works! Hopefully anyone else trying to deploy Shiny Apps that rely on connecting to a DB2 database will find this useful.

Related

Simba Athena ODBC: unable to use SQLGetPrivateProfileString functions

This is very strange, I want to setup a connection from RStudio to my instance in AWS Athena.
I am using unixodbc as the driver manager, and succeded by testing the connection using isql -v 'Simba Athena'. However, when I test the connection in RStudio with...
con <- DBI::dbConnect(
odbc::odbc(),
"Simba Athena"
)
... it gives me the error Error: nanodbc/nanodbc.cpp:1021: 00000: [Simba][ODBC] (11560) Unable to locate SQLGetPrivateProfileString function.. Any clue about it, I am a bit stuck.
It is basically not finding the correct ODBC driver. Simba by default references the driver in its /Library/simba/athenaodbc/lib/simba.athenaodbc.ini setup file to libodbc.dylib but it should be libodbcinst.dylib. At least in MacOS.
This solved my problem.
I got the same error when I link with static library of "libodbc.a", however I can succeed to connect when I change to link with dynamic library of "libodbc.so"

Installing a package from private GitLab server on Windows

I am struggling with installing a package from a GitLab repository on a Windows computer.
I found different hints but still have problems to install my package from GitLab. First of all, I generated a public and private key with puttygen.exe. The files need to be changed afterwards, I had to remove comments and stuff so they look like my the file on my Unix system. So now, both public and private key files have just a single line.
I tried to install my package via devtools::install_git which takes very long and I get the error message
Error: Failed to install 'unknown package' from Git:
Error in 'git2r_remote_ls': Failed to authenticate SSH session: Unable to send userauth-publickey request
And with devtools::install_gitlab I get a different error message and I somehow have the feeling, the link which gets generated doesn't fit to my GitLab server.
Error: Failed to install 'unknown package' from GitLab:
cannot open URL 'https://gitlab.rlp.net/api/v4/projects/madejung%2FMQqueue.git/repository/files/DESCRIPTION/raw?ref=master'
My complete code to test at the moment is
creds <- git2r::cred_ssh_key(publickey="~/.ssh/id_rsa_gitlab.pub",
privatekey="~/.ssh/id_rsa_gitlab")
devtools::install_git(
url='git#gitlab.rlp.net:madejung/MQqueue.git',
quiet=FALSE,
credentials=creds)
devtools::install_gitlab(
repo='madejung/MQqueue.git',
host='gitlab.rlp.net',
quiet=FALSE,
credentials=creds
)
My id_rsa_gitlab.pub file looks like this and is just a single line:
ssh-rsa AAAA....fiwbw== rsa-key-20200121
The id_rsa_gitlab file has just the code:
AAABA.....3WNSIAGE=
Update
On my Mac system it works as expected after installing the libssh2 library via homebrew and and recompiling git2r with install.packages("git2r", type = "source").
So the working code on my machine is:
creds <- git2r::cred_ssh_key(publickey="~/.ssh/id_rsa_gitlab.rlp.net.pub",
privatekey="~/.ssh/id_rsa_gitlab.rlp.net")
devtools::install_git(
url='git#gitlab.rlp.net:madejung/MQqueue.git',
quiet=FALSE,
credentials=creds
)
For some strange reason, the devtools::install_git call needs about a minute to fail in the end. I have no idea where the problem here is.
After struggling for almost a day, I found a solution I can live with...
I first created a PAT (Personal Access Token) in my gitlab account and granted full API access. For some reason the read_only access didn't worked and I am now tired to figure out what the problem is.
After this I had still problems to install my package and for some reason, the wininet setting for downloading doesn't work.
I used the command capabilities("libcurl") to check if libcurl is available on my windows, which was and tried to overwrite wininet to libcurl by using method='libcurl' in the install function. Somehow, this was not enough so I overwrote the options variable download.file.method directly.
options("download.file.method"='libcurl')
devtools::install_gitlab(
repo='madejung/MQqueue',
auth_token='Ho...SOMETHING...xugzb',
host='gitlab.rlp.net',
quiet=FALSE, force=TRUE
)

7: [unixODBC][DataDirect][ODBC 20101 driver]6015 error

For our application we have planned to use the Progress Data Direct ODBC driver for oracle. So i have downloaded the EVAL version and installed it. Our application servers are running in the Linux environment.
After installing the EVAL version i have tested the sample code provided by them. I have configured the ODBC.INI and ODBCINST.INI properly.
Tested the DSN connection successfully with the sample program provided by DataDirect Progress.
Then i started using the same for my application Lib LD path set properly ODBC , ODBCINST variables are properly set.
when i try to bring up my servers i got the below error message
7: [unixODBC][DataDirect][ODBC 20101 driver]6015
In this message i'm not getting the message description , only i got the error code which is 6015
How to get the error message for this code 6015 ?
Any help on this?
Due to the older version of driver got the error , so installed newer version and it got resolved.

ubuntu to windows find file path r setwd

So I have an Access database that I am trying to see on a windows server 2008 R2 (server name: WrenLab02); this server has the network discovery on, has the folder shared with that title, and is able to be pinged from the ubuntu computer; however now I want to call the folder that the files are in (which I tested on the server itself and works), but on the Ubuntu it keeps saying file directory not found.
On the Ubuntu computer in R:
FilePath <- file.path("//WrenLab02/Clinical/")
if (file.exists(FilePath)) {
setwd(FilePath)
} else {
dir.create(file.path(FilePath))
setwd(FilePath)
}
I know the path exists; I've tried it from another computer (which worked). Even I tried putting "smb://Wrenlab02/Clinical/" as the file director and still the setwd() cannot set the file path.
Maybe I just don't have the folder properly mapped to the Ubuntu, I tried to mount it and it is logged in and I can look at the files inside the folder and indeed the path says smb://WrenLab02/Clinical/. So I don't know where to go from here.
I figured it out; if anyone else is trying to pull files from a windows machine and you are working on a Lynx or Unbuntu machine this code should help you out.
setwd("/run/user/1000/gvfs/smb-share:server=wrenlab02,share=clinical/")
However now I am trying to use odbcConnect from RODBC package; this will connect me to a database from another server
WrenLIS <- '/run/user/1000/gvfs/smb-share:server=wrenlab01,share=administration/DATABASE/CLINICAL DATABASE/PatientContactDB.accdb'
cns <- odbcConnect(dsn="WrenLIS", uid="nferranti", pwd="H0ckey")
but it wont connect I keep getting an error that says:
Warning messages:
1: In RODBC::odbcDriverConnect("DSN=WrenLIS;UID=nferranti;PWD=H0ckey") : [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=WrenLIS;UID=nferranti;PWD=H0ckey") : ODBC connection failed

Problems connecting remotely to PostgreSQL on Heroku from R using RPostgreSQL

I'm using the RPostgreSQL 0.4 library (compiled on R 2.15.3) on R 2.15.2 under Windows 7 64-bit to interface to PostgreSQL. This works fine when connecting to my PostgreSQL databases on localhost. I'm trying to get my R code to run with a remote PostgreSQL database on Heroku. I can connect to Heroku's PostgreSQL database from the psql command shell on my machine, and it connects without a problem. I get the message:
psql (9.2.3, server 9.1.9)
WARNING: psql version 9.2, server version 9.1.
Some psql features might not work.
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Clearly, psql uses SSL to connect. When I try to connect using the RPostgreSQL library routine dbConnect(), however, supplying exactly the same credentials using dname=, host=, port=, user=, password=, the connection fails with the complaint:
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect <user>#<hostname> on dbname <dbname>)
Calls: source ... .valueClassTest -> is -> is -> postgresqlNewConnection -> .Call
Execution halted
I know that Heroku insists on an SSL connection if you want to access their database remotely, so it seems likely that the R interface routine dbConnect() isn't trying SSL. Is there something else that I can do to get a remote connection from R to PostgreSQL on Heroku to work?
To get the JDBC URL for your heroku instance:
Get your hostname, username and password using [pg:credentials].
Your jdbc URL is going to be:
jdbc:postgresql://[hostname]/[database]?user=[user]&password=[password]&ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
Proceed as you would normally with JDBC.
Apparently there is a way using RJDBC. See:
http://ryepup.unwashedmeme.com/blog/2010/11/17/working-with-r-postgresql-ssl-and-mssql/
Please note that in order to connect to Heroku database with JDBC externally, it is important to set the sslfactory parameter as well. Hope Heroku team goes through it and modifies their documentation.
String dbUri = "jdbc:postgresql://ec2-54-243-202-174.compute-1.amazonaws.com:5432/**xxxxxxx**";
Properties props = new Properties();
props.setProperty("user", "**xxxxx**");
props.setProperty("password", "**xxxxx**");
props.setProperty("ssl", "true");//ssl to be set true
props.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory");// sslfactory to be set as shown above
Connection c=DriverManager.getConnection(dbUri,props);
See answer to related Q at https://stackoverflow.com/a/38942581. The suggestion of using RPostgres (https://github.com/rstats-db/RPostgres) instead of RPostgreSQL resolved this same issue for me.

Resources