2012-06-09 2 views
3

도움이 필요합니다. 고전 ASP에서 데이터베이스에 연결할 때 일정한 빈 페이지가 나타납니다. 보안상의 이유로 일부 연결 문자열을 변경했습니다. 나는이 문자열이 vb.net에서 연결할 수 있기 때문에 작동한다는 것을 알고있다.SQL 서버에 연결할 때 빈 페이지 - 클래식 ASP

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Search Test</title> 
</head> 

<body> 
<% 
Set Conn = Server.CreateObject("ADODB.Connection") 
Conn.Open "Data Source=ServerIP;Initial Catalog=Database;User ID=Username;Password=Password" 

strSql = "SELECT * FROM categories Where idParentcategory=1 ORDER BY categorydesc ASC" 

Set rs = Conn.Execute(strSql) 

If rs.eof Then 
    Response.write("No records returned") 
End If 

do until rs.eof 
    Response.write(rs("categorydesc") & "<br>") 
    rs.movenext 
loop 

Conn.Close 
Set Conn = Nothing 
%> 
</body> 
</html> 

답변

1

를가 빈 페이지를 보여주는 있다면, 그것은 당신이 on error resume next 우리가 볼 수없는 한 가능하다 (어쩌면 그것은 파일을 포함에있어)?

나는 eof을 확인한 다음 인 경우에만 결과 세트를 루핑하여 처리 할 것입니다. 당신은 빈 페이지가 오는 이유를 확인 할 수 있어야한다

  1. :

    Set rs = Conn.Execute(strSql) 
    
    If rs.eof Then 
        Response.write("No records returned") 
    Else 
        do until rs.eof 
        Response.write(rs("categorydesc") & "<br>") 
        rs.movenext 
        loop 
    End If 
    
    rs.Close : set rs = nothing 
    Conn.Close : set Conn = Nothing 
    

    이 제외 03Usr의 대답 @에서 정말 다르지 않다.

  2. 연결 개체를 닫고 처리하는 것 외에도 실제로는 레코드 집합 개체를 닫고 처리해야합니다 (비어있는 경우에도 마찬가지입니다).
0

이 시도 :

If not rs.eof then 
Do while not rs.eof or rs.bof 
     Response.write(rs("categorydesc") & "<br>") 
    rs.movenext 
    Loop 
Else 
     Response.Write "No records found" 
End If