Try fix problem with detection of crashed agent. references #2561
Fix sql error. closes #2660