ASP Error Handling (conn.Open) (ADODB.Connection)

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I have an ASP file (shown below) which I call from an HTM page to query a
database table. It works correctly if I pass it the correct connection
string. I am trying to make it fail with a proper error message if I change
the UserID value in my connection string to a non-existing user (as an
example). Therefore, it should fail on the conn.Open line and give me some
sort of connection error message in Err.Description. But I get an "Operation
is not allowed when the object is closed" message which sounds like it is
coming from a line which runs after the conn.Open line. I tried commenting
everything between the conn.Open line and conn.Close line and I still receive
the same message. If I comment out the conn.Close line, the ASP file fails
all together on the xml.Send() line in the HTM page.

I tried to put an [if Err.Number <> 0 then] line right after the conn.Open
line, but the ASP file fails altogether when I do that.

Any ideas which line is producing the error message and how I can get a
proper error message from the conn.Open line?

Thanks,
Bill

-----------------------------------------------------------
// THIS IS PART OF MY WebLogin.htm FILE USING JAVASCRIPT.

var xml = new ActiveXObject("Microsoft.XMLHTTP");
xml.Open( "GET", "WebLogin.asp", false );
xml.setRequestHeader('ConnectionString', sConnect);
xml.setRequestHeader('Username', f.LogNamTbx.value);
xml.setRequestHeader('Password', f.PasswdTbx.value);
xml.setRequestHeader('TablePrefix', sTablePrefix);
xml.Send();
try {eval(xml.responseText);}
catch(e){if(e instanceof Error) {alert("Error encountered when evaluating
the [WebLogin.asp] page. Error message: " + e.message)}}

if (f.Result2.value != "")
alert("Error: " + f.Result2.value);

-----------------------------------------------------------

<%
' THIS IS MY WebLogin.asp FILE USING VBSCRIPT.

' Turn On Error Handling
On Error Resume Next

dim sUser
dim sPwd
dim conn
dim rs
dim success
dim sTblPrefix
dim sConn
dim FName
dim LName
dim sEmail
dim errormsg

errormsg = ""
success = false

sConn = Request.ServerVariables("HTTP_ConnectionString")
sUser = Request.ServerVariables("HTTP_Username")
sPwd = Request.ServerVariables("HTTP_Password")
sTblPrefix = Request.ServerVariables("HTTP_TablePrefix")

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open sConn

Set rs = conn.Execute("SELECT First_Name, Last_Name, Email, Password FROM "
& sTblPrefix & "CT_LOGON_NAMES WHERE Name = '" & sUser & "'")
if not rs.eof then
if rs("Password") = sPwd then
success = true
FName = rs("First_Name")
LName = rs("Last_Name")
sEmail = rs("Email")
end if
rs.close
end if

conn.Close
Set conn = Nothing

' Error Handler
if Err.Number <> 0 then
success = false
'errormsg = Err.Number & " - " & Err.Source & " - " & Err.Line & " - " &
Err.Description
errormsg = Err.Number & " - " & Err.Source & " - " & Err.Description
end if

%>
var ele;
ele = document.getElementById("Result");
ele.value = "<%=success%>";
ele = document.getElementById("Result2");
ele.value = "<%=errormsg%>";
ele = document.getElementById("FirstName");
ele.value = "<%=FName%>";
ele = document.getElementById("LastName");
ele.value = "<%=LName%>";
ele = document.getElementById("RequestorsEmailAddress");
ele.value = "<%=sEmail%>";

.



Relevant Pages

  • Re: error messages practically worthless
    ... the .open statement) it opens fine. ... Access itself makes the query statement. ... Dim cnnFLDCW, cnnCurPrj As ADODB.Connection ... > ways to get this error message, such as typographical errors, incorrect ...
    (microsoft.public.access.externaldata)
  • Re: Return to form if query unmatched
    ... I am getting the following error message: ... If it doesn't pop up a message and set Cancel = True. ... Dim Myrst As Recordset ... Dim MyRecCount As Long ...
    (microsoft.public.access.queries)
  • Re: Script to create subdirectories
    ... I tried it and I'm getting an error message at this line: ... Dim aFolders, newFolder ... ' Splits the various components of the folder name. ...
    (microsoft.public.windows.server.scripting)
  • RE: ODBC Driver Login Failed
    ... Further coding has revealed that this error message does not occur if I do ... Dim oCnn As ADODB.Connection ... Set oCnn = New ADODB.Connection ... 'Clean up Excel Objects ...
    (microsoft.public.access.modulesdaovba)
  • Re: Macro for Frequency Data
    ... So I decided to try your macro by deleting my first row of labels. ... "Tom Ogilvy" wrote: ... Dim rng As Range, c As Range, c1 As Range ... and I get exactly the same error message. ...
    (microsoft.public.excel.programming)