Jim Crozier
Jim Crozier

Reputation: 1418

Failed R instances + RODBC

Quick question: I am running multiple R instances parallel in batch mode using an RODBC connection, and randomly one (or more) of my instances is failing. If I go back and run the instances one by one, all of them are successful. There is no error in the log, and I am just trying to deduce where exactly the issue is coming from. My main hypotheses are that I am hitting a memory heap top and the instance is failing, or (more probably) there is some kind of time out happening with the RODCB connection. Any suggestions?

Thanks,

Jim

Upvotes: 1

Views: 1127

Answers (1)

David LeBauer
David LeBauer

Reputation: 31741

It is not clear why no error shows, perhaps you could try options(error = recover)

I used to get the following error when using multiple database connections:

Error in mysqlExecStatement(conn, statement, ...) : 
  RS-DBI driver: (connection with pending rows, close resultSet before continuing)

I avoid this error by issuing the following line to close any open connections before issuing a new query:

lapply(dbListConnections(MySQL()), dbDisconnect)

I took this code from the R help list.


update: one of my collaborators has created a suite of functions to facilitate database interactions, including db.con, db.open, db.close, and db.query that could be used like:

## load functions
source("https://raw.github.com/PecanProject/pecan/master/db/R/utils.R")

## example
params <- list(dbname = "mydb", username = "myname", password = "!#@?$")
con <- db.open(params)
mydata <- db.query("select * from mytable;")
db.close(con)

Upvotes: 2

Related Questions