Is there a method for checking which roles a user has in SQL using SMO?
I can add a role via:
user.AddToRole("Administrators")
But cannot see an obvious method to progmatically list them.
Is there a method for checking which roles a user has in SQL using SMO?
I can add a role via:
user.AddToRole("Administrators")
But cannot see an obvious method to progmatically list them.
Yes, there is EnumRoles function which returns a string collection.
Here's an example
For Each RoleName As String In user.EnumRoles()
Console.WriteLine(RoleName)
Next
HTH
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
user.AddToRole("Administrator")
End If
Next
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.