better error handling for database connections