Reputation: 4832
I'm trying to write a very very simple script for a search function in a site using Classic ASP. As follows:
<%
Dim keyword, page
set Cnt=Server.CreateObject("ADODB.Connection")
keyword = Request.QueryString("s")
page = Cint(Request.QueryString("p"))
Function openDB()
DSN="Driver={SQL Server};Server=xx.xxx.xxx.xxx;Database=db_xxx;UID=xxx;PWD=xxx"
Cnt.Open(DSN)
End Function
Function closeDB()
Cnt.Close()
End Function
If (page = 0) Then
page = 1
End If
If (Trim(keyword) <> "") Then
openDB()
strSQL = "WITH OrderedResults AS (SELECT *, ROW_NUMBER() OVER (order by memorialid) as RowNumber FROM memorials WHERE bg LIKE '%2%') SELECT * FROM OrderedResults WHERE RowNumber between 1 and 5"
set rs = cnt.execute(strSQL)
While NOT rs.EOF
Response.Write(rs("name"))
Wend
closeDB()
End If
%>
The problem is, this script just keeps timing out. There are only 5 records in the table at the moment, and when I run the SQL directly in Managment Studio it brings back results in miliseconds. Can anyone help me figure out why this script takes so long.
Upvotes: 0
Views: 462
Reputation: 195972
You are missing the important rs.movenext
While NOT rs.EOF
Response.Write(rs("name"))
rs.movenext
Wend
otherwise your code never exits the loop as it keeps printing the same record..
Upvotes: 4