Link to home
Start Free TrialLog in
Avatar of Sybux
SybuxFlag for Switzerland

asked on

HOWTO : query LDAP with ASP (not an AD)

Hi,

I'm looking for an example of how to read value in a LDAP server. I've googled but always found example based on AD.

Does anyone got such example ?

Thx
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

with ADO you should be able to do so?
set objADsPath as needed
Set con = Server.CreateObject("ADODB.Connection")
con.provider ="ADsDSOObject"
con.open "Active Directory Provider"
Set Com = CreateObject("ADODB.Command")
Set Com.ActiveConnection = con
Com.CommandText ="select  ... from 'GC://"+objADsPath+"' WHERE ... "
Set rs = Com.Execute

While Not rs.EOF 
  ...
  rs.MoveNext
wend

rs.Close
con.Close
Set rs = Nothing
Set con = Nothing 

Open in new window

Avatar of Sybux

ASKER

It's based on AD not ldap
AD is a directory service provider, LDAP is a protocol used to query AD and other directory service providers. The LDAP query in the article i referenced will work with AD, or any other provider - it is not an AD specific query.
ok, I think then you need to get the LDAPClient objects (http://download.cnet.com/ActiveX-LDAP-Client/3000-2206_4-10019353.html),  and :
Set pLDAP = CreateObject("LDAPClient.3")
Call pLDAP.Connect("ldapserver","389","cn=Directory Manager", "password")

Set pAttributeNames = CreateObject("LDAPClient.StringCollection")
Call pAttributeNames.Add("givenName")

' Find all the Johns and all the Smiths
Set pEntries = pLDAP.Search("o=airus", "(|(givenName=John)(sn=Smith))", , pAttributeNames)
For Each pEntry In pEntries
    Response.Write(pEntry.Attributes("givenName").Values(0).Value & "<br>")
Next 

Open in new window

hope this helps
Avatar of Sybux

ASKER

So based on your comments, I've written this :
	Set conn = Server.CreateObject("ADODB.Connection")
	conn.provider ="ADsDSOObject"
	conn.open "Active Directory Provider"
	Set objCmd = CreateObject("ADODB.Command")
	objCmd.ActiveConnection = conn
	objCmd.Properties("SearchScope") = 2
	objCmd.Properties("Page Size") = 20

	objCmd.CommandText = "select cn,mail,sn from 'LDAP://" & ldapIp & "/" & ldapDn & "'"
	response.write objCmd.commandtext & "<br>"
	Set rs = objCmd.Execute

	While Not rs.EOF 
	  response.write rs.Fields("sn")
	  response.write (".")
	  rs.MoveNext
	wend

Open in new window


It seems that the query return something as "response.write (".")" print many points on screen. But I can't get any values
SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

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
ASKER CERTIFIED SOLUTION
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
Avatar of Sybux

ASKER

Team work to fine the tip