I am experimenting with RMySQL, and have accidentally created a connection without a handle.
dbConnect(MySQL(), user = "foo", password = "bar")
connLocalDB = dbConnect(MySQL(), user = "foo", password = "bar")
Note that the return of the first call is not assigned to anything. Now, when I do a dbListConnections(MySQL())
I see two connections:
> dbListConnections(MySQL())
[[1]]
<MySQLConnection:0,0>
[[2]]
<MySQLConnection:0,1>
I then tried this:
> dbDisconnect(dbListConnections(MySQL())[[1]])
[1] TRUE
but, then, I got this:
> dbListConnections(MySQL())
[[1]]
Error in .local(dbObj, ...) :
internal error in RS_DBI_getConnection: corrupt connection handle
How to safely terminate a connection that is not assigned a handle?
Generally for creating a connection, getting the data of a query and then closing the connection I use the following function:
getDataSql <- function( query ) {
con = dbConnect(RMySQL::MySQL(), dbname = "dbname", host = "host", user = "username", password = "pasword", port = "port")
result <- dbGetQuery(con, query)
dbDisconnect(con)
result
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With