Opens and closes db connections manually to avoid errors when using MySQL backend