Closing Database Connection
I am having some difficulty with an ASP file I'm working with. All I'm doing is searching a database for a particular user's name in the database. The page will work the first time it's run, but if I try to refresh the page, I get an error that says:
"Error Type:
Provider (0x80004005)
Unspecified error
/IMI/login.asp, line 12"
Line 12 in the login.asp is:
adoConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Inetpub\wwwroot\IMI\StudentData.mdb"
I'm pretty sure this has something to do with the connection. Anyway, here's my entire page of code:
<%@Language=VBScript%>
<%
dim fName, lName, ssn, returnVal
fName = Request.Form("FirstName")
lName = Request.Form("LastName")
ssn = Request.Form("SSN")
dim adoConn, rsStudents, strSql
Set adoConn = Server.CreateObject("ADODB.Connection")
adoConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:\Inetpub\wwwroot\IMI\StudentData.mdb"
set rsStudent = Server.CreateObject("ADODB.Recordset")
strSql = "Select * From Students Where FirstName='"&fName&"' AND LastName='"&lName&"'"
rsStudent.Open strSql, adoConn, adOpenKeyset
%>
<html>
<body>
<%
returnVal = 0
if rsStudent.EOF then
returnVal = 1
else
'We know that we have at least one record (hopefully only one)
'Set returnVal to 2 (wrong SSN) and if we find the correct SSN
'we'll reset it to 0
returnVal = 2
rsStudent.MoveFirst
While Not rsStudent.EOF
if ssn=rsStudent("SSN") then
returnVal = 0
end if
rsStudent.MoveNext
Wend
end if
%>
&Return=<%=returnVal%>
</body>
</html>
<%
adoConn.Close
Set adoConn = Nothing
%>
I thought I had everything I needed with the Close and setting the connection to Nothing. Can someone please help me figure out what I've done wrong.
Chris
|