RMySQL: closing a connection without a handle

I am experimenting with RMySQL and accidentally created a connection without a handle.

dbConnect(MySQL(), user = "foo", password = "bar") connLocalDB = dbConnect(MySQL(), user = "foo", password = "bar") 

Please note that returning the first call is not tied to anything. Now when I do dbListConnections(MySQL()) , I see two connections:

 > dbListConnections(MySQL()) [[1]] <MySQLConnection:0,0> [[2]] <MySQLConnection:0,1> 

Then I tried this:

 > dbDisconnect(dbListConnections(MySQL())[[1]]) [1] TRUE 

but then I got the following:

 > 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?

+6
source share
1 answer

Typically, to create a connection, receive request data and then close 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 } 
0
source

Source: https://habr.com/ru/post/984731/


All Articles