Improved DB error handling