Kenneth Fisher shows a couple common issues when executing as another user or login:
The problem is that sometimes I’ll forget to revert back.
1EXECUTE
AS
LOGIN =
'Doc'
;
Msg 15406, Level 16, State 1, Line 8
Cannot execute as the server principal because the principal “Doc” does not exist, this type of principal cannot be impersonated, or you do not have permission.Hey! I know I Doc exists, and I’m sysadmin. How is this not working? Simple enough, I forgot to REVERT. There are two simple options here. I either completely forgot to run it, or I was in the wrong database.
Read the whole thing.