Basic questions for getting started with Web

There are two approaches and I think you’re mixing them together.

  1. A constant keep-alive request. SELECT 1 sent every 30 seconds or so just to keep the connection alive.
  2. A try-fail-reconnect system. Try the query. If it fails with a disconnection, reconnect and try again.

In both cases pool these connections and serve them as necessary. A new connection for every SQL query can quickly exhaust your maximum connections if your server is busy.

Is one of these options always “better” than the other or does it depend on the project which one to choose? Which of the two do you prefer?

I’ve been using Tim’s method #2 for many years with desktop and web apps. I wrap my SQL requests in a method that does this, so no extra coding for each database operation. And no extra overhead – if the user walks away from the computer for an hour and comes back, there will be only 1 extra database call. This also allows the database server to disconnect inactive sessions to manage its own resources.

1 Like