gpt4 book ai didi

sql-server - 服务器主体 "sa"无法在当前安全上下文下访问数据库 "model"

转载 作者:行者123 更新时间:2023-12-02 16:05:20 24 4
gpt4 key购买 nike

我创建了一个存储过程,它执行一系列需要特殊权限的操作,例如创建数据库、恢复数据库等。我使用以下命令创建此存储过程

execute as self

...以便它作为 SA 运行。这是因为我想为没有任何权限的 SQL 用户提供仅运行我定义的这些命令的能力。

但是当我运行这个存储过程时,我得到

The server principal "sa" is not able to access the database "model" under the current security context.

为什么SA无法访问模型数据库?实际上,我在 SA 下独立运行了存储过程中的代码,并且运行良好。

最佳答案

阅读Extending Database Impersonation by Using EXECUTE AS在继续之前。

when impersonating a principal by using the EXECUTE AS USER statement, or within a database-scoped module by using the EXECUTE AS clause, the scope of impersonation is restricted to the database by default. This means that references to objects outside the scope of the database will return an error.

您需要使用module signingHere就是一个例子。

关于sql-server - 服务器主体 "sa"无法在当前安全上下文下访问数据库 "model",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16212179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com