Execute a stored procedure as another user permiss

2019-06-15 02:18发布

I faced the following problem: there's a user who has to execute a stored procedure (spTest). In spTest's body sp_trace_generateevent is called. sp_trace_generateevent requires alter trace permissions, and I don't want user to have it. So I would like user to be able to execute spTest. How can I do that?

4条回答
Bombasti
2楼-- · 2019-06-15 02:35

This is what I did (and succeeded):

let Source = Sql.Database("server", "database", 
    [Query= "EXECUTE AS USER='user' EXECUTE [schema].[spname] 'parm1', 'parm2'"])

in

Source
查看更多
\"骚年 ilove
3楼-- · 2019-06-15 02:38

As others have suggested you can achieve what you wish using the Execute As clause. For examples of implementation choices take a look at the Books Online documentation for the Execute As clause.

For further reading and to develop more understanding of this topic, what you are looking to achieve comes under the security concept of Context Switching.

查看更多
何必那么认真
4楼-- · 2019-06-15 02:51

Try this:

EXECUTE AS user = 'special_user'

EXECUTE YourProcerdure

REVERT

see these:
Understanding Context Switching <<<has examples of things like you are trying to do
Understanding Execution Context
EXECUTE AS Clause (Transact-SQL)
EXECUTE AS (Transact-SQL)

查看更多
相关推荐>>
5楼-- · 2019-06-15 02:52

When you go to execute that specific stored procedure you will need to create a different connection using the needed user credentials.

查看更多
登录 后发表回答