What is your age & sex?
Are you taking any medication?
One more question:
Is the pain felt during sex is deep or its superficial?
You need pelvic examination & other tests to know the exact cause.So I advice you to consult your gynecologist for the clinical examination to find out the root cause & then take the treatment.
Hope my answer had helped you