Reputation: 51
I'm building a shiny app that connects to a SQLite database. It enables the user to see tables and update and insert data.
Now my question is whether it is better to connect once at the start of the app and disconnect once when closing it. Or everytime a query is executed (connect -> execute query -> disconnect).
Approach 1:
Approach 2:
App starts -> dbConnect(), read tables, dbDisconnect()
User inserts or updates data -> dbConnect(), execute SQL-Query, dbDisconnect()
Open DB, execute Query, Close DB repeats for every interaction with DB...
What are the benefits of each approach? Is the connection blocked for the time the connection is held open? And what how is opening and closing the DB affecting the performance?
Upvotes: 5
Views: 636