added error log with sql