There are two approaches and I think you’re mixing them together.
A constant keep-alive request. SELECT 1 sent every 30 seconds or so just to keep the connection alive.
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.
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.