Change a users role when executing a stored procedure

  • I wanted to see, if its possible, to change a users role in sql server from a nonsysadmin role to a sysadmin role using a command. Also, is their a way to verify this role has been changed?

  • I guess you execute a sproc that has been created using "execute as login"

    you may be able to actually perform stuff you normaly wouldn't be able to.

    create proc usp_SSC_test

    with execute as login 'aWindows\SysadminLogin'

    as

    begin

    AS

    SET NOCOUNT ON;

    SELECT USER_ID() AS [USER_ID]

    , USER_NAME() AS [USER_NAME]

    , SUSER_ID() AS [SUSER_ID]

    , SUSER_SNAME() AS [SUSER_SNAME]

    , IS_SRVROLEMEMBER ('sysadmin') AS [Is_ServerAdmin_Sysadmin]

    , IS_MEMBER('db_owner') AS [Is_DB_owner]

    , IS_MEMBER('db_ddladmin') AS [Is_DDL_Admin]

    , IS_MEMBER('db_datareader') AS [Is_DB_Datareader]

    , ORIGINAL_LOGIN() AS [ORIGINAL_LOGIN]

    end

    Grant exec usp_SSC_test to TheNormalUser;

    Now have TheNormalUser execute:

    exec usp_SSC_test

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Thanks for the quick response. I'll give it a try and let you know how it turns out.

    Eric

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

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