How to do it with respect to the moment of opening / closing a connection if the program uses a database:

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

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

?

  • one
    Usually do 1 - andreymal

1 answer 1

if a single-threaded application, then option 1; if multi-threaded / multiprocessing, then option 2