How to do it with respect to the moment of opening / closing a connection if the program uses a database:
- open a connection, for example, when starting the program, work with the database, performing various actions on it, close the connection and close the program before closing the program
or
- start the program, then, if necessary, for example, write to the database, open a connection, make a record, close the connection, then repeat this process (opening a connection-operation-closing) to repeat if necessary
?