Determine SQL Server Database role

  • Hi All,

    Using SQLDMO, I want to find out the Database roles permission that a user is having. I mean if there is a database say: TEST and the user is "sa1" then when I go to Enterprise manager->SQL Server Group->Local->Security->Logins->sa1 (this is the user).

    After Rite clicking on sa1 and click the "Database Access" tab and then selecting the TEST Database, I see that the user has 'public' and 'db_owner" database roles. I want to get this (in this case I need public and db_owner)through programmatically using SQLDMO. If there is a stored procedure too, then please let me know.

    Any help\hint is much appreciated.

    Thanks In advance !

    SK

  • Sorry I cant really answer about DMO.

    In TSQL you can look at sp_helprolemember

    or try a variation of

    select DbRole = g.name, MemberName = u.name, MemberSID = u.sid

    from sysusers u, sysusers g, sysmembers m

    where g.uid = m.groupuid

    and g.issqlrole = 1

    and u.uid = m.memberuid

    order by 1, 2

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply