[Original Post]
I have seen a couple of similar SO questions but I don't think any of them are related to OS.
Long story short, this is what I see when I try to establish a ssl connection to Redshift.
library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv,
host = "XXXXXXXX.us-east-1.redshift.amazonaws.com",
port = 5439,
user = "XXXXXXXX",
password = "XXXXXXXX",
dbname = "db1")
> Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect XXXXXXXX#XXXXXXXX.us-east-1.redshift.amazonaws.com on dbname "db1")
I have tried the following and none of them worked.
Connect to Redshift via SSL using R
Importing files from PostgreSQL to R
Connect to Postgres via SSL using R
https://groups.google.com/forum/#!topic/rpostgresql-dev/ELnVUJqjDbk
I have an EC2 node (Ubuntu) in AWS and another Mac Pro in office, so I tried to use the same code to connect from both.
The Linux system works with copying & pasting the exact same code. Here is the Sys.info() on the Linux server:
sysname Linux
release 3.13.0-48-generic
version #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015
nodename ip-xx-xxx-xx-xx
machine x86_64
login unknown
user bcui
effective_user bcui
However, the Mac Pro failed with the exact same error message. Here is the Mac Sys.info() (same as my Mac laptop):
sysname Darwin
release 15.3.0
version Darwin Kernel Version 15.3.0:
Thu Dec 10 18:40:58 PST 2015;
root:xnu-3248.30.4~1/RELEASE_X86_64
nodename bcui-MBP.local
machine x86_64
login bcui
user bcui
effective_user bcui
I am wondering what could be different between the Mac and Linux configuration that causes this error message?
[Update 2016/02/10]
I have tried to uninstall R and all related files, and then reinstall R from homebrew:
brew tap homebrew/science
brew install R
Same error message:
> Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect XXXXXXXX#XXXXXXXX.us-east-1.redshift.amazonaws.com on dbname "db1")
FYI, I can connect to other non-ssl Redshift clusters using the same code, so it could be something related to openssl on Mac.
[Update 2016/02/11]
More info from #MasashiMiyazaki's comment:
I have used psql via CLI to connect and it works fine. In addition, I can also connect successfully using the Python module psycopg2. However, I will have to disable this line from .bash_profile in order for them to work:
export DYLD_LIBRARY_PATH=/usr/lib:$DYLD_LIBRARY_PATH
Taking a shot in the dark here. Have you tried RPostgres?
Install it like so
# install.packages("devtools")
devtools::install_github("RcppCore/Rcpp")
devtools::install_github("rstats-db/DBI")
devtools::install_github("rstats-db/RPostgres")
Then test it out
library(DBI)
library(RPostgres)
con <- dbConnect(RPostgres::Postgres(),
host = "XXXXXXXX.us-east-1.redshift.amazonaws.com",
port = 5439,
user = "XXXXXXXX",
password = "XXXXXXXX",
dbname = "db1")
Related
Disclaimer: I'm a statistician/bioinformatician by training, so I'm quite new to networks, servers, and databases.
System: Macbook Pro (M1 chip).
I'm trying to connect to an SQL Server database remotely via R and RStudio.
To start, I ran the following commands in terminal (as seen here https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver16):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y brew install msodbcsql18 mssql-tools18
The code I'm running in RStudio is as follows (as seen here https://db.rstudio.com/getting-started/connect-to-database):
library(DBI)
library(odbc)
con <- DBI::dbConnect(odbc::odbc(),
Driver = "ODBC Driver 18 for SQL Server",
Server = "xxx.xxx.xxx.xx",
Database = "Dbname",
UID = "username",
PWD = "password",
Port = 3306,
.connection_string ="TrustServerCertificate=yes")
The above gives me the following error:
Error: nanodbc/nanodbc.cpp:1021: 00000: [unixODBC][Driver Manager]Data
source name not found and no default driver specified
I can't find any help related to the errors I'm getting at https://db.rstudio.com/getting-started.
Slightly different piece of code gives me a different error:
con <- DBI::dbConnect(odbc::odbc(),
.connection_string = "Driver={ODBC Driver 18 for SQL
Server};Uid=username;Pwd=password;Host=xxx.xxx.xxx.xx;Port=3306;Database=Dbname;TrustServerCertificate=yes;")
Error: nanodbc/nanodbc.cpp:1021: 00000: [Microsoft][ODBC Driver 18 for
SQL Server]Neither DSN nor SERVER keyword supplied [Microsoft][ODBC
Driver 18 for SQL Server]Invalid connection string attribute
What is a Server Keyword as referred to in the second error? Is the server supposed to be an IP address as I've indicated in the code?
Does the use of ODBC Driver matter? How can I tell if I'm using the right one?
Am I off the mark with any of the information I'm feeding into dbConnect()?
Any tips welcome.
Thanks.
Thanks to #AlwaysLearning for pointing at the mistake in my second chunk of code. Host= should have been Server=.
As for the first chunk, I don't know why it wouldn't work.
I´m trying to connect to a Postgresql localhost server from R using the following commands:
rm(list=ls())
library(RPostgreSQL)
host="localhost";port=5432;user="postgres";pw="postgres"
dbname="myBase"
drv = RPostgreSQL::PostgreSQL()#dbDriver("PostgreSQL")
con = dbConnect(drv, dbname = dbname,host = host, port = port,user = user, password = pw)
rm(pw)
When I run de code, I get the following:
"Error in postgresqlNewConnection(drv, ...) : RS-DBI driver: I_)"
For some reason I get those strange symbols instead of an error message.
The version of R is 4.1.3, and I'm using 14.2.1 version of Postgresql. No problems when running queries from pgadmin directly.
I've tried uninstalling and re-installing both R and Postgreql and still no work.
Any clues?
I have a docker container that contains a database which I'm able to access with the user id and password below and am running into an error when attempting to connect using this code:
con <- DBI::dbConnect(odbc::odbc(),
Driver = "ODBC Driver 17 for SQL Server",
Port = 1433,
Server = "localhost",
Database = "master",
UID = "sa",
PWD = "password!23")
The error is:
Error: nanodbc/nanodbc.cpp:1021: 00000: [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute
Any ideas on what the issue could be?
Computer specs:
MacBook Pro (16-inch 2019)
OS: macOS Monterey (version 12.2.1)
Processor: 2.3 GHz 8-Core Intel Core i9
Memory: 16GB 2667MHz DDR4
Startup Disk: Macintosh HD
Graphics: AMD Radeon Pro 5500M 4 GB
Rstudio Version: 2021.09.0 Build 351
OpenSSL Version: 1.1
EDIT:
Switching the code such that the server references 127.0.0.1, 1433 fixed the latter error, but now I'm receiving the former:
Error: nanodbc/nanodbc.cpp:1021: 00000: [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection
Code used to attempt to create connection:
con <- DBI::dbConnect(odbc::odbc(),
driver = "ODBC Driver 17 for SQL Server",
server = "127.0.0.1,1433",
database = "master",
uid = "sa",
pwd = "password!23")
Docker command used to run the container:
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=password!23' -p '1433:1433' --name sql3 -d mcr.microsoft.com/mssql/server:2017-latest
Container attributes (docker ps --no-trunc):
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f755291fe369f9ad3339626528999bb7cef3d7947e68045b60fc4591f865aace mcr.microsoft.com/mssql/server:2017-latest "/opt/mssql/bin/nonroot_msg.sh /opt/mssql/bin/sqlservr" 24 minutes ago Up 41 seconds 0.0.0.0:1433->1433/tcp sql3
I don't have incontrovertible proof that it was Monterey 12.2.1 that was giving me problems, but downgrading to Big Sur 11.6.4 did resolve my issue (and gave me an opportunity to install dependencies in a more conscientious way).
Thanks everyone for your guidance!
I'm attempting to connect to a database within a local Docker image I've spun up using DBI and am running into some pretty cryptic errors... I've successfully started the Docker container (below shows result of docker ps -a):
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
131ab042012c mcr.microsoft.com/mssql/server:2017-latest "/opt/mssql/bin/nonr…" 27 minutes ago Up 27 minutes 127.0.0.1:1433->1433/tcp admiring_northcutt
I then try to connect via:
pool<- pool::dbPool(odbc::odbc(),
Driver = "ODBC Driver 17 for SQL Server",
Server = "localhost",
Database = "master",
UID = "sa",
PWD = "***********",
Port = 1433)
and receive the error:
Error: nanodbc/nanodbc.cpp:1021: 00000: [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute
Checking my odbc driver using odbc::odbcListDrivers() returns the output below, so the drivers seem to be present.
name attribute value
1 ODBC Driver 17 for SQL Server Description Microsoft ODBC Driver 17 for SQL Server
2 ODBC Driver 17 for SQL Server Driver /usr/local/lib/libmsodbcsql.17.dylib
3 ODBC Driver 17 for SQL Server UsageCount 2
In addition, executing the container and attempting to connect to the database via the commands:
docker exec -it <container-name> /bin/bash
/opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U sa -P '<password>'
EDIT: The above method now works and I'm able to actively query within the database. I know that the error can't be due to invalid login credentials because I'm using the same exact ones as I ran above in the container.
This same process works for a coworker, so I'm wondering if it's a local issue with my set up. We already compared our .ini files as suggested in this link and they're identical, I've clean re-installed Docker, and I've even ran the coworker's identical container with no luck. Any ideas what could be happening here?
Computer specs:
MacBook Pro (16-inch 2019)
OS: macOS Monterey (version 12.2.1)
Processor: 2.3 GHz 8-Core Intel Core i9
Memory: 16GB 2667MHz DDR4
Startup Disk: Macintosh HD
Graphics: AMD Radeon Pro 5500M 4 GB
Rstudio Version: 2021.09.0 Build 351
OpenSSL Version: 1.1
I am working with a remote server running Ubuntu 19.10. I'd like to initiate a non-headless chrome server and have developed the following script:
require(RSelenium)
eCaps <- list(chromeOptions = list(
args = c('--window-size=1280,800',
"--disable-extensions",
"--use-gl=swiftshader",
"--user-data-dir=/home/user/.config/google-chrome/Profile1",
"--remote-debugging-port=9222")
))
# Google Chrome version is 81.0.4044.138
rD <- rsDriver(browser = "chrome",
chromever = "81.0.4044.138",
extraCapabilities = eCaps,
port =
as.integer(base::sample(seq(32768,65535, by=1),1)))
remDr <- rD[["client"]]
remDr$navigate("https://stackoverflow.com/")
If I log into the box via SSH and start a new R session I can paste the above commands and Chrome server launches with the correct profile and saved passwords required for my purposes.
If, however, I run the exact same commands from RStudio Server this results in an error:
Selenium message:unknown error: Chrome failed to start: exited abnormally.
(chrome not reachable)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '4.0.0-alpha-2', revision: 'f148142cf8', time: '2019-07-01T21:30:10'
System info: host: 'xxx', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '5.3.0-59-generic', java.version: '1.8.0_252'
Driver info: driver.version: unknown
remote stacktrace: #0 0x55918478e189 <unknown>
Could not open chrome browser.
Client error message:
Summary: UnknownError
Detail: An unknown server-side error occurred while processing the command.
Further Details: run errorDetails method
Check server log for further details.
Some thoughts:
I'm only running the selenium server in non-headless mode as I cannot seem to launch Chrome with a saved profile (and saved passwords) when using the --headless argument.
If I use the --headless argument as above then the sever can be sucessfully launched both from within RStudio Server and an R terminal session
It feels like a permissions issue, and I have experimented with changing the RStudio Server user to my same username that I SSH into the box with, as per these instructions. This does not resolve the problem.
version.string R version 3.6.1 (2019-07-05)
[Package RSelenium version 1.7.7 Index]
Any help appreciated!