January 15, 2017 at 7:12 pm
I have created a role on my database called 'SU'.
So how can I now list all users that are assigned to this database role (just users without 'dbo' or similar) ?
January 15, 2017 at 7:50 pm
each database has a system view named sys.database_role_members, which is just ID's associated ot roles; you have to join that against database_principals to get what you are after.
you'll need something fancier if you have roles within roles, as you need to take that into account as well.
SELECT [rolz].[name] AS [RoleName] ,
[memz].[name] AS [MemberName]
FROM [sys].[database_role_members] [relz]
INNER JOIN [sys].[database_principals] [rolz] ON [relz].[role_principal_id] = [rolz].[principal_id]
INNER JOIN [sys].[database_principals] [memz] ON [relz].[member_principal_id] = [memz].[principal_id];
Lowell
January 15, 2017 at 8:24 pm
This, unfortunately,this works only if I run it on the server. If I run it from my program then I only get one entry and that is only the first record found.
January 15, 2017 at 8:39 pm
Senchi - Sunday, January 15, 2017 8:24 PMThis, unfortunately,this works only if I run it on the server. If I run it from my program then I only get one entry and that is only the first record found.
Those views are filtered. If you are sysadmin, you can see everything. If you are a normal user, you only see yourself, basically.
Lowell
January 15, 2017 at 8:58 pm
Is there a way arround ?
I need ordinary users to see who belongs in their group.
January 15, 2017 at 9:17 pm
Senchi - Sunday, January 15, 2017 8:58 PMIs there a way arround ?
I need ordinary users to see who belongs in their group.
Create a stored procedure that returns the data you want, and then grant execution rights to the groups/users that need to execute it?
January 15, 2017 at 9:40 pm
Thats what I did but it does not work.Its like Lowell said.
January 15, 2017 at 9:55 pm
Lowell - Sunday, January 15, 2017 8:39 PMSenchi - Sunday, January 15, 2017 8:24 PMThis, unfortunately,this works only if I run it on the server. If I run it from my program then I only get one entry and that is only the first record found.Those views are filtered. If you are sysadmin, you can see everything. If you are a normal user, you only see yourself, basically.
Can you cheat and use EXECUTE AS in the stored procedure to run it in a different security context?
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply