do you have to be ovulating to get pregnant?

I've read places that yes, the only way to get pregnant is when you're ovulating, but I've also heard that to be a myth. So which one is it? Also how long does sperm live in the vagina after sex?