Added error handling to database connection.