Fixed database access - returns appropriate errors