问题描述
当我说的有效权限,我指的是所列出的权限,当你去到SQL Server Management Studio中的数据库的属性,点击权限,然后单击有效标签。
When I say effective permissions, I'm referring to the permissions listed when you go into the properties of a database in SQL Server Management Studio, click "Permissions", and then click the "Effective" tab.
到目前为止,我已经能够确定与下面的代码明确权限:
So far, I have been able to determine the explicit permissions with the following code:
using Microsoft.SqlServer.Management.Smo;
...
DatabasePermissionInfo[] permissions = database.EnumDatabasePermissions("username");
不过,我仍然需要得到有效的权限。在这种情况下,我增加了对用户的登录名,并给它中的作用具有db_datareader
和 db_datawriter权限
为数据库,通过用户映射。
However, I still need to obtain the effective permissions. In this scenario, I added a login for a user and gave it the role of db_datareader
and db_datawriter
for a database through the User Mapping.
在数据库,列出的有效权限 CONNECT,DELETE,INSERT,SELECT,
和权限更新
,但明确权限只列出连接(这是上面的代码拉回唯一)。那么,有没有一种方法以编程方式检索的有效权限呢?
In the permissions for the database, the effective permissions listed are CONNECT, DELETE, INSERT, SELECT,
and UPDATE
, but the explicit permissions only list connect (which is the only thing that the above code pulls back). So is there a way to programmatically retrieve the effective permissions as well?
感谢。
推荐答案
我相信你可以调用的>:
I believe you can call sys.fn_my_permissions
:
execute as user = 'SomeUserName' -- Set this to the user name you wish to check
select * from fn_my_permissions(null, 'DATABASE') -- Leave these arguments, don't change to MyDatabaseName
order by subentity_name, permission_name
revert
这给了我同样的结果SSMS你所提到的选项。
This gave me the same results as the SSMS option you mentioned.
这篇关于如何确定一个SQL Server数据库,通过C#用户的有效权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!