[R] RODBC Connections closed automatically in background

From: Jay Z <zjay2006_at_yahoo.com>
Date: Tue 19 Sep 2006 - 22:12:19 GMT


I am having a problem with RODBC's connections. It appears that my connection to the database is closed by R automatically before I am done with it.

Here is my code:

foo <- function(dsn) {
  db <- odbcConnect(dsn)
  odbcSetAutoCommit(db, FALSE)
  data <- someDatabaseOperation(db)
  data2 <- someLongCalculation(data)
  anotherDatabaseOperation(db, data2) # This often fails b/c the db is no longer open.   odbcClose(db)
}

I see some output:

  Warning: closing unused RODBC handle 9
  Warning: [RODBC] Error SQLDisconnect
  Warning: [RODBC] Error SQLFreeconnect
  Warning: [RODBC] Error in SQLFreeEnv

  Error in odbcGetErrMsg(channel) : first argument is not an open RODBC channel

I suspect that during the call to someLongCalculation(), R considers the database connection as "unused", and therefore, closes the connection, which prevents me from using the connection in the call to anotherDatabaseOperation().

What causes the database connection to close? What can I do to prevent the connection from closing implicitly?

I am using R 2.3.1 on Windows with the latest version of RODBC, connnectin to SQL Server 2000.

Thanks in advance.



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed Sep 20 08:16:00 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 19 Sep 2006 - 22:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.