Hello r-help!

My name is Dan McGoldrick, I am a statistical geneticist and I work with ontologies, AI and general genetic data analysis.

I was wondering aabout the tryCatch function -- don't really understand the implimentation...

What I would like to do is within an R API, test a mysql connection object for an error (server has gone away) and if the connection is functional leave it alone; otherwise, kill it if it is unattached, then refresh the connection and continue with my program executions.  I have tried making a simple dummy table with one value and something like
EnsureCon<-function(){

conMissing<-0;

mytest<-try(sql("select * from ConTest"),silent=TRUE);

if(ConTestPass(mytest[[1]])==0) {

conMissing<-1;

SentientCon<-dbConnect(MySQL(), user="root", password="mypass", host="localhost", dbname="mydatabase", port=3307);

print("attemping reconnect...")

}

else {print("connection intact")};

if (conMissing==1){

mytest<-try(sql("select * from ConTest"),silent=TRUE);

if(ConTestPass(mytest[[1]])==0) {

print("reconnect failed...check network and login details.")

# drop into a network scan process...

}}

else {print("connection re-established")};

return(SentientCon)

}

ConTestPass<-function(aconnecttest){

if(aconnecttest==1) return(1) else return(0);

}

I now have a lot of orphaned connections? because I get back

Error in mysqlNewConnection(drv, ...) : RS-DBI driver: (¸/&cannot allocate a new connection -- maximum of 16 connections already opened)


So this means I need better control over the MySQL server connections within my R API. I could execute SQL statements, and go into the system but would prefer to stay within R if I can...A function EnsureRefreshCon would be my ultimate goal. Perhaps a CleanServerConnections too?

I need some examples to get my head around this code.

So.. a long running algorithm might need to go away from MySQL and come back, but by then the connect is orphaned? 

Any pointers? (I have read the R-MySQL doc and a slide presentation by Luke Tierney...) Helpful, but I need more explanation, and someone must have had this problem before?

Peace out,

Daniel J McGoldrick Ph.D.

Sentient Solutions





	[[alternative HTML version deleted]]

