0

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="***")
kermatt
  • 1,585
  • 2
  • 16
  • 36
  • So you were connected before this? Could you show a little more of your code? – Hack-R Jun 28 '16 at 21:41
  • Not connected before, this is this is the initial connection,in the opening stub of a new program. In this case the DB engine was configured with a limited connection pool, and the DB error was "no connections available". Would like the R script to report that so we can see from the script *why* the connection fails. – kermatt Jun 28 '16 at 21:42
  • 1
    See this excellent answer on how to use [trycatch()](http://stackoverflow.com/questions/12193779/how-to-write-trycatch-in-r) in R. Also, that may be a `RPostgreSQL` issue not giving specific info because `RMySQL` error raises: *Unknown MySQL Server Host '***'* – Parfait Jun 29 '16 at 00:09
  • @MattK if you have an ODBC name that's probably an easier way to connect. If not, validate the architecture compatibility (i.e. 32-bit DB's need 32-bit R, etc), credentials, etc. Try to login on the command line outside of R. You can probably get at the problem this way. – Hack-R Jun 29 '16 at 02:34
  • @Parfait - That is useful information. I will ping the RPostgreSQL mail list to see if this is unique to the PosrgreSQL driver. – kermatt Jun 29 '16 at 17:13

0 Answers0