Yep its a pretty common problem.
I have a unit with pushbutton switches where there is 15v across the contacts when the unit is asleep, a little moisture in the switch and the unit goes crazy!.
Basically the anode corrodes, the way to minimise this is to make the anode bigger than the cathode, so the shell of the D type should be at 5v , obviosly unworkable.
Good old telephone cables run at 50v, but they are used with positive earth, so the dirt corrodes, and the copper wire at -50v is unharmed.
With connectors the only real way to get some success is to fill the connector with silicone grease (RS sells a really thick one) . One of my products is used next to a swimming pool, and we conformally coat the PCB's and laboriously apply silicone grease to every single pin on all the connectors.
For connector presence detection , like in your application, simple capacitively couple to the sense pin (that gets shorted to ground when plugged in). If you use the "soft pullup" feature on your CPU , you can tell whether there is a capacitor present by setting the port low as an output, then make it an input, then set it "high", wait 10uS, read the pin, if its 1 there's no capacitor, if it's still 0 there is a capacitor. With a bit of programming you can distinguish between a capacitor, a 10k resistor or a short circuit. We use this method to check if a remote switch is plugged into a 10m cable, and can reliably detect which end the cable is unplugged , or localise a cut cable to about 2m , by timing how long it takes to float back up again. (It's poor mans TDR) very helpful where said cable runs through the ceiling space and down a wall cavity!