In Qt there are a few steps that need to be finish until a database access can be done.
The very first step is to add a database by connection name:
QSqlDatabase::addDatabase("QMYSQL", connectionName);
After this I can use open()
and close()
to open/close the corresponding connection.
That database can also be removed using the following call:
QSqlDatabase::removeDatabase(connectionName);
My application does this a lot since it accesses various databases in parallel processes for a lot of purposes. Also it is a server application that runs a very long time without being restarted.
It seems obvious to me that it is a bad idea to keep connections open all the time due possible network issues and limited connections on the server side.
However what about addDatabase()
? Is there any harm or benefit in calling addDatabase()
without calling removeDatabase()
directly after (but on application exit only)? Or is it better to directly pair these calls at all times?