Link to home
Start Free TrialLog in
Avatar of Gitcho
Gitcho

asked on

ASP LDAP Query

Hey all ... can't seem to pull a few attributes from AD ... this query works :  
---------------------------------------------------------------------------------------------
<LDAP://domain.com>;(&(objectCategory=person)(objectClass=user)(sAMAccountName=JSmith));sn,givenName,sAMAccountName,department,ADsPath;subtree
---------------------------------------------------------------------------------------------

... but as soon as I change the attributes and add any one of these: "description", "office", or "phone", it errors out :
---------------------------------------------------------------------------------------------
<LDAP://domain.com>;(&(objectCategory=person)(objectClass=user)(sAMAccountName=JSmith));sn,givenName,sAMAccountName,department,ADsPath,description,office,phone;subtree
---------------------------------------------------------------------------------------------

When those attributes are added, it dies at this line :
    Set objRecordSet = objCommand.Execute

What gives ? How do I pull a users description, office, or phone from LDAP ?  
Any good web links to pulling user info from AD using LDAP & ASP ?
Avatar of jmelika
jmelika

What error does it give you?

JM
Avatar of Gitcho

ASKER

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
LDAP.asp, line 134

---------------------------------------------------------------------------------------

strAttributes = "sn,description,givenName,sAMAccountName,department,ADsPath"
arrAttributes = split(strAttributes,",")
      
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
objCommand.Properties("Sort On") = "displayName"    
Set objRecordSet = objCommand.Execute
If objRecordSet.EOF Then
      'return empty if result set empty
      XMLUserData = "<?xml version='1.0' encoding='ISO-8859-1'?><root></root>"
      Exit Function
End If
XMLtext = "<?xml version='1.0' encoding='ISO-8859-1'?>" & vbNewLine
XMLtext = XMLtext & "<xml>" & vbNewLine
' Loop through results
Do Until objRecordSet.EOF
      XMLtext = XMLtext & "<user>" & vbNewLine
      For i=0 to Ubound(arrAttributes)
            XMLtext = XMLtext & "<" & arrAttributes(i) & ">" & objRecordSet.Fields(arrAttributes(i)) & "</" & arrAttributes(i) & ">" & vbNewline
      Next
      XMLtext = XMLtext & "</user>" & vbNewLine
      objRecordSet.MoveNext
Loop
XMLtext = XMLtext & "</xml>"
OK another question.  Which line is 134?

JM
Avatar of Gitcho

ASKER

oh ... sorry ...

XMLtext = XMLtext & "<" & arrAttributes(i) & ">" & objRecordSet.Fields(arrAttributes(i)) & "</" & arrAttributes(i) & ">" & vbNewline

It seems that the query executes just fine (there's no error at the "Set objRecordSet = objCommand.Execute" line), but I can't refer to the property in the variable.
Avatar of Gitcho

ASKER

i figured it out ... "description", "office", and "phone" are multi-valued items (arrays), and can't be referred to directly.
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial