Better handle multiple databases if no queries were run on the last one

If the last db checked didn't have any queries, the profiler was showing no queries at all.