connecting to clickhouse in R - r

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?

Related

Trouble accessing oracle database using R (odbc package)

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

RODBC connection from R to SQL failing

I'm using R Studio to connect to SQL Server Management using library(RODBC).
Note that the below code works on my local system, but does not work when trying to connect remotely.
This is my connection code:
connection <- RODBC::odbcDriverConnect( 'driver={SQL Server};server=SERVERNAME ;database=DBNAME;trusted_connection=TRUE' )
I get the following warning message:
Warning messages:
1: In RODBC::odbcDriverConnect("driver={SQL Server};server=SERVERNAME;database=DBNAME;trusted_connection=TRUE") :
[RODBC] ERROR: state 08001, code 18, message [Microsoft][ODBC SQL Server Driver][DBNETLIB]SSL Security error
2: In RODBC::odbcDriverConnect("driver={SQL Server};server=SERVERNAME;database=DBNAME;trusted_connection=TRUE") :
[RODBC] ERROR: state 01000, code 772, message [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (SECDoClientHandshake()).
3: In RODBC::odbcDriverConnect("driver={SQL Server};server=SERVERNAME;database=DBNAME;trusted_connection=TRUE") :
ODBC connection failed
It's really odd because I definitely have access to the server and database in question.
It's worth noting that I have access to the server from a local system (above code works) and access to a remote system (code does not work).
Any idea why this might be happening?
RODBC is not a great package, it would be much better to use the RStudio built odbc instead:
library(odbc)
con <- dbConnect(odbc(),
Driver = "SQL Server",
Server = "SERVER",
Database = "DATABASE",
Trusted_Connection = "True" ,
timeout = 5000
)
In the following command line
connection <- RODBC::odbcDriverConnect( 'driver={SQL Server};server=SERVERNAME ;database=DBNAME;trusted_connection=TRUE' )
make trusted_connection = FALSE or no. Its a simple case of SSL error. If you are using linux, for server, use ip address rather than hostname.

Error in connecting R to Redshift

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.

Print dbConnect exception in R?

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="***")

R - connecting to SQL Server using using RSQLServer

I want to use RSQLServer instead of RODBC to connect to a database called 'Mkt_DW'. I think my server hostname is my machine DHX number - that's what is returned when I query the hostname in SQL Server 2008 using:
SELECT HOST_NAME() AS HostName, SUSER_NAME() LoggedInUser
I then enter the following code into R Studio:
library(RSQLServer)
library(DBI)
driver <- dbDriver("SQLServer")
url <- "DHX32510;Database=Mkt_DW;Trusted_Connection=TRUE;"
conn <- dbConnect(driver, url)
I get the following error:
Error in rJava::.jcall(drv#jdrv, "Ljava/sql/Connection;", "connect", url, :
java.sql.SQLException: Network error IOException: Connection refused: connect
Can anyone tell me what I'm doing wrong?
Thanks,
Neil
It is because it cannot find the 'sql.yaml' file:
See not from the package author:
"See ?SQLServer. It will look for the YAML file in the following location by default: Sys.getenv("HOME")"
https://github.com/imanuelcostigan/RSQLServer/issues/57

Resources