Is it possible to reconnect to database table object in R

Viewed 47

Suppose I create a database connection:

con = dbConnect(dbDriver("Oracle"), 
        username = "username", 
        password = "password", 
        dbname = "dbname")

And create a lazy tibble connection to a particular table in the database:

particular_table = tbl(con, "particular_table")

After a time, a connection to database is lost. Is there any way how to re-establish the connection using a new connection (by rerunning the code for con) but with the old particular_table object? Or do I always need to re-assign the object with a new connection by running the second code again?

1 Answers

The connection is stored inside a nested list in tbl object.

You can rewrite the connection by assigning it the new con object. After that, business goes as usual.

con = dbConnect(dbDriver("Oracle"), 
        username = "username", 
        password = "password", 
        dbname = "dbname")

particular_table[["src"]][["con"]] = con
Related