[R] RODBC package: how to check whether connection is open

Dieter Menne dieter.menne at menne-biomed.de
Fri May 29 08:26:45 CEST 2009

Stavros Macrakis-2 wrote:
> What is the recommended way of checking whether an RODBC connection is
> open?
> Since odbcValidChannel is not exported from namespace RODBC, I suppose I
> shouldn't be using it.
> This is the best I could come up with, but it seems a bit 'dirty' to be
> using a tryCatch for something like this:
>   odbcOpenp <- function(conn)
>      tryCatch({odbcGetInfo(conn);TRUE},error=function(...)FALSE)

Directly after an open, testing for class of the channel should work. As I
understand ODDBC, there is no way of testing if the channel "is still open"
other than doing a test-read, because the other side could be connected
transatlantic. I remember an IBM memo giving an example that sends a
passthrough SQL query to the remote site.


channel = odbcConnectAccess("db.mdb")
channel = odbcClose(channel)
str(channel) # Still of class RODBC, evidently

View this message in context: http://www.nabble.com/RODBC-package%3A-how-to-check-whether-connection-is-open-tp23771854p23774853.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list