Added sql error logging