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?
Related
I've the error ORA - 12560 when I try connect to Oracle DB installed on VM.
sql*plus, pl/sql, excel - connect successfully
Сonnection code in R
con <- dbConnect(odbc::odbc(), driver ='Oracle in instantclient_19_14',
dns = "user", encoding = "windows-1251",PWD ="qazedcwsx")
#--- output Error: nanodbc/nanodbc.cpp:1021: IM006: [Oracle][ODBC][Ora]ORA-12560: TNS:protocol adapter error
sql*plus I can connect only if after the password I write #sid, in R same method not working
Help please =(
Connected ! =)
con <- dbConnect(odbc::odbc(),
.connection_string = "Driver={Oracle in nstantclient_19_14};Dbq=XE;Uid=user;Pwd=qazedcwsx;)
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.
I'm trying to use
odbcDriverConnect("driver={SQL
Server};server=IP;database=DBNAME;uid=username;pwd=password")
to connecting sql server database from shiny R,
but its result is -1.
I run the same code in R studio and get results normally, what's the problem?
For testing more I tried this one:
con <- dbConnect(odbc::odbc(),
Driver = "SQL Server",
Server = "IP",
Database = "dbname",
UID = "username",
PWD ="password",
Port = Port)
But again it runs in R studio but not in shiny and gets this error:
nanodbc/nanodbc.cpp:950: IM002: [unixODBC][Driver Manager]Data source name
not found, and no default driver specified
I have postgres installed locally in my ubuntu. The dbname is postgres and the user name is also postgres. When I'm trying to connect this database to my R script, I'm getting an error saying-
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect postgres#localhost on dbname "postgres"
Here is the command that I'm running-
con <- dbConnect(drv, dbname = "postgres",
host = "localhost", port = 5432,
user = "postgres", password=pw)
I checked that this is the right command to run to make this connection and I have also used this to connect to an external server before. But somehow I'm not able to connect to my local postgres instance.
What do you think I'm missing out?
I have build up a postgresql 9.2 database. My table looks like that:
CREATE DATABASE "EURUSD_M1"
WITH OWNER = fadmin
ENCODING = 'UTF8'
TABLESPACE = pg_default
LC_COLLATE = 'German_Germany.1252'
LC_CTYPE = 'German_Germany.1252'
CONNECTION LIMIT = -1;
However when trying to connect thorugh the rpostgresql driver I get:
> drv <- dbDriver("PostgreSQL") ## loads the PostgreSQL driver
> con <- dbConnect(drv, port='5432', dbname='EURUSD_M1',
+ user='fadmin') ## Open a connection
Error in postgresqlNewConnection(drv, ...) :
RS-DBI driver: (could not connect fadmin#local on dbname "EURUSD_M1"
)
btw to specify host = 'localhost' does not change anything! Also fadmin is a superuser in my db!
Here are further connection information:
Any ideas what I am doing wrong?
I appreciate your answers!
RPostgreSQL, just like the psql command-line tool, connect via tcp/ip network interface even when you have the server on the same machine.
For this to work, you must enable network access; see the various PostreSQL HOWTOs and guides. You probably have to edit / alter a file call pg_hba.conf or similar.