Moved SQL error handling to errorHandler