2

I have been trying to create an error handling path for our classic asp website. I have been searching for information for 3hrs now and have not found much even here on stack overflow. So if you can point me towards a duplicate great ... I couldn't find anything although it must exist.

My plan is the following ...

  1. Have proper error handling in the stored procedures. Any errors that occur get inserted into an error table and are also raised back up to the application.
  2. Have "On error resume next" set on the page. Then check the connection.errors collection for errors. As well as Server.GetLastError() property.
  3. If there are any redirect to a page to to display safe error information and insert another record into another database table to tie the page name where the error occurred to the already existing database error in the database table mentioned above for later debugging purposes.

I have created the following page to to begin testing this out. However it is not working.

Dim cmd
Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = con
cmd.CommandType = adCmdStoredProc

on error resume next

cmd.CommandText = "spReturnDBException"
cmd.CommandTimeout = 30 ' 2 minutes
cmd.Execute


dim objErr
set objErr = Server.GetLastError()

if objError.ASPCode <> 0 then

    response.write("ASPCode=" & objErr.ASPCode)
    response.write("")
    response.write("ASPDescription=" & objErr.ASPDescription)
    response.write("")
    response.write("Category=" & objErr.Category)
    response.write("")
    response.write("Column=" & objErr.Column)
    response.write("")
    response.write("Description=" & objErr.Description)
    response.write("")
    response.write("File=" & objErr.File)
    response.write("")
    response.write("Line=" & objErr.Line)
    response.write("")
    response.write("Number=" & objErr.Number)
    response.write("")
    response.write("Source=" & objErr.Source)

else 
    response.write("There's nothing wrong.")
end if



Dim objErr2
for each objErr2 in objConn.Errors
  response.write("<p>")
  response.write("Description: ")
  response.write(objErr2.Description & "<br />")
  response.write("Help context: ")
  response.write(objErr2.HelpContext & "<br />")
  response.write("Help file: ")
  response.write(objErr2.HelpFile & "<br />")
  response.write("Native error: ")
  response.write(objErr2.NativeError & "<br />")
  response.write("Error number: ")
  response.write(objErr2.Number & "<br />")
  response.write("Error source: ")
  response.write(objErr2.Source & "<br />")
  response.write("SQL state: ")
  response.write(objErr2.SQLState & "<br />")
  response.write("</p>")
next

Free(cmd)
Free(con)

In the stored procedure I simply RAISERROR( N'Lets throw an error because I want to!', 17, 0 );

The output I get every time is as follows ...

ASPCode=ASPDescription=Category=Column=-1Description=File=Line=0Number=0Source= Description: Help context: Help file: Native error: Error number: Error source: SQL state:

Why am I not getting any error information on the conn.Errors loop?

Resolved.

I was using a different connection object for the loop that loops through the connection.Errors ... copy paste error.

However on a side note ... I found it extremely difficult to find information on how to even do what I've so far.

Kevin Donde
  • 912
  • 3
  • 15
  • 32

1 Answers1

0

here's some additional resources:

some general topics: http://social.msdn.microsoft.com/search/en-US?query=Server.GetLastError%28%29&refinement=89

a specific example: http://support.microsoft.com/kb/224070

Dee
  • 1,432
  • 1
  • 9
  • 8
  • Yeah I looked at Server.GetLastError() a little bit ... but I didn't think that it also displayed the database errors that are raised back up through the command object. If it does then that's what I need ... but does it? – Kevin Donde Dec 21 '11 at 22:08