Asp classic 如何正确报告/处理经典asp页面错误和数据库错误

Asp classic 如何正确报告/处理经典asp页面错误和数据库错误,asp-classic,error-handling,Asp Classic,Error Handling,我一直在尝试为我们的经典asp网站创建一个错误处理路径。我已经搜索了3小时的信息,甚至在堆栈溢出上也没有找到太多。所以如果你能给我指一个复制品的话。。。我找不到任何东西,尽管它肯定存在 我的计划如下 在存储过程中进行正确的错误处理。发生的任何错误都会被插入到错误表中,并被重新引发到应用程序中 在页面上设置“错误恢复下一步”。然后检查connection.errors集合中的错误。以及Server.GetLastError()属性 如果有任何重定向到某个页面,则显示安全的错误信息,并将另一条记录插

我一直在尝试为我们的经典asp网站创建一个错误处理路径。我已经搜索了3小时的信息,甚至在堆栈溢出上也没有找到太多。所以如果你能给我指一个复制品的话。。。我找不到任何东西,尽管它肯定存在

我的计划如下

  • 在存储过程中进行正确的错误处理。发生的任何错误都会被插入到错误表中,并被重新引发到应用程序中
  • 在页面上设置“错误恢复下一步”。然后检查connection.errors集合中的错误。以及Server.GetLastError()属性
  • 如果有任何重定向到某个页面,则显示安全的错误信息,并将另一条记录插入另一个数据库表中,以将发生错误的页面名称与上述数据库表中已存在的数据库错误联系起来,以便以后进行调试
  • 我已经创建了下面的页面来开始测试。但是它不起作用

    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)
    
    Dim cmd
    Set cmd=Server.CreateObject(“ADODB.Command”)
    cmd.ActiveConnection=con
    cmd.CommandType=adCmdStoredProc
    出错时继续下一步
    cmd.CommandText=“spReturnDBException”
    cmd.CommandTimeout=30'2分钟
    cmd.Execute
    暗淡的
    set objErr=Server.GetLastError()
    如果objError.ASPCode为0,则
    response.write(“ASPCode=“&objErr.ASPCode”)
    回答。写(“”)
    response.write(“ASPDescription=“&objErr.ASPDescription”)
    回答。写(“”)
    response.write(“Category=“&objErr.Category”)
    回答。写(“”)
    response.write(“Column=“&objErr.Column”)
    回答。写(“”)
    response.write(“Description=”&objErr.Description)
    回答。写(“”)
    response.write(“File=“&objErr.File”)
    回答。写(“”)
    response.write(“Line=“&objErr.Line”)
    回答。写(“”)
    response.write(“Number=“&objErr.Number”)
    回答。写(“”)
    response.write(“Source=“&objErr.Source”)
    其他的
    回答。写下(“没有什么问题。”)
    如果结束
    暗色objErr2
    对于objConn.Errors中的每个objErr2
    响应。写入(“”)
    响应。写入(“说明:”)
    响应.写入(objErr2.Description&“
    ”) write(“帮助上下文:”) response.write(objErr2.HelpContext&“
    ”) write(“帮助文件:”) write(objErr2.HelpFile&“
    ”) write(“本机错误:”) response.write(objErr2.NativeError&“
    ”) write(“错误号:”) 响应。写入(objErr2.Number&“
    ”) write(“错误源:”) response.write(objErr2.Source&“
    ”) write(“SQL状态:”) write(objErr2.SQLState&“
    ”) 回答。写(“

    ”) 下一个 免费(cmd) 免费(con)
    在存储过程中,我只是简单地抛出一个错误(N'let抛出一个错误,因为我想这样做!',17,0)

    我每次得到的输出如下

    ASPCode=ASPDescription=Category=Column=-1Description=File=Line=0Number=0Source= 描述:帮助上下文:帮助文件:本机错误:错误号:错误源:SQL状态:

    为什么我在conn.Errors循环中没有得到任何错误信息

    断然的。 我正在为循环使用另一个连接对象,该循环通过连接。错误。。。复制粘贴错误


    然而,另一方面。。。我发现很难找到关于如何完成迄今为止所做工作的信息。

    这里有一些额外的资源:

    一些一般性主题:

    一个具体的例子:
    这里有一些额外的资源:

    一些一般性主题:

    一个具体的例子:

    是的,我看了一下Server.GetLastError()有点。。。但我不认为它还显示了通过命令对象返回的数据库错误。如果是这样,那就是我需要的。。。是吗?是的,我看了一下Server.GetLastError()有点。。。但我不认为它还显示了通过命令对象返回的数据库错误。如果是这样,那就是我需要的。。。但这是真的吗?