Johannes69
Johannes69

Reputation: 51

RSQLite why and when to use disconnect

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:

  1. App starts -> dbConnect() (only once)
  2. User does stuff. Insert, read, update...
  3. App closes -> dbDisconnect() (only once)

Approach 2:

  1. App starts -> dbConnect(), read tables, dbDisconnect()

  2. User inserts or updates data -> dbConnect(), execute SQL-Query, dbDisconnect()

  3. 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

Answers (0)

Related Questions