asp errors not displayed

前端 未结 7 1622
独厮守ぢ
独厮守ぢ 2021-01-21 12:31

I have moved an sql database from one server to a new one (detached/attached)

Now i experience some strange behavior as it does not work but NO error is displayed.

相关标签:
7条回答
  • 2021-01-21 12:40

    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//"
    
    %>
    
    0 讨论(0)
  • 2021-01-21 12:45

    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

    0 讨论(0)
  • 2021-01-21 12:47

    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.

    0 讨论(0)
  • 2021-01-21 12:50

    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))
    
    0 讨论(0)
  • 2021-01-21 12:55

    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.

    0 讨论(0)
  • 2021-01-21 12:59

    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.

    0 讨论(0)
提交回复
热议问题