H, I'm quite a newbie on this.
I have a Unix machine with R/RStudio and Python installed.
I need to connect to an Oracle DB in a secure way.
I have created a wallet with mkstore given by Oracle and with Python and cx_Oracle library I have no problems in connecting to this DB, but how can I afford the same result with R?
There's an example in the ROracle doc:
## Create connection authenticated with external credentials.
con <- dbConnect(drv, username ="", password="", external_credentials = TRUE)
You'll probably need to pass dbname too.
Related
Can anyone provide the connection string for connecting to Snowflake through RODBC:: odbcconnect in R?
Thanks in advance!
I'm moving from Teradata to Snowflake. And I have a lot of functions in my code which works only with an RODBC connection, but I'm only finding DBI connections to Snowflake on the internet.
Based on your question I assume that you have already installed the Snowflake ODBC driver and created a DSN following the Snowflake documentation appropriate for your OS and you have installed RODBC package working with other ODBC DSNs in your system.
Then you can connect to Snowflake as follows:
library(RODBC)
ch <- odbcConnect("DSN_NAME", uid = "USERNAME", pwd = "PASSWORD")
#test query to test the connection by printing the current timestamp
sqlQuery(ch, paste('SELECT CURRENT_TIMESTAMP()'))
I'm struggling to connect my shiny application to one of the database we use in our company. I've succesfully connected to Azure / Mongo / SQL Server databases but now I've got a SAP SQL Anywhere 17 database to connect to.
Not surprisingly there's no specific connection to that database provided in the R Drivers (https://www.rstudio.com/products/drivers/).
Now I can solve this in two ways I believe, our IT department is convinced that a generic ODBC connection should work, or I have to get the specific SQL Anywhere drivers installed on my shiny app somehow.
For both solutions I can't find much online. If I search for generic ODBC connection the recommendations go to FreeTDS which is in the RODBC package, which then might not work together with Pool (according to what I've read).
Searching how to install specific drivers on a shiny application is also not bringing me much.
Try using
options(java.parameters="-Xmx8g")
library(RJDBC)
drv <- JDBC("com.microsoft.sqlserver.jdbc.SQLServerDriver", "drivers/jdbc/mssql-jdbc-8.4.1.jre8.jar", identifier.quote="`")
processingStart = Sys.time()
conn <- dbConnect(drv,
"jdbc:sqlserver://SERVER_NAME;databaseName=DATABASE_NAME",
user = "USER_NAME",
"PASSWORD"
)
I'm struggling a bit with how to connect R to ServiceNow ODBC.
The closest solution I found is https://www.cdata.com/kb/tech/servicenow-odbc-r.rst, but it's using some paid software dependencies to make it work, which I think unnecessary.
If someone else has managed to set up a connection between R and ServiceNow, I would like to learn how.
ServiceNow provides its own ODBC driver. Once installed, you can connect to the ServiceNow instance using DBI library.
library(DBI)
con <- dbConnect(odbc::odbc(), .connection_string = "Driver={ServiceNow ODBC Driver 64-bit};", timeout = 10)
I am trying to make a connection from R to Oracle and I am having issues doing so.
Here is the connection script I am using with the DBI and odbc packages:
library(DBI)
library(odbc)
con <- DBI::dbConnect(odbc::odbc(),
Driver = "Oracle in OraClient11g_home1",
Server = "orasade06.hc-sc.gc.ca",
SID = "sdv11040",
Schema = "STG",
Username = "username",
Password = "pw",
Port = 1521)
I am able to make a successful connection through Oracle SQL Developer to view my database and schema.
I have installed the Oracle ODBC driver (Oracle in OraClient11g_home1) on my machine, however I cannot make a successful connection from "R".
Here is the error I get:
Error: nanodbc/nanodbc.cpp:983: IM002: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Any help and guidance would be greatly appreciated.
Thanks.
I have written a tutorial around this, maybe take a look :
https://guillaumepressiat.github.io/blog/2019/11/oraclyr
Some key points :
If your Oracle client is 32-bit, using R 32-bit is a (or the) solution. Otherwise R and odbc error messages aren't crystal-clear
In RStudio see if an Oracle client appears in Connections Pane
It's easier on linux but strings and parameters for odbc are a little different.
Lastly, for connection string, this answer is interesting : how to make a connection string for oracle that includes hostname, instance name, user id, password using system.data.oracleclient?
Maybe someone knows if it's possible to send data from ms sql database to R server, so it could calculate some columns and send them back to ms sql again?
I am not that much familiar with R server's integration and I am cautious that is not even possible. If this is not possible, maybe it would be possible to send them from asp.net mvc 5 using integration from .net library, but I do not think that is a good solution because the data can have more then 500k rows so it would be extremely slow.
Querying a database from a server running R requires three things:
Network security that allows you to communicate between the machines
Drivers installed on the R server
Configurations that allow you to connect to the database from R
In general, it is best to have your IT/Ops team take care of the Networking security and the installation of drivers, since these are things that they likely have security procedures around. We recommend using the RStudio Professional Drivers, which are easy to install and designed to work with our products.
Then, when it comes to the connection from R to the database, we recommend using the odbc package, which is a DBI compliant interface to using ODBC drivers. You can acquire the latest stable version from CRAN with install.packages("odbc").
In general, a connection looks something like this:
library(odbc)
con <- dbConnect(odbc(),
Driver = "SQLServer",
Server = "mysqlhost",
Database = "mydbname",
UID = "myuser",
PWD = rstudioapi::askForPassword("Database password")
Port = 1433)
The rstudioapi::askForPassword function will prompt the user for a password and reduce the need to store passwords in code. For more options on securing credentials, there is a dedicated article on the topic. Note that there is also support for DSNs:
# Using a DSN
con <- dbConnect(odbc::odbc(), "mydbalias")
for other reference please visit this url.
Hope it helps.