Fixed bug with sql error count