2012-04-03 8 views
0

私はこのメソッドを持っています。最後の行で、samAccountNameを取得しようとしたところで、私はCOM Exceptionを投げて私を狂ってしまいます。ADクエリー、サーバーが動作していません

public User FindUsername(string samAccountName, string groupDisplayName) 
     { 
      using (DirectoryEntry searchRoot = new DirectoryEntry(ldapf, ldapu, ldapp)) 
      { 
       using (DirectorySearcher searcher = new DirectorySearcher(searchRoot)) 
       {    
        searcher.Asynchronous = false; 
        searcher.PropertiesToLoad.Add("SAMAccountName"); 
        searcher.PropertiesToLoad.Add("displayName"); 
        searcher.PropertiesToLoad.Add("uSNChanged"); 
        searcher.PropertiesToLoad.Add("member"); 
        searcher.PropertiesToLoad.Add("co"); 
        searcher.PropertiesToLoad.Add("company"); 
        searcher.PropertiesToLoad.Add("mail"); 


        searcher.Filter = String.Format("(SAMAccountName={0})", samAccountName); 
        searcher.SearchScope = SearchScope.Subtree; 
        searcher.PageSize = 1000; 

        SearchResult result = searcher.FindOne(); 
        ResultPropertyCollection resultPropColl = result.Properties; 
        Object memberColl = resultPropColl["member"]; 
        using (DirectoryEntry memberEntry = new DirectoryEntry("LDAP://" + memberColl, ldapu, ldapp)) 
        { 
         try 
         { 
          System.DirectoryServices.PropertyCollection userprops = memberEntry.Properties; 
          object obVal = userprops["SAMAccountName"].Value; 
+1

例外は何ですか? –

+0

サーバーが動作していないCOMException。 –

+0

プロパティを確認し、SAMAccountNameはsAMAccountNameにする必要があります(リンク:http://msdn.microsoft.com/en-us/library/windows/desktop/ms679635(v=vs.85).aspx) – jwillmer

答えて

0

は、私がどこかに働いていた私のコードに問題があることを気づいたと私は

foreach (Object memberColl in resultPropColl["member"]) 
        { 

どうやらそれは一人のユーザ、resultPropCollを返した場合のforeachがありませんでした[「メンバー」]は、まだのコレクションですオブジェクト?

関連する問題