Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Example of ASP LDAP query string? 14

Status
Not open for further replies.

MikeBronner

Programmer
May 9, 2001
756
US
Could someone post an example of ASP code used to query LDAP without any proprietary components?

Thanks! Take Care,
Mike
 
Were you every able to find something like this... it would be very helpful to me as well.

Thanks!
Michael
 
HI.

Have you got any solution to connect to LDAP server ?. I'm also looking for a code as how to connect to LDAP from ASP. Could u pls share if you got anu solution for this.

Thanks

Ahmed
 
U have not closed your connections. Try adding
Code:
con.Close
Set rs = Nothing
Set con = Nothing
in the end of your asp-files were U have conncetions.
But I have never connected to a LDAP befor so I dont know if U have to do it here :)
 
RoKKos -

Thank you for catching that error.

zcolton
 
Hi Guys,

I want to connect to my IPlanet LDAP Server using ASP. This is how I connect to the server using ColdFusion. Can somebody please show me how to QUERY the LDAP Server using ASP.

ColdFusion:
-----------

<CFLDAP
server=&quot;ldapserver&quot;
port=&quot;389&quot;
action=&quot;query&quot;
name=&quot;results&quot;
start=&quot;o=microsoft&quot;
scope=&quot;onelevel&quot;
attributes=&quot;dn&quot;
sort=&quot;ou&quot;
maxrows=&quot;100&quot;
timeout=&quot;20&quot;>

<table border=&quot;0&quot; cellspacing=2 cellpadding=2>
<cfoutput query=&quot;results&quot;>
<tr>
<td>#dn#<br></td>
</tr>
</cfoutput>
</table>

Regards,
Allan
 
This is one of my pages for my W2K Active Directory Phonebook.

<%@ Language=VBScript %>
<%
Option Explicit
Dim con,rs,Com,letter,school
%>
<html>
<head>
<style>
.over { background-color: #FFFF66; cursor: hand}
.out { background-color: #CCCCCC}
</style>
</head>
<body topmargin=&quot;0&quot; leftmargin=&quot;0&quot; bgcolor=&quot;#CCCCCC&quot; >
<%
letter = request.queryString(&quot;letter&quot;)
school = request.queryString(&quot;school&quot;)
If letter <> &quot;&quot; Then
Set con = Server.CreateObject(&quot;ADODB.Connection&quot;)
con.provider =&quot;ADsDSOObject&quot;
con.open &quot;Active Directory Provider&quot;
Set Com = CreateObject(&quot;ADODB.Command&quot;)
Set Com.ActiveConnection = con
Com.CommandText =&quot;select name, sAMAccountname from 'LDAP://hs_inst.burlington.org/OU=Staff,OU=Domain Users,DC=burlington,DC=org' WHERE objectCategory='person' AND department='&quot;+school+&quot;' AND sn='&quot;+letter+&quot;*' ORDER BY name&quot;
Set rs = Com.Execute
%>
<table border=&quot;0&quot; cellpadding=&quot;0&quot; bgcolor=&quot;#CCCCCC&quot;>
<%
Do While Not rs.EOF
%>
<tr><td onMouseOver=&quot;this.className='over'&quot; onMouseOut=&quot;this.className='out'&quot; class=&quot;out&quot; valign=&quot;middle&quot; onclick=&quot;window.open('info.asp?user=<% response.write rs(&quot;sAMAccountname&quot;)%>','InfoFrame');window.open('emailstart.htm','EmailFrame');&quot;><a><b><font color=&quot;#000080&quot; face=&quot;Verdana&quot; size=&quot;2&quot;>
<% response.write rs(&quot;Name&quot;)%></font></b></a></td>
</tr>
<%
rs.MoveNext
Loop
rs.Close
%>
</table>
<%
con.Close
Set rs = Nothing
Set con = Nothing
End If
%>
</body>
</html>
 
zcolton, thank you for the code, however I can't get it to work. If I give you my ldap server details, can you add it in your code and post it here.

LDAP Server: develLdap
Port: 389
Action: Query
Start: &quot;o=microsoft&quot;

Can you do this for me?

Regards
Allan
 
The code I posted has a few items that need to be taken into consideration. I posted a link in a post above where you can download the complete phonebook. It has a readme that has some vital info in it to get it to work on your system. What exaclty do you want the asp page to do?
 
I want my asp code to query m iPlanet LDAP directory. I showed you how ColdFusion makes call to the LDAP Server, I want to do exactly the same with ASP
 
The code I pasted above will work, you will need to modify it to match your setup.
 
Your code connect to the Active Directory Server it being a microsoft product. But I'm trying to connect to iPlanet (Sun product) using ASP.

Here is the code, it works.

<%
Set pLDAP = CreateObject(&quot;LDAPClient.3&quot;)
Call pLDAP.Connect(&quot;ldapserver&quot;,&quot;389&quot;,&quot;cn=Directory Manager&quot;, &quot;password&quot;)

Set pAttributeNames = CreateObject(&quot;LDAPClient.StringCollection&quot;)
Call pAttributeNames.Add(&quot;givenName&quot;)

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

I have downloaded the The ActiveX LDAP Client. ActiveX component is designed for accessing Lightweight Directory Access Protocol (LDAP) servers from Visual Basic and Active Server Pages applications. The LDAP Client can be used from any application that supports ActiveX components.

The licensed version of the ActiveX LDAP Client is not available for download.

Do you know if there is a ActiveX LDAP component which can be used for free to connect to LDAP

Regards,

Allan

 
i zcolton
your code give me the error:

Provider(0x80004005)
Unspecified error

Line:
Set rs = Com.Execute

Can you help me ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top