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 SkipVought 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
0
0
US
Could someone post an example of ASP code used to query LDAP without any proprietary components?

Thanks! Take Care,
Mike
 
Z,

Is there a way to do that last query in SQL?

This is what I have, but gives me a Type mismatch or no data at all.

<%
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 Member FROM 'LDAP://CN=\#All_Management,OU=DISTLIST,DC=<my domain>,DC=ORG'"
Set rs = Com.Execute
Do While Not rs.EOF
response.write rs("Member") & ("<BR>")
rs.MoveNext
Loop
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
%>

Thanks yet again!
CN
 
CoolNutz,

Q: Is there a way to do that last query in SQL?

A: Nope

Z
 
CoolNutz:

Here's what you will need to do: (I'll get back to you with the code later)
Dump the recordset into an array. Close the recordset. The connection will no longer be needed. Right a function to sort that array. I've done it before. I have to go searching through my old code.

Z
 
i'll give it a shot, but a sample would be great.

Thanks, greatly appreciated.
YOUR A PATIENT MAN!

CN
 
CN,

Code:
<%@ Language=VBScript %>
<%
Option Explicit
response.buffer=true
Dim objGroup,objMember,groupldap,iLoop,tempstr,temparray,sortarray
%>
<html>
<head>
<script language=JScript runat=server>
    function SortVBArray(arrVBArray) {
        return arrVBArray.toArray().sort().join('\b');
    }
</script>
</head>
<body>
<%
groupldap="[b]cn=groupname,dc=domain,dc=com[/b]"
Set objGroup = GetObject ("LDAP://"&groupldap&"")
tempstr=""
For each objMember in objGroup.Members
 if tempstr<>"" then
  tempstr=tempstr&"#"
 end if
 tempstr=tempstr&objMember.CN
next
Set objGroup=nothing
temparray=split(tempstr,"#")
SortArray = Split(SortVBArray(temparray), Chr(8))
For iLoop = LBound(SortArray) to UBound(SortArray)
response.write SortArray(iLoop)%><br>
<%next%>
</body>
</html>

Z
 
Hey zColton, it is me again. We are now upgrading our entire intranet to ASP.Net. Do you have an equivalent example of your phonebook in VB.Net?
 
I have looked through this entire thread, but nothing really seems to be geared towards what I need...at least I don't think so. I am a complete newby at LDAP.

I am trying to connect to LDAP with ASP and I have ALMOST gotten it to work, but not completely. Can someone take a look at my two samples of code and give me pointers please?

---------------------------------------------
SAMPLE #1
:: Returns error "Table does not exist."

Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Open "ADs Provider", _
"uid="& UserID &",ou=unt,o=people", _
Password


str = "SELECT emplid "&_
"FROM 'LDAP://id.unt.edu:389/o=unt/ou=people' "&_
"WHERE uid = '"& UserID &"'"
Set rs = conn.Execute(str)

---------------------------------------------
SAMPLE #2
:: Returns error "The Active Directory property cannot be found in the cache."

testpath = "LDAP://id.unt.edu:389/uid="& UserID &",ou=people,o=unt"
set usr = GetObject(testpath)

usr.GetInfo

emplid = usr.Get("emplid")
response.write emplid


In sample #2, I know that the field I am requesting is only accessible to an autheticaed user, I just don't know how to pass in the password.

Aaron


 
Hi all,

This is some simple code to get your login name & email address from active directory. It took me ages to work out the code. But it uses alot less code than I used to use.

Set objSysInfo = CreateObject("ADSystemInfo")
Set adsUser = GetObject("LDAP://" & objSysInfo.username)
User=adsUser.CN
Email=adsUser.EmailAddress
Response.write User
Response.write Email
 
refering to the original question of the post...is it anyway possible to use this object with a standard LDAP server?? I would appreciate if somebody clarifies this for me because I am getting tones of different errors and don't know if its even possible to do. thanxs!
 
One that allows ldap queries. Its not Active Directory and not a domain controler, only a win2k paltform running a directory server supporting LDAP queries.
 
Code for connecting to and quering an ldap server is dependant upon the ldap server. You can use the examples here to give you a roadmap as to what to do, but you will need to do research on the ldap server you are running to make any custom changes to fit your needs.
 
It may be easier us to provide you with the help you need if you let us know what ldap server you are running.
 
Its the DC directory of Cisco CallManager. Its a propietary directory but it supports ldap queries on port 8404. I tried the following pieces of code and got different errors:

code 1:

<%
function exeQuery(queryStr) {

try
{var oConn = new ActiveXObject("ADODB.Connection");}
catch(err)
{Response.write("Err: " + err.number.toString(16) + " desc: " + err.description);}
try
{oConn.Open (cst);}
catch(err)
{Response.write("Err: " + err.number.toString(16) + " desc: " + err.description);}
try
{oConn.Execute(queryStr);}
catch(err)
{Response.write("Err: " + err.number.toString(16) + " desc: " + err.description);}

try
{oConn.Close();}
catch(err)
{Response.write("Err: " + err.number.toString(16) + " desc: " + err.description);}
}

var cst="Provider=ADSDSOObject;User ID=Directory Manager;Password=cisco;"

var str="SELECT cn FROM 'LDAP://172.17.17.115:8404/ou=Users,o=cisco.com' WHERE objectClass='ciscoocUser'";

exeQuery(str);
%>

error 1: table does not exist.

code 2:

<%
SQLStmt = "SELECT cn " & _
"FROM 'LDAP://172.17.17.115:8404/o=cisco.com/ou=Users' " & _
"WHERE objectClass='ciscoocUser'"

Set Conn = CreateObject("ADODB.Connection")
Conn.Provider = "ADSDSOObject"

Conn.Open "ADs Provider", _
"cn=Directory Manager,o=cisco.com", _
"cisco"

set rs= CreateObject("ADODB.Recordset")
rs.Open SQLStmt, Conn, 3,4,1
output=""

if rs.EOF Or rs.BOF then
Response.write("empty")
else
Response.write("non_empty" & rs.RecordCount)
rs.MoveFirst
Do
output= output & rs.Fields("cn").Value & " "
rs.MoveNext
Loop While (Not rs.EOF)

end if

If (Conn.Errors.Count > 0) Then
Response.write ("Error: " & Conn.Errors(1).Description)
End If

Response.write("output: " & output)

%>

error 2: Unspecified error, line 14

I was trying different combinations and languages :-S

 
Your best bet to find the answer would be to find a Cisco support/user forum.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top