I've had that same problem.
I'm guess that you, like me, have no trouble getting on the Internet, on Swapnote, on the eShop, or even into online game lobbies. But once you try to actually connect to somebody? Bam: you get that error code.
I spent almost two hours on the phone with a Nintendo tech support guy, and we never figured it out. Eventually we actually gave up, I took my 3DS to my brother's house--he has a different router brand--and it worked fine. I played MK7 online to my heart's content. I forget what brand his router is, but it's different than mine.
For the record, mine is a Netgear WGT-624 V.3. It's a router issue. Get a different router.