Using RPostgreSQL and getting an exception on dbConnect:
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect ...)
Calls: dbConnect -> dbConnect -> postgresqlNewConnection -> .Call
Execution halted
Looking for a way to catch the error reported by the database engine. dbGetexception requires a connection object, so its no use when the connection fails.
Is there a way to throw an error that reports what the error message from the DB engine is, so I know why the connection failed?
All that is needed to generate an error, either with an unavailable server, or bad user or DB name is:
library('RPostgreSQL')
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, host= "***", dbname = "***", user="***")
Related
I am trying to connect to my localhost Postgres DB within R to further read/write tables. The server is running in the background which I'm monitoring in the background. I'm using the RPostgreSQL library.
pg <- dbDriver(drvName = "PostgreSQL")
con <- dbConnect(drv = pg, dbname = "test",
host = "localhost",
port = 5432,
user = "postgres",
password = "1234")
dbListTables(con)
Just running the dbConnect part gives a strange message reading:
ØJI)
Further running the dbListTables function gives:
Error in h(simpleError(msg, call)) :
error in evaluating the argument 'conn' in selecting a method for function 'dbWriteTable': object 'con' not found
I can't figure out what I am missing.
Edit: I think I'm not using the RPostgreSQL library correctly. Using RPostgres worked perfectly now.
A colleague at work is having trouble using the odbc package function. I am trying to find help.
He is using an oracle database using R instead of running our traditional SAS programs, but he has not been successful. We are trying to find out what is causing the error messages below. Can someone help?
Attempt 1:
#Get the Oracle JDBC driver
jdbcDriver =JDBC("oracle.jdbc.OracleDriver",
classPath="C:/instantclient_19_10/ojdbc8.jar")
Create connection string to the Database we want
connect.string <-
glue("jdbc:oracle:thin:#//{host}:{port}/{sid}",
host = "stdbprd01.states.bls.gov",
port = 1521,
sid = "lausonep")
print(connect.string)
#Establish connection to your database
con <- dbConnect(jdbcDriver,
connect.string,
user = "username",
password = rstudioapi::askForPassword("Database password"))
Error in .jcall(drv#jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1], :
java.sql.SQLRecoverableException: Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
Attempt 2:
library(odbc)
con <- DBI::dbConnect(odbc::odbc(),
driver="Oracle in OraClient12Home1",
database="lausprd",
uid="aakre_n",
pwd="!QAZ1qaz#WSX2wsx",
host="stdbprd01.states.bls.gov",
port=1521
)
Error: nanodbc/nanodbc.cpp:1021: IM006: [Oracle][ODBC][ORA]-12560: TNS:protocol adapter error
[Microsoft][ODBC Driver Manager] Driver’s SQLSetConnectAttr failed
I am new to clickhouse. I am trying to set connection in the following way:
library(DBI)
con <- dbConnect(clickhouse::clickhouse(),
host="localhost",
port=8123L,
user="default",
password="")
but I get this error:
Error in .local(drv, ...) : dbIsValid(con) is not TRUE
I have tested the authentication and they are correct. I also check the connection with dbCanconnect and I get this error:
"fail to connect: Operation now in progress"
Could you please help on that?
I'm trying to connect RStudio to Amazon Redshift via JDBC and this is what I tried to run:
driver <- JDBC("com.amazon.redshift.jdbc42.Driver", "~/Downloads/RedshiftJDBC42-1.2.1.1001.jar", identifier.quote="`")
# url <- "<JDBCURL>:<PORT>/<DBNAME>?user=<USER>&password=<PW>
url <- "jdbc:redshift://<cluster-name>.<xxxxxx>.us-east-1.redshift.amazonaws.com:5439/<dbname>?user=<username>&password=<password>"
conn <- dbConnect(driver, url)
When executing dbConnect(), I get the following error:
Error in .jcall(drv#jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1], :
java.sql.SQLException: [Amazon](500150) Error setting/closing connection: Operation timed out.
Any idea what is causing this and how to fix it?
Update: There was a problem with access through security groups. If you're having a similar issue, check the inbound rules of your security group and make sure they allow access to Redshift via your IP.
In R, I'm using the RPostgreSQL package to connect to my Postgres database (9.5.1). Here's the code:
library("RPostgreSQL")
con <- dbConnect(dbDriver("PostgreSQL"), dbname="mydb", host="localhost", port=5432, user="myuser")
This does not work, per this message:
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect myuser#localhost on dbname "mydb"
)
Calls: system.time ... .valueClassTest -> is -> is -> postgresqlNewConnection -> .Call Execution halted
However, if I explicitly put in the host address instead of localhost, it works, i.e.
library("RPostgreSQL")
con <- dbConnect(dbDriver("PostgreSQL"), dbname="mydb", host="15.2.52.1", port=5432, user="myuser")
I realize this is not much to go on, but I'd like to use localhost here. I'm working on Ubuntu 14.