我有一个闪亮的应用程序,它使用RPostgreSQL
. 在应用程序结束时,连接已关闭,应卸载驱动程序,但出现错误,警告我连接未关闭。
代码看起来像这样:
# in the app.R file, but not in the server function:
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname = "database1",
host = "localhost", port = 5432,
user = "user", password = "pw")
# in the server function:
foo <- dbGetQuery(con, "SELECT * from table1")
# at the end of the server function to disconnect when the app is closed:
session$onSessionEnded(function(){
dbDisconnect(con)
dbUnloadDriver(drv)
})
但是,我收到错误消息:Error in postgresqlCloseDriver(drv, ...): RS-DBI driver: (There are opened connections -- close them first)
这与 command 一起显示dbUnloadDriver(drv)
。
当我手动查找打开的连接时,dbListConnections()
我会得到一个列表,其中包含最多 16 个与数据库的打开连接。请注意,我只使用dbGetQuery
neverdbSendQuery
来避免关闭连接。
有任何想法吗?