Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

Attempting to use multiple ODBC connections across parallelized worker threads may fail as in the following example:

loaddata <- function(cn){

result <- sqlQuery(cn,'select * from boston')

return(head(result))

}

library(RODBC)

cn1 <- odbcConnect("RevoTestDB", uid='RevoTester', pwd='RevoTester')

cn2 <- odbcConnect("RevoTestDB", uid='RevoTester', pwd='RevoTester')

cn3 <- odbcConnect("RevoTestDB", uid='RevoTester', pwd='RevoTester')

cn4 <- odbcConnect("RevoTestDB", uid='RevoTester', pwd='RevoTester')

rxSetComputeContext('localpar')

system.time ({

z <- rxExec(loaddata, rxElemArg(list(cn1,cn2,cn3,cn4)), 
packagesToLoad='RODBC')

})

Error in do.call(.rxDoParFUN, as.list(args)) :

task 1 failed - "first argument is not an open RODBC channel"

The problem is the worker processes receive the ODBC connections as closed.

The issue here is that connections are process-specific, so unless the workers are sharing the parent process (as in multicore workers created via forking), the parent's connections can't be shared by the workers. To distribute ODBC computations on non-forked workers, establish the connections on each worker as part of the distributed task.

Example:

loaddata <- function(){
library(RODBC)
cn <- odbcConnect("RevoTestDB", uid='RevoTester', pwd='RevoTester')
result <- sqlQuery(cn,'select * from boston')
return(head(result))
}

z <- system.time({z <- rxExec(loaddata,
packagesToLoad='RODBC')})


Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×