You must not permit your puppy to misbehave one minute and punish it the next. Don't allow him on the sofa normally and then not when you have guests in the home. This is inconsistent, unfair, and will confuse and frustrate your puppy. Rules should be clear-cut in black and white, with no gray areas in between. Timing is everything when you are training your puppy.
Puppies live in the present.
They connect good and bad things with what they are doing at the moment. If you are reprimanding him, the reprimand should interrupt his behavior and immediately direct him to a positive activity. He can't make the connection with what he did even a minute before. If you are able to catch your puppy soiling, startle him with your reprimand to interrupt him right in the middle, then take him outside, wait for him to finish there, and reward him for a job well done. Because it is so important to catch your puppy doing good and bad behaviors, your puppy should always be under your supervision.