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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LDAP query

Status
Not open for further replies.
Apr 27, 1999
705
US
Hello,

I hope someone will be able to help me with an LDAP query.
The code below is returning one record, but when I try to display the value of "sn", nothing is returned, but I can see it the the GUI.
Does anyone have any ideas?

Thanks in advance,
fengshui1998

CONST ADS_SERVER_BIND = &H0200
strUser = "cn=Manager,dc=myCompany,dc=com"
strPassword = "xxxxxxx"

strServer = "160.22.74.136"
strDNSDomain = "ou=mcs,dc=myCompany,dc=com"
strBase = "<LDAP://" & strServer & "/" & strDNSDomain & ">"
strFilter = "(&(objectClass=person)(cn=1111111))"

Set objNS = GetObject("LDAP:")
Set objRootDSE = objNS.OpenDSObject("LDAP://" & strServer & "/" & strDNSDomain, strUser, strPassword, ADS_SERVER_BIND)

Set oConnection = CreateObject("ADODB.Connection")
oConnection.Open "Provider=ADsDSOObject;"
Set oCommand = CreateObject("ADODB.Command")
oCommand.ActiveConnection = oConnection
oCommand.CommandText = strBase & ";" & strFilter & ";sn;subtree"
Set rs = oCommand.Execute
msgbox rs.recordcount
Do While NOT rs.eof
msgbox rs("sn")
Loop
 
what does sn designate?

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 


Geates,

"sn" stands for "surname". It is one of the fields for the results I want returned from LDAP.

Thanks
 
loop through the record set to see if sn is even returned in the record set

Code:
for each field in rs
   msgbox field & " = " & rs(field)
next

if not, we'll look elsewhere

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
could it be because the record pointer is not at the beginning and thus the do loop never run? Also, the do loop never moves the record pointer to iterate the recordset.

Try:

Code:
    Set rs = oCommand.Execute
    msgbox rs.recordcount
    [red]rs.movefirst[/red]
    Do While NOT rs.eof
       msgbox rs("sn")
       [red]rs.movenext[/red]
    Loop

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top