The Messenger of Allah ﷺ used to say, "O Allah, I seek refuge in You from a prayer that brings no benefit," and he mentioned another supplication.
حدثنا محمد بن المتوكل حدثنا المعتمر قال قال أبو المعتمر أرى أن
أن رسول الله ﷺ كان يقول اللهم إني أعوذ بك من صلاة لا تنفع وذكر دعاء آخر
[Its chain of transmission is daif] the narrator was uncertain about its chain of transmission