Simplify database connections into one method