A longsword is even worse than a rapier for fighting such a creature. The rapier, being a thrusting weapon, could conceivably be driven in far enough to cause injury. Slashing weapons will do about as much functional damage as keying a car.Well not perfect, just a little bit more. In the end I think we can agree that there's little chances that any weapons would be able to do real lasting damage to an ancient gargantuan dragon if things were to be realistic.
The best weapon to use on a dragon, if you don't have siege equipment handy, would be a nice long spear. Lots of stuff in Dragonlance is silly, but their choice of dragonslaying weapons was dead-on.