Solved

HOWTO : query LDAP with ASP (not an AD)

Posted on 2014-03-10
9
839 Views
Last Modified: 2014-03-18
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
0
Comment
Question by:Sybux
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
9 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39917147
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

0
 

Author Comment

by:Sybux
ID: 39917163
It's based on AD not ldap
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39917174
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39917177
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
0
 

Author Comment

by:Sybux
ID: 39917383
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
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39917408
that would be the case if rs.Fields("sn") is returning empty/null all the time ...
you may use another field name instead of sn to get some data...
0
 

Accepted Solution

by:
Sybux earned 0 total points
ID: 39928019
Ok finally I did it.

You put me on the way. In fact, datas read in the SQL statement are presented as Array. So we can't just read the value. We have to go throw the array as for example :

myValue = rs.Fields("cn")
if isArray(myValue) then response.write myValue(0)
0
 

Author Closing Comment

by:Sybux
ID: 39936358
Team work to fine the tip
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Classic ASP application Will support SQL 2014 5 102
Help with query 3 36
Adjust an existing ASP Query 45 25
PHP encrypted string and passing to a ASP Page 12 38
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question