Steynsk
asked on
Inconsistent error on active directory retrieval
Hello Expert,
In my classic ASP application I use a function that needs one parameter. The parameter is the "employeeID". It uses the employeeID to retrieve other values from the active directory like :
The function works nine out of ten cases just fine. But occasionally it generates the following error:
and line 94 is line 13 (the line with the sql statement) in the code above.
Is there a way to prevent this error?
In my classic ASP application I use a function that needs one parameter. The parameter is the "employeeID". It uses the employeeID to retrieve other values from the active directory like :
displayname
sn(surname)
givenname
mail
department
function ADS(employeeID)
FuncADuser = "domain\username" 'anonymized
FuncADpassword = "password" ' anonymized
sDomain = "DC=abc,DC=def,DC=intra"
Set Conn = Server.CreateObject("ADODB.Connection")
Set RS4 = Server.CreateObject("ADODB.Recordset")
Conn.Provider = "ADsDSOObject"
Conn.Properties("User ID") = FuncADuser
Conn.Properties("Password") = FuncADpassword
Conn.Properties("Encrypt Password") = True
strConn = "Active Directory Provider"
Conn.Open strConn , FuncADuser, FuncADpassword
SQL = "SELECT displayname,sn,givenname,mail,department FROM 'LDAP://" & SDomain &"' WHERE employeeID = '" & employeeID & "'"
RS4.Open SQL, Conn,1,1
dim ADSarray
ADSarray = RS4.GetRows()
ADS=ADSarray
RS4.Close
end function
The function works nine out of ten cases just fine. But occasionally it generates the following error:
error '80020009'
/functions.asp, line 94
and line 94 is line 13 (the line with the sql statement) in the code above.
Is there a way to prevent this error?
There may be two reason
1. Value (employeeID) you provided to SQL statement is NULL
2. It could not find the records for employeeID!!!
Make sure your provided information does not contains case sensitive behavior!!
Couple of modified code as below:
You need to check with the case!
1. Value (employeeID) you provided to SQL statement is NULL
2. It could not find the records for employeeID!!!
Make sure your provided information does not contains case sensitive behavior!!
Couple of modified code as below:
....
IF Trim(employeeID) <> "" then
condition = "' WHERE lcase(employeeID) = '" & Trim(lcase(employeeID)) & "'"
ELSE
condition = "' WHERE [u]OTHER CONDITION TO FILTER RECORD'[/u]"
END IF
SQL = "SELECT displayname,sn,givenname,mail,department FROM 'LDAP://" & SDomain & condition
RS4.Open SQL, Conn,1,1
dim ADSarray
IF (NOT RS4.BOF) AND (NOT RS4.EOF) then
ADSarray = RS4.GetRows()
END IF
RS4.CLOSE
Conn.CLOSE
ADS=ADSarray
....
You need to check with the case!
ASKER
Thank you both for your quick and very constructive comments. I will implement your suggestions but I have some doubts about them.
When I get the error and I push F5 to reload the page response is always correctly. I'm more thinking about a timeout or something like that. Could I make the page sleep 2 sec and then ask the database again?
Kind regards,
Steynsk
When I get the error and I push F5 to reload the page response is always correctly. I'm more thinking about a timeout or something like that. Could I make the page sleep 2 sec and then ask the database again?
Kind regards,
Steynsk
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Monty,
I've added the If and give it some time.
I'll get back to you next week.
Thanks
I've added the If and give it some time.
I'll get back to you next week.
Thanks
ASKER
Thanks again Monty
RS4.Open SQL, Conn,1,1
if not rs4.BOF and not rs4.EOF then
dim ADSarray
ADSarray = RS4.GetRows()
else
'-- handle a no data scenario
end if