[R] Test if mysql connection is alive

Frans Marcelissen fransiepansiekevertje at gmail.com
Thu Feb 14 14:53:18 CET 2013


Hi fellows,
I use RMySQL. I want to reconnect, if the connections is not alive anymore.

if (!connected()) con<-dbConnect(MySQL(),user=..,
                                    password=..,host=..,db=..)

But how can I do the test connected()?
I thought the way to do this was,

connected()<-function(){return (exists("con") & isIdCurrent(con))}

But that does'n work, after some time connected() returns TRUE, but the next
dbGetQuery  signals

Error in mysqlExecStatement(conn, statement, ...) : 
  RS-DBI driver: (could not run statement: MySQL server has gone away)

How can I test if the connection is still valid?

Thanks
Frans



More information about the R-help mailing list