2012-04-03 3 views
0

그래서이 방법을 사용하고 마지막 줄에서 samAccountName을 얻으려는 곳에서 저에게 COM 예외를 던져서 저를 미쳤습니다.광고 쿼리, 서버가 작동하지 않습니다.

아이디어가 있으십니까?

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는 누락 된 [ "회원"] 아직도의 모음입니다 사물?

관련 문제