OHDSI Home | Forums | Wiki | Github

Error when creating cohorts with CohortGenerator on Microsoft SQL server

Hi, I am trying to generate some cohorts on a Microsoft SQL. I am getting this error when running createCohortTables with incremental = TRUE and when running generateCohortSet.

Error in rJava::.jcall(resultSet, "Z", "next") : 
com.microsoft.sqlserver.jdbc.SQLServerException: USE statement is not supported to switch between databases. Use a new connection to connect to a different database.

The traceback shows that comes from the function DatabaseConnector::getTableNames.

> traceback()
5: stop(structure(list(message = "com.microsoft.sqlserver.jdbc.SQLServerException: USE statement is not supported to switch between databases. Use a new connection to connect to a different database.", 
       call = rJava::.jcall(resultSet, "Z", "next"), jobj = new("jobjRef", 
           jobj = <pointer: 0x000001ad266bc4e8>, jclass = "com/microsoft/sqlserver/jdbc/SQLServerException")), class = c("SQLServerException", 
   "SQLException", "Exception", "Throwable", "Object", "error", 
   "condition")))
4: .jcheck()
3: rJava::.jcall(resultSet, "Z", "next")
2: DatabaseConnector::getTableNames(connection, cohortDatabaseSchema) at #16
1: createCohortTables(connectionDetails = connectionDetails, cohortTableNames = cohortTableNames, 
       cohortDatabaseSchema = results_database_schema, incremental = TRUE)

This error is similar to Connecting to azure SQL database from achillesWeb - Developers - OHDSI Forums

t