asp errors not displayed

五迷三道 提交于 2019-12-02 00:04:38

Oh i partially found the answer for the error display.

In the Debug pane of the IIS directory configuration, Enable ASP debugging should NOT be checked...althought i thougth it should...

have you got your browser set to "show friendly http errors" this in conjuction with what you have already identified is the common causes I've had for not seeing an error message.

Shahkaplesh is also right that you can use Server.GetLastError() to get the last error that occurred but you shouldn't need to do this in this example.

When executing a query you don't use the "Set" command. I don't know why its not showing you anything, but your code should look more like this:

<%
const database_dsn="PROVIDER=SQLNCLI10; SERVER=FR-2626\SQLLOP;DATABASE=Lop;Uid=admin-sql;Pwd=xxxx;" 

response.write("Step 0//")

set conn=server.CreateObject("ADODB.Connection")
set RS=server.CreateObject("ADODB.Recordset")

conn.Open database_dsn

response.write("Step 1//")
req = "Select count(*) From tblArticleList"

response.write("Step 2//")
RS = conn.Execute(req)

response.write("Step 3//")
%>

Yes, the parentheses on the "Response.Write" are optional. But I'm OCD like that and it makes troubleshooting a little easier.

You need to place error checking code to find out what the actual error might be. I would suggest that you change you code like so:

<%
const database_dsn="PROVIDER=SQLNCLI10; SERVER=FR-2626\SQLLOP;DATABASE=Lop;Uid=admin- sql;Pwd=xxxx;"

'Its very important to add this line!!! '
On Error Resume Next
'Its very important to add this line!!! '

response.write "Step 0//"

set conn=server.CreateObject("ADODB.Connection")
set RS=server.CreateObject("ADODB.Recordset")

conn.Open database_dsn

if err.number<>0 then
    response.write err.description
end if

response.write "Step 1//"
req = "Select count(*) From tblArticleList"

response.write "Step 2//"
set RS = conn.Execute(req)

if err.number<>0 then
    response.write err.description
end if

response.write  "Step 3//"

%>

And not to kick a dead horse but I'm doing something similar against an Oracle database and I've had two phantom problems I have yet to identify root cause but here's two things that made them go away.
1. Name all columns in a Query and Alias any that are calculated (sum, count, avg, etc.) So your query would become

req = "Select count(*) NumRows From tblArticleList"

2. Wrapping my query string in a call to cstr caused the result.EOF flag to be populated correctly rather than be returned with an empty or null value causing a simple DO WHILE NOT result.EOF Some Action LOOP to create an infinite loop until the web request timed out. So e.g.

response.write "Step 2//"
set RS = conn.Execute(cstr(req))

Nothing major just a couple tips if you get stuck and can't find out why. Follow the debugging advice above though, that's good info.

I think Server has a GetLastError method, which you can check to find out what error occurred while running any statement.

e.g. On error resume next .... statement that could cause an error.... errorObject = Server.GetLastError()

For ASPError object, refer http://www.w3schools.com/asp/asp_ref_error.asp

Actually don't mean to be disagreeable, but yes you do need a Set there, as you are setting an object type and presumably wanting to use the return value at some point (if this wasn't just a test script which it looks like to me).

Also btw parentheses are not really correct there in Response.Write() as it does not return a value. They only happen to work on single parameter subs because you can put parentheses anywhere you like around expressions.

eg:

 a = (b)
 Response.Write ((("test"))&(1))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!