Improved handling of database connection errors