EXECUTE AS and REVERT

  • Hello,

    can anyone help me understand why this happens:

    My original login id: 'DNS\original'

    EXECUTE AS LOGIN = 'DNS\other';

    select suser_sname();

    REVERT;

    select suser_sname();

    The code returns DNS\other for the first select, but it also returns the samething for the second select, shouldn't it he reverted back to 'DNS\original'? What am I missing here?

    Thank you.

  • Yes, it should revert back to your original username. This may sound like a long shot, but did you actually execute the REVERT? If you're running it one command at a time, that would cause it, but nothing else that I can see.

  • I suspect you may have impersonated the user more than once and reverted to 'DNS\other' rather than 'DNS\original'.

    Could you please try this:

    select suser_sname(); -- should return 'DNS\original'

    EXECUTE AS LOGIN = 'DNS\other';

    select suser_sname();

    REVERT;

    select suser_sname();

    If the first SELECT does not return 'DNS\original' I think you need to revert once more.

    -- Gianluca Sartori

  • Ed Wagner (11/8/2013)


    Yes, it should revert back to your original username. This may sound like a long shot, but did you actually execute the REVERT? If you're running it one command at a time, that would cause it, but nothing else that I can see.

    Hmm, if I exec the REVERT; and wait until it finishes in a sec, and then it works; if I run all the commands together, it failed, like the REVERT was skipped

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply