dbTalk Databases Forums  

AMO Question to query for existence of user

microsoft.public.sqlserver.olap microsoft.public.sqlserver.olap


Discuss AMO Question to query for existence of user in the microsoft.public.sqlserver.olap forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
SteveM
 
Posts: n/a

Default AMO Question to query for existence of user - 07-27-2006 , 09:07 PM






I'm trying to test to see if a user exists in a Role via AMO. I've cut some
of the code here. How do I complete the code below to test to see if the
suserid is a member of the role?


Dim suserid as string = "domain\user"
Dim sRole as string = "myrole"
Dim oServer As New Microsoft.AnalysisServices.Server
oServer.Connect(sServer)
Dim oDatabase As Database = oServer.Databases.FindByName(sDatabase)
If oDatabase Is Nothing Then
MsgBox("Did not find expected database: " & sDatabase,
MsgBoxStyle.OkOnly, "Error looking for partition")
GoTo Done
Else
Dim oRole As Role = oDatabase.Roles.FindByName(sRole)
If Not oRole Is Nothing Then
' error processing
Else
' Check for user
???????
End If

Reply With Quote
  #2  
Old   
Darren Gosbell
 
Posts: n/a

Default Re: AMO Question to query for existence of user - 07-29-2006 , 08:28 AM






I have not compiled and tested this code, but off the top of my head the
code inside the user check would look something like the following.


' Check for user
Dim oMbr as RoleMember
For each oMbr in oRole.Members
If oMbr.Name.ToLower = suserid.ToLower Then

<User is in role>

Exit For
End If
Next oMbr


You should keep in mind the fact that if the user is part of a group and
the group is a member of the role, this code will fail as it is just
string matching on the member name. I am pretty sure .Net 2.0 exposes
some classes around AD that would let you get a strongly typed object
that would allow you to check if a user is part of a group.

--
Regards
Darren Gosbell - SQL Server MVP
Blog: http://www.geekswithblogs.net/darrengosbell

In article <4DF035EF-8122-4A11-99CE-80737B5D67CA (AT) microsoft (DOT) com>,
SteveM (AT) discussions (DOT) microsoft.com says...
Quote:
I'm trying to test to see if a user exists in a Role via AMO. I've cut some
of the code here. How do I complete the code below to test to see if the
suserid is a member of the role?


Dim suserid as string = "domain\user"
Dim sRole as string = "myrole"
Dim oServer As New Microsoft.AnalysisServices.Server
oServer.Connect(sServer)
Dim oDatabase As Database = oServer.Databases.FindByName(sDatabase)
If oDatabase Is Nothing Then
MsgBox("Did not find expected database: " & sDatabase,
MsgBoxStyle.OkOnly, "Error looking for partition")
GoTo Done
Else
Dim oRole As Role = oDatabase.Roles.FindByName(sRole)
If Not oRole Is Nothing Then
' error processing
Else
' Check for user
???????
End If




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.