[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

LDAP SQL question using ADsDSOObject

Posted on 2005-04-20
8
Medium Priority
?
3,813 Views
Last Modified: 2008-02-07
I need to connect to our local LDAP directory to pull data for our online directory (name, phone, dept. etc...)  I got the connection to work properly but this is all the data that I can pull, am I missing something?  By the way this is our Cisco Call Manager LDAP server.

Thanks for the help


........Here is my code:
<%
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 cn,  ADsPath FROM 'LDAP://adacm_sec:####/o=cisco.com/ou=users' "
response.Write Com.CommandText

Set rs = Com.Execute
Response.Write "<br><b>Records found:" & (rs.RecordCount)
%>
<table border="0" cellpadding="0" bgcolor="#CCCCCC" ID="Table1">
 <%
     Do While Not rs.EOF
          %>
          <tr><td><b><font face='Arial,helvetica' size='2'><% = rs.fields(0) %></b></td>
          </tr>
               
          <%
     rs.MoveNext
     Loop
     rs.Close
%>
</table>
<%
con.Close
Set rs = Nothing
Set con = Nothing

%>

.......Here is the data that is returned:
SELECT cn, name, ADsPath FROM 'LDAP://adacm_sec:####/o=cisco.com/ou=users'
Records found:1074
 LDAP://adacm_sec:####/ou=Users,o=cisco.com
LDAP://adacm_sec:####/cn=6972,ou=Users,o=cisco.com
LDAP://adacm_sec:####/cn=ac,ou=Users,o=cisco.com
LDAP://adacm_sec:####/cn=acsohelp,ou=Users,o=cisco.com
LDAP://adacm_sec:####/cn=agent1,ou=Users,o=cisco.com
LDAP://adacm_sec:####/cn=agent2,ou=Users,o=cisco.com
LDAP://adacm_sec:####/cn=asabrakd,ou=Users,o=cisco.com
LDAP://adacm_sec:####/cn=asadamma,ou=Users,o=cisco.com
LDAP://adacm_sec:####/cn=ASBATYVL,ou=Users,o=cisco.com
etc............................
0
Comment
Question by:Ada County
  • 4
  • 3
8 Comments
 
LVL 15

Expert Comment

by:Colosseo
ID: 13828896
Hi assuming the connection is working ok

try adding two extra lines below
 
         <tr><td><b><font face='Arial,helvetica' size='2'><% = rs.fields(0) %></b></td>

so you should have:

          <tr><td><b><font face='Arial,helvetica' size='2'><% = rs.fields(0) %></b></td>
          <td><b><font face='Arial,helvetica' size='2'><% = rs.fields(1) %></b></td>
          <td><b><font face='Arial,helvetica' size='2'><% = rs.fields(2) %></b></td>
          </tr>

Assuming you are using this select still: SELECT cn, name, ADsPath FROM 'LDAP://adacm_sec:####/o=cisco.com/ou=users'

Then you should be getting 3 fields back to the recordset so adding .fields(1) and .fields(2) should give you the values stored in them

HTH

Scott
0
 
LVL 6

Author Comment

by:Ada County
ID: 13829083
I tried that and now I recieve the Adspath name(SELECT cn, name, ADsPath):

LDAP://adacm_sec:####/ou=Users,o=cisco.com

And when it gets to these lines:

 <td><b><font face='Arial,helvetica' size='2'><% = rs.fields(1) %></b></td>
  <td><b><font face='Arial,helvetica' size='2'><% = rs.fields(2) %></b></td>

 I get this error:

 Provider error '80020009'

Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.

/it/ldap.asp, line 0
 
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13829367
I suspect that would be because the field is a multi-value field, right?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 6

Author Comment

by:Ada County
ID: 13829374
Im not sure
0
 
LVL 6

Author Comment

by:Ada County
ID: 13829600
I tried this thinking that it is a multivalue field and it still gives me an error: any ideas

..............................-heres my new code:
<%
Set con = Server.CreateObject("ADODB.Connection")
con.provider ="ADsDSOObject"
con.open "ADs Provider", _
          "cn=Directory Manager,o=cisco.com,ou=users", _
          "password"

Set Com = CreateObject("ADODB.Command")
Set Com.ActiveConnection = con
Com.CommandText ="SELECT  cn FROM 'LDAP://adacm_sec:####/cn=directory manager,o=cisco.com' "  & _
                         "WHERE objectClass='*' "

response.Write Com.CommandText

Set rs = Com.Execute
Response.Write "<br><b>Records found:" & (rs.RecordCount)
%>
<table border="0" cellpadding="0" bgcolor="#CCCCCC" ID="Table1">
 <%
       Do While Not rs.EOF Or rs.BOF
            ReturnValue = rs.Fields(0)
            If IsArray(ReturnValue) Then
                        For I = LBound(ReturnValue) To UBound(ReturnValue)
                              If ReturnValue(I) <> "" Then
                                    Response.Write ReturnValue(I) & "<BR>"
                              End If
                        Next
            Else
                        Response.Write ReturnValue & "<BR>"
            End If
            rs.MoveNext
      Loop

%>
</table>
<%
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing

%>

<------------------------ here is the page that is displayed

Records found:1 Provider

 error '80040e21'
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.

/it/ldap.asp, line 21
 
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 2000 total points
ID: 13830004
If you think they are multi-value fields than use something like this:


Set rs = .Execute(SQL)
With rs            
      If Not .EOF Then
            Do While Not .EOF
                  For Each fld in rs.Fields
                        Response.Write "<b>" & fld.Name & ":</b> " & GetValues(fld.Value) & "<br>"
                  Next
                  .MoveNext
                  If Not .EOF Then
                        Response.Write String(100, 45) & "<br>"
                  End If
            Loop
      Else
        Response.Write "No records found!"
      End If
      .Close
End With
Set rs = Nothing

Function GetValues(Values)
Dim Value, ValueList

If IsArray(Values) Then  ' Multi Value
      For Each Value In Values
            ValueList = ValueList & StripSchemaPath(Value) & "; "
   Next
      GetValues = Left(ValueList, Len(ValueList) - 2)
Else
      GetValues = StripSchemaPath(Values)
End If

End Function

Function StripSchemaPath(Value)
Dim BSPos

If Not IsNull(Value) Then
      BSPos = InStrRev(CStr(Value), "\")
      StripSchemaPath = Mid(Value, BSPos + 1)
Else
      StripSchemaPath = vbNullString
End If

End Function
0
 
LVL 6

Author Comment

by:Ada County
ID: 13835036
I keep getting this error no matter what I do.  I wish I could give 500,000 points for the answer to this question.  Whenever I try and display other fields besides adspath I get this error!  Do you think it has something to do with permissions on the ldap directory box?  right now I am using anonymous access.

Records found:1
Provider error '80040e21'
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.

/it/ldap.asp, line 25
 

With rs          
     If Not .EOF Then
          Do While Not .EOF
               For Each fld in rs.Fields
                    Response.Write "<b>" & fld.Name & ":</b> " & GetValues(fld.Value) & "<br>" <----Line 25
               Next
               .MoveNext
               If Not .EOF Then
                    Response.Write String(100, 45) & "<br>"
               End If
          Loop
     Else
       Response.Write "No records found!"
     End If
     .Close
End With
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13836292
>>Check each OLE DB status value, if available. <<
Add an Error Handler to your code (always a good idea) and see if the ADO Errors Collection gives you any more information.  Something like:

With rs          
     If Not .EOF Then
          Do While Not .EOF
               For Each fld in rs.Fields
                    On Error Resume Next
                    Response.Write "<b>" & fld.Name & ":</b> " & GetValues(fld.Value) & "<br>" <----Line 25
                    If Err<>0 Then
                        DisplayErrors con.Errors
                    End If
                    On Error GoTo 0
               Next
               .MoveNext
               If Not .EOF Then
                    Response.Write String(100, 45) & "<br>"
               End If
          Loop
     Else
       Response.Write "No records found!"
     End If
     .Close
End With

Sub DisplayErrors (ADOErrors)
Dim er

For Each er In ADOErrors
    Response.Write "Number:" & er.Number & "<br/>"
    Response.Write "Description :" & er.Description & "<br/>"
    Response.Write "NativeError :" & er.NativeError & "<br/>"
    Response.Write "Source:" & er.Source & "<br/>"
    Response.Write "SQLState:" & er.SQLState & "<br/>"
Next

End Sub
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

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…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

612 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