Fixed bug that didn't allow the connection to the SQLite database to be closed

See issue #5228 for more details