I am so sorry you baby is have this problem. Do you know how to express the anal glands? Here is a website with some good information on that:
http://www.peteducation.com/article.cfm?articleid=510
Is there swelling below and on either side of the anus? If the anal glands are impacted then they can rupture and be very painful and your dog will require antibiotics. You can wet a washcloth with warm water and apply that to the area and that will help relieve some of the pain. Please let us know how he is doing tomorrow after his vet visit. Best wishes for a speedy recovery.