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!

QUERY ONLY A USER IN ACTIVE DIRECTORY IN ASP

Status
Not open for further replies.

fandrad

Programmer
Sep 1, 2003
3
0
0
CO
Hi Engineers!
I need your valious help... Sorry for my english is very regular but understandly..!

I'm developt an Asp script that query information about a especific user in Active Directory, this, contains differentes
OU (Organizative Units). Below see my Active Directory's tree...

Domain [localhost.local]
- DC=XXX, DC=YYY
|_OU = 1.FOODS
|_|_ _CN= Peter
|_|_ _CN= Chales
|
|_OU = 2.SALES DEPARTMENT
|_|_ _CN= Jhon
|_|_ _CN= Amsterd
|
|_OU = 3.MANAGMENT
|_|_ _CN=Alex
|_|_ _CN=XXX
|_|_ _CN=Alfred

I need to obtain the information of user "CN=Alfred" from Unit Organization "OU=3.Managment". I pass the UID or samAccountName like
parameter in the query.
I finished the asp script but the problem is very slow the query's execution for any user (Aprox. 35 seconds).
Would you tell me How Optimized it ? Or exist other way to query de active directory...?

Thanks a lot!


------------------------------------------------------------
<%
Usuario = request("usuario")
IF usuario <> "" then
Const ADS_SCOPE_SUBTREE = 2
dim objconnection
dim objcommand
dim objRecordSet
dim Name
dim mail
dim x

x=0
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
Set objCommand1 = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection


const adUseClient=3
const adOpenStatic = 3
const adLockOptimistic = 3
const adLockReadOnly = 1
const adCmdText = 1
const adFilterFetchedRecords = 3

Dim cn
dim cmd
dim rs
Dim lcConn

Dim i
Dim j

set cn = CreateObject("ADODB.Connection")
set cmd = CreateObject("ADODB.Command")
set rs = CreateObject("ADODB.RecordSet")

lcConn = "Provider=ADsDSOObject"
cn.Open lcConn

With rs
Set .ActiveConnection = cn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open "<LDAP://lucas:389>;(objectClass=organizationalPerson);CN,adspath,telephoneNumber,samAccountName" , , adOpenStatic, adLockReadOnly, adCmdText
.Filter = adFilterFetchedRecords
End With

noestanADSI = 0
For i = 0 To rs.RecordCount - 1
on error resume next

msg = empty
longitud = instr(rs.Fields("adspath"),"OU")

if longitud <> 0 then
nuevacadena = mid(rs.Fields("adspath"),longitud)
longitudNueva = instr(nuevacadena,",")
organizacion = (left(nuevacadena,longitudNueva-1))
objCommand.CommandText = "SELECT adspath, mail From 'LDAP://lucas.testing.local:389/" & organizacion & ",DC=root,DC=local' " & _
" WHERE samAccountName = '"&usuario&"' "
Set objRecordSet = objCommand.Execute

if err.number <> 0 then
msg = "Error!<br>"
exit for
else
if not objRecordSet.eof then
msg = "Field ---> " & objRecordSet.Fields("mail") & "<br>"
msg = msg & "ADSI Path ---> " & objRecordSet.Fields("adspath")
exit for
end if
end if

end if
objCommand.close
rs.close

rs.MoveNext
Next

response.write "Variable --->" & msg

END IF
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top