Sunan Ibn Majah, Hadith 617

It was narrated from Abu Umamah that: The Messenger of Allah forbade a man to perform prayer when he was suppressing (the urge to urinate or defecate).

حَدَّثَنَا بِشْرُ بْنُ آدَمَ، حَدَّثَنَا زَيْدُ بْنُ الْحُبَابِ، حَدَّثَنَا مُعَاوِيَةُ بْنُ صَالِحٍ، عَنِ السَّفْرِ بْنِ نُسَيْرٍ، عَنْ يَزِيدَ بْنِ شُرَيْحٍ، عَنْ أَبِي أُمَامَةَ، أَنَّ رَسُولَ اللَّهِ ـ صلى الله عليه وسلم ـ نَهَى أَنْ يُصَلِّيَ الرَّجُلُ وَهُوَ حَاقِنٌ ‏.‏

sunnah.com