Inconsistent '80020009' error

In my classic ASP page I include a config.asp in this config.asp I’ve got script/function  that pulls some values from the Active Directory and returns them in an array.

The problem is that the error is inconstant and it only occurs occasionally and completely random. Sometimes once in ten and sometimes  ones in twenty-two times.

Another strange thing is that the error is an error mostly occurring in a data retrieval. Where it occurs in this case in a line where I’m building up my query. On this line:

SQL = "SELECT displayname,sn,givenname,mail,department FROM 'LDAP://" & SDomain &"' WHERE employeeID = '" & employeeID & "'"

Open in new window

And I’m not asking the AD LDAP anything yet in this line.
But still get this error:
error '80020009'
config.asp, line 115

It happens on two different web servers  (I’ve got only one AD).
When I  add a line 116 like:
Response.write sql 

Open in new window

I get an excellent query even when I get the error!

I use this include in almost all my files and there it works just fine.

I need to tell you I'm a bit of an amateur so feel free to advice to do things differently.
The complete code is beneath:

It all starts in my default.asp with these lines:

if isempty( rs3("afspraakbatch")) then
					response.write("<td align=""center""><a href=""#"" onClick=""requotepopup('plannen.asp?relatieID="&rs3("id")&"&sessieID="&rs3("sessieID")&"&medew="&rs3("OWpersoneelsnummer")&"','height=600,width=1300,scrollbars=yes,resizable=yes')"" Title=""Een uitnodiging versturen"" ><img src='images/agenda.png'style=""border-style: none""></a></td>")
				else
					response.write("<td align=""center""><a href=""#"" onClick=""requotepopup('plannen.asp?relatieID="&rs3("id")&"&sessieID="&rs3("sessieID")&"&medew="&rs3("OWpersoneelsnummer")&"&batchID="&rs3("afspraakbatch")&"','height=600,width=1300,scrollbars=yes,resizable=yes')"" Title=""Een uitnodiging versturen"" ><img src='images/agenda.png'style=""border-style: none""></a></td>")
				end if

Open in new window


Then this file "plannen.asp" loads:

<% Option Explicit %>
<!--#INCLUDE FILE="_header.asp"-->

<script>
	$(function() {
		$( "#datepicker" ).datepicker( {dateFormat: "yy-mm-dd", minDate: 0}, $.datepicker.regional[ "nl" ]).attr('readonly','readonly');
		$( "#locale" ).change(function() {
			$( "#datepicker" ).datepicker( "option",
				$.datepicker.regional[ $( this ).val() ] );
		});
	});
</script>
<%

SQL = "select jaargesprek_relatie.*, jaargesprek_sessies.* FROM jaargesprek_relatie inner join jaargesprek_sessies on jaargesprek_relatie.id=jaargesprek_sessies.relatieID WHERE id=" & Request.QueryString("relatieID") & " and jaargesprek_relatie.status='actief' and jaargesprek_sessies.status='actief'"

Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open SQL, cs ,3,3
if RS("LGpersoneelsnummer")=Session("employeeID") OR RS("gesprekken")=Session("employeeID") then 'als je niet één van de gesprekspartners bent dan heb je hier niets te zoeken
	dim sql, datum, van, afspraken, afspraak, myarray, medew, waarde, newtime, batchID, relatieID, sessieID, oddsevens, nogteversturen, afspraakgemaakt, query_string, i , uur, minuten, afspraaklocatie, formID
	SQL = "select * FROM jaargesprek_relatie WHERE id=" & Request.QueryString("relatieID") & " and (LGpersoneelsnummer=" & Request.QueryString("medew") & " OR OWpersoneelsnummer=" & Request.QueryString("medew") & ");"
	Set RS = Server.CreateObject("ADODB.Recordset")
	RS.Open SQL, cs ,3,3
	if rs.eof then
		response.redirect("registreer.asp?pagina="& GetPath)
	end if
	datum = Request.Form("datum")
	van = Request.Form("van")
	afspraken = false
	afspraak = now()
	SQL="SELECT jaargesprek_relatie.*, jaargesprek_sessies.*, jaargesprek_batch_afspraken.afspraaklocatie, jaargesprek_afspraakvoorstellen.* FROM (jaargesprek_sessies INNER JOIN (jaargesprek_BatchPerSessie INNER JOIN (jaargesprek_afspraakvoorstellen INNER JOIN jaargesprek_batch_afspraken ON jaargesprek_afspraakvoorstellen.batchID = jaargesprek_batch_afspraken.batchID) ON jaargesprek_BatchPerSessie.batchID = jaargesprek_batch_afspraken.batchID) ON jaargesprek_sessies.sessieID = jaargesprek_BatchPerSessie.sessieID) INNER JOIN jaargesprek_relatie ON jaargesprek_sessies.relatieID = jaargesprek_relatie.id where jaargesprek_relatie.id='"&Request.QueryString("relatieID")&"' AND jaargesprek_sessies.status='actief' AND van >= getdate() order by afspraakdatum" 
	Set RS = Server.CreateObject("ADODB.Recordset")
	RS.Open SQL, cs ,3,3
	if NOT isempty(Request.QueryString("medew")) then 'als je het personeelsnummer vanuit de URL parameters krijgt dan
		myarray = ADS(Request.QueryString("medew"))
		medew = Request.QueryString("medew")
		response.write sql
	else 'anders moet het je het kunnen verkrijgen vanuit de recordset
		if Session("employeeID") = rs("LGpersoneelsnummer") then 'en als je personeelsnummer dan overeenkomt met die van het OW dan
			myarray = ADS(rs("OWpersoneelsnummer"))
			medew = rs("OWpersoneelsnummer")
		else 'anders ben je dus de LG
			myarray = ADS(rs("LGpersoneelsnummer"))
			medew = rs("LGpersoneelsnummer")
		end if
	end if
	if not rs.eof then
		afspraak = true
		batchID=RS("batchID")
		afspraak=RS("afspraak")
		afspraaklocatie=RS("afspraaklocatie")
		formID=RS("formID")
	end if

	if(afspraak< now()) then
		gesprekspartner = ADS(rs("planning"))	
		response.write ("<p align=""center"">Deze afspraak heeft in het verleden plaatsgevonden op <br><br><font size=""4""><b> "&FormatDateTime(RS("afspraakdatum"),1)&" van "&FormatDateTime(RS("van"),4)&" tot "&FormatDateTime(RS("tot"),4)&" </font></b><br><br>Mocht deze afspraak niet hebben plaatsgevonden plan<br>dan hieronder gewoon een nieuwe afspraak in en probeer het opnieuw.</p>")& vbCrLf
	else
		response.write ("<br><br><h2  align=""center"">"& myarray( 2, 0 ) &" "& myarray( 3, 0 ) &" uitnodigen voor een jaargesprek</h2>")
		response.write ("<p  align=""center"">Selecteer hieronder uw voorkeursdata en tijd<br> die u <a href=""mailto:"& myarray( 1, 0 ) &"""> "& myarray( 2, 0 ) &"</a> wilt voorstellen als moment(en) voor het jaargesprek.<br>Druk daarna op de knop Toevoegen. Herhaal dit zo vaak als u wilt.</p>")
	end if	

	response.write ("<form method=""Post"" name=""plannen"">")& vbCrLf
	response.write ("<table border=""0"" align=""center"">")& vbCrLf

		if ((Request.QueryString("batchID")="")and(Request.Form("datum")="")) then
			waarde = ""
		else
			waarde = (Year(CDate(Request.Form("datum")))) & "-" & Month(CDate(Request.Form("datum"))) & "-" & Day(CDate(Request.Form("datum")))
		end if
		if not isempty(van) then
			response.write ("<tr><td height=""1"">datum</td><td>:</td><td><input type=""text"" value=""" & waarde & """></td></tr>")
			response.write ("<input type=""hidden"" name=""datum"" size=""15"" value=""" & waarde&""">")& vbCrLf
		else
			if Year(CDate(Request.Form("datum")) < 2015) then
				response.write("<tr><td height=""1"">datum</td><td>:</td><td><input type=""text"" id=""datepicker"" name=""datum"" size=""15""></td></tr>")
			else
				response.write("<tr><td height=""1"">datum</td><td>:</td><td><input type=""text"" id=""datepicker"" name=""datum"" value="""& waarde &""" size=""10""></td></tr>")
			end if
		end if
		response.write("<tr><td height=""1"">aanvang</td><td>:</td><td><select name=""van"" onchange=""this.form.submit();"">")& vbCrLf
		newtime = "06:45:00"
		response.write("<option value="""">Selecteer..</option>")& vbCrLf
		Do Until newtime = "23:45:00"
			newtime = DateAdd("n",15,newtime)
			if FormatDateTime(newtime,4) = van then 
				response.write("<option value=""" & FormatDateTime(newtime,4) & """ selected>"&FormatDateTime(newtime,4)&"</option>")& vbCrLf
			else
				response.write("<option value=""" & FormatDateTime(newtime,4) & """>"&FormatDateTime(newtime,4)&"</option>")& vbCrLf
			end if
		Loop
		newtime = "00:00:00"
		Do Until newtime = "06:45:00"
			newtime = DateAdd("n",15,newtime)
			if FormatDateTime(newtime,4) = van then 
				response.write("<option value=""" & FormatDateTime(newtime,4) & """ selected>"&FormatDateTime(newtime,4)&"</option>")& vbCrLf
			else
				response.write("<option value=""" & FormatDateTime(newtime,4) & """>"&FormatDateTime(newtime,4)&"</option>")& vbCrLf
			end if
		Loop
		response.write("</select></td></tr>")& vbCrLf
		response.write("</form>")& vbCrLf

		response.write ("<form method=""Post"" name=""plannen1"" action=""plannen_post.asp"">")& vbCrLf
		If ((NOT isempty(Request.QueryString("batchID"))) OR (not isempty(batchID)))Then
			if not isempty(batchID) then
				response.write ("<input type=""hidden"" name=""batchID"" value=""" & batchID&""">")& vbCrLf
				response.write ("<input type=""hidden"" name=""afspraaklocatie"" value=""" & afspraaklocatie&""">")& vbCrLf
			else
				response.write ("<input type=""hidden"" name=""batchID"" value=""" & Request.QueryString("batchID")&""">")& vbCrLf
				response.write ("<input type=""hidden"" name=""afspraaklocatie"" value="""">")& vbCrLf
				batchID = Request.QueryString("batchID")
			end if	
		end if

		if NOT isempty(Request.QueryString("relatieID")) then
			response.write ("<input type=""hidden"" name=""relatieID"" value=""" & Request.QueryString("relatieID")&""">")& vbCrLf
			response.write ("<input type=""hidden"" name=""sessieID"" value=""" & Request.QueryString("sessieID")&""">")& vbCrLf
			relatieID = Request.QueryString("relatieID")
			sessieID = Request.QueryString("sessieID")
		else
			response.write ("<input type=""hidden"" name=""relatieID"" value=""" & relatieID&""">")& vbCrLf
			response.write ("<input type=""hidden"" name=""sessieID"" value=""" & sessieID&""">")& vbCrLf
		end if

	if not isempty(van) then
			response.write ("<input type=""hidden"" name=""datum"" value=""" & datum &""">")& vbCrLf
			response.write ("<input type=""hidden"" name=""van"" style=""width:150px;"" value=""" & van &""">")& vbCrLf
			response.write("<tr><td>tot</td><td>:</td><td><select style=""width:90px;"" name=""tot"">")& vbCrLf
			i=0
			uur = hour(CDate(van))
			minuten = minute(CDate(van))
			if minuten = 0 then 
				minuten = "00"
			end if 
			Do Until uur > 18
				uur = uur+1
				if i=0 then
					response.write("<option value=""" & uur &":"& minuten & ":00"" selected>"&uur &":"& minuten&"</option>")& vbCrLf
				else
					response.write("<option value=""" & uur &":"& minuten & ":00"">"&uur &":"& minuten&"</option>")& vbCrLf
				
				end if
				i=1
			Loop
			response.write("</select><font color=""red""><- selecteer hier optioneel meerdere uren in één keer! Waardoor u meerdere opties kunt aanbieden.</font></td></tr>")
			response.write("<tr><td>Afspraak afspraaklocatie</td><td>:</td><td><input type=""text"" name=""locatie"" value="""&afspraaklocatie&""" /></td></tr>")
			SQL = "SELECT distinct formID,versie, formname from jaargesprek_productieform where nieuwste=1"
			Set RS = Server.CreateObject("ADODB.Recordset")
			RS.Open SQL, cs ,3,3
			response.write("<tr><td>Type document voor de verslaglegging</td><td>:</td>")
			response.write("<td><select required name=""formID"" class=""select"">")
				Response.write("<Option value="""">Selecteer...</Option>")
				While RS.EOF = False
					if rs("formID") = formID then
						response.write("<Option value="""&RS("formID")&"-"&RS("versie")&" selected"">" & rs("formname") & " - versie " & rs("versie") &"</option>")
					else
						response.write("<Option value="""&RS("formID")&"-"&RS("versie")&""">" & rs("formname") & " - versie " & rs("versie") &"</option>")
					end if
				RS.MoveNext 
				Wend 
				response.write("</select></td></tr>")
					
			response.write("<tr><td colspan=""3"" align=""center""><input type=""submit"" name=""submit"" class=""button"" value=""Toevoegen"" /></td></tr>")

			response.write ("</form>")
	else
			response.write("<tr><td colspan=""3"" align=""center""></td></tr>")
			'response.write ("</form>")
	end if

		
	response.write ("</table>")	
	if not rs.eof then
		response.write ("<div style="" margin-top: 10px; margin-right:  10%; margin-bottom: 0; margin-left: 10%;  padding:5px;  border:1px solid #aaa; background-color: #F5E3BD;"">")
		if ((nogteversturen=true) AND (afspraakgemaakt=false))then
			response.write ("<p align=""center"">Hieronder staan één of meerdere afspraken die u aan <a href=""mailto:"& myarray( 1, 0 ) &"""> "& myarray( 2, 0 ) &" </a> gaat aanbieden of welke u inmiddels heeft aangeboden.U kunt alleen opties verwijderen indien de deze nog niet door "& myarray( 2, 0 ) &" gezien zijn.")
		else
			response.write ("<p align=""center"">Hieronder staan één of meerdere afspraken die u aan <a href=""mailto:"& myarray( 1, 0 ) &"""> "& myarray( 2, 0 ) &" </a> heeft aangeboden. U kunt alleen opties verwijderen indien de deze nog niet door "& myarray( 2, 0 ) &" gezien zijn.")
		end if
		response.write ("<table class=""breed"" align=""center"">")
		response.write("<tr><th>datum</th><th>locatie</th><th>van</th><th>tot</th><th>aangeboden op</th><tr>")
		afspraken = true
	end if
	oddsevens = 1
	nogteversturen=false
	afspraakgemaakt=false
	Do While Not rs.EOF
		If (oddsevens MOD 2 = 0) Then 
			response.write("<tr class='odd'>")
		Else 
			response.write("<tr class='even'>")
		End If
		response.write("<td align=""right"">" & FormatDateTime(RS("afspraakdatum"),1)  & "</td>")
		if oddsevens = 1 then
			response.write("<td align=""right"">" & afspraaklocatie & "</td>")
		else
			response.write("<td align=""center""> ,,  ,,</td>")	
		end if
		response.write("<td align=""center"">" & FormatDateTime(RS("van"),4) & "</td>")
		response.write("<td align=""center"">" & FormatDateTime(RS("tot"),4) & "</td>")

		if (Len(RS("voorgesteld")&vbNullString) = 0) Then
			response.write("<td align=""center"">Nog niet verstuurd</td>")
			nogteversturen=true
		else
			response.write("<td align=""center"">" & RS("voorgesteld") & "</td>")
		end if
		
		if ((Len(RS("gezien")&vbNullString) = 0) and (Len(RS("afspraak")&vbNullString) = 0))  Then
			response.write("<td align=""center""><a href=""plannen_del.asp?relatieID=" & Request.QueryString("relatieID") &"&sessieID=" & Request.QueryString("sessieID")&"&batchID=" & batchID &"&medew=" & medew &"&afspraakID=" & rs("afspraakID") &""" Title=""Hiermee kunt u deze afspraak optie weer uit uw lijst verwijderen."" ><img src='images/delete.gif'style=""border-style: none""></a></td>")	
		else
			response.write("<td align=""center"" bgcolor=""#F5E3BD""></td>")	
		end if
		if ((Len(RS("gekozen")&vbNullString) = 0) AND (Len(RS("gezien")&vbNullString) <> 0) )Then
			response.write("<td align=""center"">Gezien op "&FormatDateTime(RS("gezien"),1)&"</td>")
		end if
		
		if (Len(RS("gekozen")&vbNullString) <> 0) Then
			afspraakgemaakt=true
			response.write("<td align=""center"">De op "& FormatDateTime(RS("gezien"),1) & " gekozen datum <a href=""Plannen_keuze_del.asp?relatieID=" & Request.QueryString("relatieID") &"&sessieID=" & Request.QueryString("sessieID")&"&batchID=" & batchID &"&medew=" & medew &"&afspraakID=" & rs("afspraakID") &""" Title=""Hiermee kunt u gekozen afspraak weer verwijderen.Tegelijker tijd stuurt de applicatie een nieuwe e-mail met het verzoek opnieuw een keuze te maken uit de overgebleven opties."" ><img src='images/delete.gif'style=""border-style: none""></a></td>")	
		else
			response.write("<td align=""center"" bgcolor=""#F5E3BD""></td>")	
		end if
		response.write("</tr>")
		oddsevens = oddsevens + 1
		
		rs.MoveNext 
	Loop

	response.write("</table>")
	response.write("</div>")
	if ((nogteversturen=true) AND (afspraakgemaakt=false))then
		response.write("<p align=""center""><input type=""submit"" name=""submit"" class=""button"" value=""Opslaan en deze voorstellen naar "& myarray( 2, 0 ) &" versturen"" /></p>")
	else
		response.write("<p align=""center""><input type=""button"" value=""Dit venster sluiten"" onclick=""window.close()""></p>")
	end if
	RS.Close
else
response.redirect ("registreer.asp?pagina="& GetPath)
end if
%>
</form>
<!--#INCLUDE FILE="_footer.asp"-->

Open in new window


In the top of the "plannen.asp" I load " _header.asp":

<!DOCTYPE HTML>
<html>
<!--#INCLUDE FILE="config.asp"-->
<head>
<title>UMCG Jaargesprekken</title>  
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">  
<script src="//code.jquery.com/jquery-1.10.2.js"></script>  
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
<script src="datepicker-nl.js"></script>
<link rel="stylesheet" href="tabber.css" TYPE="text/css" MEDIA="screen">
<script type="text/javascript">

/* Optional: Temporarily hide the "tabber" class so it does not "flash"
   on the page as plain HTML. After tabber runs, the class is changed
   to "tabberlive" and it will appear. */

document.write('<style type="text/css">.tabber{display:none;}<\/style>');

/*==================================================
  Set the tabber options (must do this before including tabber.js)
  ==================================================*/
var tabberOptions = {

  'cookie':"tabber", /* Name to use for the cookie */

  'onLoad': function(argsObj)
  {
    var t = argsObj.tabber;
    var i;

    /* Optional: Add the id of the tabber to the cookie name to allow
       for multiple tabber interfaces on the site.  If you have
       multiple tabber interfaces (even on different pages) I suggest
       setting a unique id on each one, to avoid having the cookie set
       the wrong tab.
    */
    if (t.id) {
      t.cookie = t.id + t.cookie;
    }

    /* If a cookie was previously set, restore the active tab */
    i = parseInt(getCookie(t.cookie));
    if (isNaN(i)) { return; }
    t.tabShow(i);
    /* alert('getCookie(' + t.cookie + ') = ' + i); */
  },

  'onClick':function(argsObj)
  {
    var c = argsObj.tabber.cookie;
    var i = argsObj.index;
    /* alert('setCookie(' + c + ',' + i + ')');*/ 
    setCookie(c, i);
  }
};

/*==================================================
  Cookie functions
  ==================================================*/
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

</script>
<SCRIPT LANGUAGE="javascript"> 
{ 
self.name="BODY"; 
} 
function requotepopup(lnk, size) { 
window.open(lnk, "requote",size)
} 
</SCRIPT>
<script language=JavaScript>

function Invers(){
temp = document.form1.elements.length ;
for (i=0; i < temp; i++){
if(document.form1.elements[i].checked == 1){document.form1.elements[i].checked = 0;}
else {document.form1.elements[i].checked = 1}
}
}
</script> 
<script type="text/javascript" src="tabber.js"></script>
<%
FUNCTION amDate(varDate)
    IF isNull(varDate) OR Trim(varDate) = "" OR varDate = "Null" THEN
       amDate = "Null"
    ELSE
       amDate =  Year(DateValue(varDate)) & "-" & Month(DateValue(varDate)) & "-" & Day(DateValue(varDate)) & " " & TimeValue(varDate) 
    END IF 
END FUNCTION
%>

</head>
<body>
<br>
<%
if Session("omgeving")="productie" then
response.write("<h1 align=""left"">Jaargesprekken</h1><br>")
else
response.write("<h1 align=""left"">Jaargesprekken <font color=""red"">(OTA omgeving)</font></h1><br>")
end if

%>

Open in new window

Then the _header.asp triggers the "config.asp":

<%
Session.LCID = 1043 
Response.Expires = 60
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"	

Set CS = Server.CreateObject("ADODB.Connection")

'Welke omgevingen hebben we? en waar bevinden deze bestanden zich op?
if Request.ServerVariables("server_name") = "anonomised value" then
	Session("omgeving")="productie"
	Session("filepath")="anonomised value"
	Session("ICSpath")="anonomised value"
	CS.Open "Provider=SQLOLEDB;Data Source=anonomised value; Initial Catalog=anonomised value; User ID=anonomised value; Password=anonomised value;"   ' Deze regel is veantwoordelijk voor de verbinding naar de productie database

elseif Request.ServerVariables("server_name") ="anonomised value" then
	Session("omgeving")="test"
	Session("filepath")="anonomised value"
	Session("ICSpath")="anonomised value"
	CS.Open "Provider=SQLOLEDB;Data Source=anonomised value; Initial Catalog=anonomised value; User ID=anonomised value; Password=anonomised value;"   ' Deze regel is veantwoordelijk voor de verbinding naar de test database
end if

Dim CS, RS, query, FuncADuser, FuncADpassword, admin, password, Conn, strRS, strConn, fullname, email, sLogonUser, sDomain, sLogonName, rs4, disclaimer, mail, test

FuncADuser = "anonomised value" ' functionele user die de Active Directory mag bevragen
FuncADpassword = "anonomised value" ' wachtwoord van de functionele user die de Active Directory mag bevragen
if InStr(Request.ServerVariables("AUTH_USER"),"-") then 
response.write "U bent ingelogd op een zogenaamde ""Autologon PC"" deze applicatie werk aleen als je ingelogd bent onder je eigen Windows gebruikersnaam die bestaat uit een samenvoeging van je achternaam en één of meerdere initalen"
response.end
end if

'onderstaande deel haalt naam, achternaam en e-mail even uit de active directory. 
sLogonUser = Request.ServerVariables("Logon_User")
sLogonName = lcase(trim(Mid(sLogonUser, Instr(1, sLogonUser, "\") + 1)))
Set Conn = Server.CreateObject("ADODB.Connection") 
Set RS = 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
strRS = "SELECT sn,givenname,mail,department, employeeID FROM 'LDAP://anonomised value' WHERE sAMAccountName = '"&sLogonName&"' ORDER by name " 
RS.Open strRS, Conn,1,1
While RS.EOF = False 
	Session("username")=Request.ServerVariables("Logon_User")
	Session("voornaam")=rs("givenName")
	Session("achternaam")=rs("sn")
	Session("fullname")=rs("givenName") & " " & rs("sn") 
	Session("email")=rs("mail") 
	Session("department")=rs("department") 
	if Session("achternaam")="Erich" then
	 Session("employeeID")=rs("employeeID") 
	 'Session("employeeID")="04781"
	else
		Session("employeeID")=rs("employeeID") 
	end if
RS.MoveNext 
Wend
RS.Close
Conn.close
if Session("employeeID")="" then
response.write "<H3 align=""center"">Uw account is (nog) niet gekoppeld aan een personeelsnummer!</h3>"
response.write "<p align=""center"">U bent ingelogd met een account wat nog niet gekoppeld is aan een personeelsnummer.<br>Deze applicatie vereist dat uw Windows account gekoppeld is aan uw personeelsnummer.<br>U kunt uw personeelsnummer koppelen in de ICT selfservice site.<br>U kunt deze site openen door <a href=""https://selfservice.ict.umcg.nl/MyData/Retrieve"">hier te klikken</a></p>"
 
response.end
end if

query = "SELECT * FROM jaargesprek_medewerkers WHERE personeelsnummer = " & "'" & Session("employeeID") & "';"
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open query, CS
If RS.EOF Then
	RS.Close
	Set RS = Server.CreateObject("ADODB.Recordset")
	SQL = "SELECT * FROM jaargesprek_medewerkers;"
	RS.Open SQL,CS,3,3
	RS.AddNew
	RS("personeelsnummer") = Session("employeeID")
	RS("datuminfo") = now()
	RS.update
	RS.Close
else
	if (not IsNull (rs("blacklist"))) and ((instr(Request.ServerVariables("url"),"help")=0)) then 'met uitzondering van de helpfiles geld deze blacklist lus voor alle pagina's
		response.write("<h2 align=""center"">U heeft nu niet langer toegang tot de applicatie!</h3>")
		response.write("<p align=""center"">U bent twee keer gewaarschuwd door de applicatie.<br>Tijdens de derde keer bent u door de applicatie op de blacklist geplaatst waardoor u niet langer toegang heeft tot de applicatie!</p>")
		response.write("<p align=""center"">U kunt dit mogelijk ongedaan maken indien u contact zoekt met de beheerder van het systeem.<br>U kunt dit doen via het nog steeds toegangkelijke support formulier.<br><br><a href=""help.asp"">Klik hier om het support formulier te openen</a></p>")
		response.write("<p align=""center"">Tevens zult u hierover een e-mail ontvangen!</p>")
		response.end
	end if 
	if not IsNull (RS("leidinggevende")) then
		Session("leidinggevende") = "ja"
	else
		Session("leidinggevende") = "nee"
	end if
	RS.close

end if 


function ADS(employeeID)
			FuncADuser = "anonomised value" ' functionele user die de Active Directory mag bevragen
			FuncADpassword = "anonomised value" ' wachtwoord van de functionele user die de Active Directory mag bevragen
			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
			response.write(employeeID)
			SQL = "SELECT displayname,sn,givenname,mail,department FROM 'LDAP://DC=zkh,DC=umcg,DC=intra' WHERE employeeID = '" & employeeID & "'"
			RS4.Open SQL, Conn,1,1
			if not rs4.BOF and not rs4.EOF then
				dim ADSarray 
				ADSarray = RS4.GetRows()
			end if
			ADS=ADSarray
			RS4.Close
			Conn.close
end function

function sendmail(van,cc,bcc,onderwerp,naar,bericht,attachment)
	if Session("omgeving")="test" then ' als het over de test omgeving gaat gaan we overrulen om geen iri app te worden
		naar = "anonomised value"
		cc = ""
		bcc= ""
	end if
	Set Mail = CreateObject("CDO.Message")
	'This section provides the configuration information for the remote SMTP server.
	'Send the message using the network (SMTP over the network).
	Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
	Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="anonomised value"
	Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
	'Use SSL for the connection (True or False)
	Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 
	Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
	'If your server requires outgoing authentication, uncomment the lines below and use a valid email address and password.
	'Basic (clear-text) authentication
	Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 
	'Your UserID on the SMTP server
	Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="anonomised value"
	Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="anonomised value"
	Mail.Configuration.Fields.Update
	'End of remote SMTP server configuration section
	disclaimer= "<font color=""red"" size=""1"">Indien dit bericht linken (hyperlinks) bevat dan werken deze alleen wanneer u ze opent op een UMCG werkstation!</font><br><hr><br>Dit bericht is verzonden door een applicatie. Het heeft geen zin het bericht te beantwoorden aangezien de antwoorden niet worden gelezen!"
	Mail.Subject=onderwerp
	Mail.From=van
	Mail.To=naar 		
	Mail.Cc=cc
	Mail.Bcc=bcc
	Mail.HTMLBody = bericht & disclaimer
	
	'optioneel een bijlage toevoegen
	if attachment<>"" then
	Mail.AddAttachment attachment
	end if

	Mail.Send
	Set Mail = Nothing
end function

Dim BigDay
Dim DaysRemaining
    
BigDay = DateSerial(Year(now), 12, 31) 'Year, month, day of bigday
DaysRemaining = DateDiff("d", Date, BigDay)

%>

Open in new window


Maybe someone can help me by advising a debug method to detect what is causing it.  

Kind regards,

Steynsk
LVL 1
SteynskAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

David Johnson, CD, MVPOwnerCommented:
that error normally means a null value
If isNull( myString ) Then Exit Function

2 different methods of using ldap from classic asp
http://bit.ly/1l6ee0S
https://msdn.microsoft.com/en-us/library/aa705944%28VS.85%29.aspx?f=255&MSPPError=-2147217396
SteynskAuthor Commented:
Thank you David for you response. But on the same data set it works 9 out of the 10 times. In other words I click the link in my default.asp and the page loads. But when I push the F5 function key some times it ones in the ten times shows this error.
SteynskAuthor Commented:
I solved it.

After a long search I've found out this line :

if(afspraak< now()) then

Open in new window


caused the problem. I solved it using datediff and checking if the diff > 0  

Sorry for the noise.

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:
Because I've solved my own problem
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.