I often get a sore neck when riding. How can I adjust the setup of my bike to help prevent this happening?
I can think of a few possible explanations:


If you're sitting too upright, vibrations from the road/trail (anything from pavement quality to serious potholes) will travel straight up your spine, causing your the gaps between your vertebrae to expand and contract.  This can add up on a long ride.  Ideally you want to be leaning forward enough that your back has at least a slight arch to it so that your muscles absorb the impact instead of your spine.  Suspension (either rear or a sprung saddle/seatpost) can help here too.
If you're riding with your elbows locked, or letting your shoulders sag then again you're letting your inflexible skeleton take the shocks instead of letting your muscles do the work.
If you're leaned too far forward, then you'll constantly be craning your neck upwards to see the road ahead.  The solution here is to raise your handlebars and/or shorten the stem length.
Finally, long rides require stretching out muscles that tend to get stay in the same position all the time.  This is especially true for your upper body and neck.  Either stop to stretch or learn how to some basic stretches while riding.  If I didn't stretch my neck periodically, I'd be a mess after a 10+ hour ride!


Sheldon Brown also has some excellent tips on neck pain &amp; riding posture.