我正在对数据库运行以下查询:
execute as user = 'domain\username'
select * from fn_my_permissions(null, 'DATABASE')
order by subentity_name, permission_name
revert;
但是会抛出以下错误:
Cannot execute as the database principal because the principal "dev\spadmin" does not exist, this type of principal cannot be impersonated, or you do not have permission.
用户是数据库的 dbo,当我在 management studio 中打开属性时,我可以看到它与该登录名相关联。EXECUTE AS LOGIN = 'domain\username'
另一方面,运行确实会返回结果。如果我明确地运行EXECUTE AS USER = 'dbo'
,我会得到结果。我还有一个不同的数据库,其中相同的场景同时返回EXECUTE AS USER
和的结果EXECUTE AS LOGIN
。
在另一个用户的另一种情况下,我跑了EXECUTE AS LOGIN = 'domain\username'
但没有得到结果,但我确实得到了EXECUTE AS USER = 'domain\username'
.
这些场景中的两个用户都与db_owner
作为数据库成员的登录名相关联。
谁能告诉我为什么这些查询没有返回我期望的结果?如果我遗漏任何重要信息,请告诉我。谢谢!