More database connection fixes