Is there a method for checking which roles a user has in SQL using SMO?
I can add a role via:


But cannot see an obvious method to progmatically list them.

Recommended Answers

All 2 Replies

Yes, there is EnumRoles function which returns a string collection.

Here's an example

For Each RoleName As String In user.EnumRoles()


Thanks, that explains it.
This is what I'm trying to do (add the user to a role if it's not a member:

For Each RoleName As String In user.EnumRoles()
              If RoleName <> "Administrator" Then
              End If
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.