I’m doing some work on ASP 3.0 and haven’t been able to get this down. ASP will correctly break (and return a 500 error) if there’s a syntax error, but if i (on purpose) write a bad sql query and then execute the query, it will just print the returned SQL error right on the HTML, instead of breaking. This would be the code (just re-wrote the sql). Also note that this is not part of a function. It’s right there on the page code.
set cn = server.createobject("ADODB.Connection")
cn.open sConn
sql= "select thiscolumndoesnotexist from table1 "
set rs01 = server.createobject("ADODB.Recordset")
rs01.Open sql, cn, 0
%>
Now, I’m sure that “On Error Resume Next” is not active, because if i break the page on ASP syntax, it will break right away. So i tried doing something like
On Error GoTo ErrorControl
code here..
ErrorControl:
Response.Status "500 You broke it"
Resume NExt
but then, the page breaks because of the On Error GoTo ErrorControl, right where “ErrorControl” started. As if it didn’t support a named error handler.
I also tried setting On Error Resume Next and then var error = Server.GetLastError(), however, it appeared as if there was no error. I think i recall reading that Server.GetLastError would only work if no output had been sent to the client (which is my case, since it’s a HTML being output, and by the time the error happens, half the document has already been sent).
Any ideas? Any help is greatly appreciated. Thanks.
Well yeah because it doesn’t.
What you need to do is turn buffering on. Either turn it on at the application level in IIS manager or use
Response.Buffer = Truebefore any content in the ASP file (static or dynamic) has been sent to the client.