Core/DBLayer: Fixed possible crashes with async queries retrieving result

Closes #12655