Connecting to a database with best practices