Fixed a bug where database connections weren't always freed

Signed-off-by: Toon Schoenmakers <nighteyes1993@gmail.com>