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 :

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

Open in new window


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?
LVL 1
SteynskAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
are you sure there will always be data returned? i don't see a check for data before populating your array, i would change it to:

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
0
Prakash SamariyaIT ProfessionalCommented:
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:
....
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
....

Open in new window


You need to check with the case!
0
SteynskAuthor Commented:
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
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
ya that sounds like a timing issue.  sounds like your code is executing before is receives the full data set, try putting in the IF statement for a check on returned data and see if the error goes away. just make sure to put something in the ELSE condition to track if the code ever gets there
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteynskAuthor Commented:
Thank you Monty,

I've added the If and give it some time.

I'll get back to you next week.

Thanks
0
SteynskAuthor Commented:
Thanks again Monty
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.