I think the best way to stay grounded with rejections is to remember that an agent or publication is not the end of the road. Once you have an agent, you have to overhaul the manuscript, then go on submissions, and then your agent will get rejected. Once an editor picks up your book, you'll edit the MS again, and unless you're very lucky, your book will get at least a few negative reviews, i.e. rejection by readers. There will always be something just out of your reach-- bestseller-dom, positive reviews in the New Yorker, or that award you covet.
Rejections need to be embraced as part of the process, imo. If you submit, you will get rejected. And the fact that you're accepted doesn't magically turn you into a successful published author. Turning a successful published author isn't always a gateway to happiness either, something is always out of your reach--so what I'm saying is we have to be in it for the long haul.
Take joys where we can-- when I receive a rejection on anything, I open up all the good remarks on my writing I've ever received, (we all get those, don't we, we just tend to focus on the negatives more)--and read those to myself. That usually helps.
In my case, I sent out a bunch of queries very quickly, and also networked a ton through workshops and conferences during the time I was in London. I signed up with an agent quite soon--within a month of when I started querying, re-worked my novel, got a few bites but no offers, wrote another, and am waiting for an offer on that one. I'm sure my agent is piling up the rejections as we speak. It does get miserable on some days, this waiting game, but what matters to me is getting up and writing again, telling myself that rejections are part of the process, and moving on with the writing. It never gets easy, and the writing life (as far as I know) is never one of uninterrupted joy. I'm digging into my third novel right now.
So, I guess, taking a long view of things takes the sting out of rejection. (For me, at least.)
All the best with your querying, and I hope you get your agent soon!