It's usually used as a casual icebreaker, an easy conversation starter, but to ask a complete stranger if they have children is surely asking for trouble. I reckon it's better to stick to chatting about the weather, the food, the décor, pretty much anything else really. In some cases, politics or religion could be a safer bet than enquiring about the biological functions of someone you've just met.
I've been thrown the old "Do you have children?" line twice that I recall. Both times it was borderline awkward. The first occasion was at a wedding reception about twenty years ago. We'd no sooner introduced ourselves than the woman I was seated next to at the dinner table asked me if I had any children.
Looking back, I know she was only trying to be friendly. Unfortunately, at the time I would have been about halfway through my twenty-year campaign to remain childfree so I probably winced at the question. I guess I said: "No".
To elaborate could have been rude. I wasn't going to bore her with my rationale for not having children. Since these reasons included fear of childbirth, concern for the environment and a desire to not betray the feminist cause, it struck me as a bit deep considering entrees hadn't even been served.
Of course, now I understand that this woman must have had children and if I'd only answered: "No, do you?", I'd have given her permission to rave on about her own offspring. Lucky I didn't then.