connect to oracle database which located on other ip using R - r

I need connect to oracle database via R
I do so
library(RODBC)
library(RJDBC)
odbcConnect(dsn = "NBD-TEST-DEV-BLACKBOX",
uid = "Y", pwd = "X")
i use oracle sql developer client to get access
When i try connect via R
i get the errors
Warning messages:
1: In RODBC :: odbcDriverConnect ("DSN = NBD-TEST-DEV-BLACKBOX; UID = x; PWD = y"):
[RODBC] ERROR: state IM002, code 0, message [Microsoft] [ODBC Driver Manager] Data source not found and no default driver used
2: In RODBC :: odbcDriverConnect ("DSN = NBD-TEST-DEV-BLACKBOX; UID = x; PWD = y"):
ODBC connection failed
i think it becase the database on another IP (R on server which ip x.x.x.x, and oracle on IP Y.y.y.y
So i have two questions
how can i indicate path to ODBC , where it. My oracle sql developer in path "C:\Users\Admin\Desktop\sqldeveloper-19.1.0.094.2042-x64"
and how to indicate needed IP when connect

Related

Deploying shiny R app to shinyapps.io gives SQL connectivity error for the connection string

Hi i am using this connection string to deploy to shinyapps.io but it never connects
con <- DBI::dbConnect(odbc::odbc(),
Driver = "SQLServer",
Server = "server",
Database = "db",
UID ="user",
PWD="pass",
Port = 1433)
It gives this error:
Error in value[[3L]](cond) :
nanodbc/nanodbc.cpp:1021: 00000: [RStudio][SqlServer] Failed to locate Server/Instance Specified.
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
There can be multiple problems here.
Firstly, you may need to whiteslist shinyapps.io's IP addresses, the full list is available here. If your database is hosted on Azure or AWS, you can easily do it there, or ask your corporate admin to help.
Secondly, you'll need to explicitly specify which drivers shinyapps.io should use to access your database. Normally, when you connect to your database locally from R, you specify Driver = "SQL Server".
However, for shinyapps.io it needs to be Driver = "FreeTDS".
You'll need to set up a function that recognises if the app is being run locally or not, and uses a relevant driver. in case of the latter you'll also need to specify a port and a TDS version, like this:
# Check if the app is being run locally or on the server
is_local <- Sys.getenv("SHINY_PORT") == ""
# A function to connect to the SQL database
dbConnector <- function(server, database, uid, pwd, local = TRUE, port = 1433, tds_version = 7.4) {
# Local connect
if (local) {
DBI::dbConnect(
odbc::odbc(),
Driver = "SQL Server",
Server = server,
Database = database,
UID = uid,
PWD = pwd
)
} else {
# Remote connect
DBI::dbConnect(
odbc::odbc(),
Driver = "FreeTDS",
Server = server,
Database = database,
UID = uid,
PWD = pwd,
Port = port,
TDS_Version = tds_version
)
}
}
# Connect to the SQL database
con <- dbConnector(server, database, uid, pwd, is_local)

ODBC Connection to ORACLE in R

I am using both the DBI and ODBC package in "R" in order to make a connection to an ORACLE database.
Here is the connection code I am using:
library(DBI)
library(odbc)
con <- DBI::dbConnect(odbc::odbc(),
Driver = "ORACLE",
Host = "orasada.ca",
SVC = "STG",
UID = "username",
PWD = "password",
Port = 1521)
Everything looks fine to me, but I keep getting this error:
Error: nanodbc/nanodbc.cpp:983: IM002: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Any ideas on what I can change to make a successful connection?
Thanks.

Establish Microsoft SQL Server Connection with R/RStudio

I am trying to connect R with Microsoft SQL server. I have used Toad for SQL Server 6.8 so far for my queries. However, for some other analysis (which can be easily performed in R) I want to connect database with R.
I have tried R function "dbconnect" with providing server name and database name. See query below:
odbc_con <- dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "xxxxx",
Database = "yyyyy",
Uid = 'US\dhrdesai',
Pwd = rstudioapi::askForPassword("Database password"),
Port = 1433)
However, I got following errors:
Error: nanodbc/nanodbc.cpp:950: IM002: [Microsoft][ODBC Driver
Manager] Data source name not found and no default driver specified
and
Error: unexpected ')' in " Port = 1433)"
Have anyone faced the same or know any other way to connect R with SQL server.
You need to use a double backslash \\ every time you see a \. I just made my connection work yesterday with the following code. Also pehaps you have not installed all the packages that is required.
library(DBI)
library(dbplyr)
library(odbc)
con <- dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "path\\path", # remember \\ if your path has a \
Database = "the_database_name",
user = "your_user_name", # remember \\ if your username has a \
Trusted_Connection = "True")

setting property in odbc

I wonder how I can set domain to a value when I am trying to connect to a SQL database in R.
Basically, I need to set Domain to cphegtd3 to be able to get to the database.
I am using the
con <- dbConnect(odbc(),
Driver = "/usr/local/lib/libtdsodbc.so",
Server = "servername",
Database = "dbname",
UID = "myuserid",
PWD = "London",
Domain="cphegtd3",
Port = 1433)
and I get the following error
Error: nanodbc/nanodbc.cpp:950: 42000: [unixODBC][FreeTDS][SQL Server]Login failed for user 'myuserid'.
The reason it fails the username is that it does not consider Domain="cphegtd3". I didn't have this issue with RSQLServer::SQLServer() and domain was an entry in the yaml file.
I can also connect to the database through DBeaver and DataGrip, and of course have to set domain in the setting. But I don't know how to inform odbc in R with this parameter.

Acces denied MariaDB Amazon-rds instance RMySQL and OBDC (windows)

I'm trying to connect R with my MariaDB instance (10.0 - Amazon RDS). Connection works fine in HeidiSQL. Both in R and ODBC drivers installation (direct and indirect), next error is prompted:
Error in .local(drv, ...) :
Failed to connect to database: Error: Access denied for user 'user'#'localhost' (using password: YES)
My account is the admin account of this instance, I used the following code:
library(RMySQL)
mySqlCreds <- list(dbhostname = "dbname.rds.amazonaws.com" , dbname="dbnamefull" , username = "user",pass = "secret", port = 3306)
drv <- dbDriver("MySQL")
dbConnect(drv, host=mySqlCreds$dbhostname, dbname=mySqlCreds$dbname, user=mySqlCreds$username, password=mySqlCreds$pass, port = mySqlCreds$port)
Same problem while connecting an ODBC driver in Windows to this instance- finds database, but again no access. Even after modifying instance parameter groups in aws console, log_bin_trust_function_creators to 1, and rebooting the database.
If you know how to solve this issue, please let me know! Thank you in advance!

Resources