Catch error message on dbConnect failure

45 views
Skip to first unread message

Matt K

unread,
Jun 29, 2016, 1:12:55 PM6/29/16
to RPostgreSQL Development and Discussion List
When dbConnect fails, for reasons like when the Postgres connection limit is reached, the error returned does not include the error message, only:

Error in postgresqlNewConnection(drv, ...) :
RS
-DBI driver: (could not connect ...)
Calls: dbConnect -> dbConnect -> postgresqlNewConnection -> .Call
Execution halted


This comment suggests that it might be an RPostgreSQL issue, as the MySQL driver does return some error detail: http://stackoverflow.com/questions/38086738/print-dbconnect-exception-in-r#comment63612612_38086738

Wrapping the connection in a tryCatch does not provide any additional message detail, and dbGetException() requires a connection object, which of course does not exist.

Is this a limitation in the currenr RPostgreSQL error handler?

con <- tryCatch(
   
{ dbConnect(drv, host = "***", dbname = "***", user = "***") },
    error
=function(cond) {
        message
("DB conn failed")
        message
(cond)
       
return(NA)
   
}
)

Reply all
Reply to author
Forward
0 new messages