Reputation: 2376
IO got a real weird problem in my asp classic page. I am generating a schedule of days off for employees. When I tested it it seemed to work fine. Though with another option I could go a week back and forth and when I went 3 weeks back the loop keeps getting looping on one single record.
So I wanted to check where the problem was by doing a count on the recordset after the SQL execution.
For some reason though, the do while loop keeps looping. I did a print count in the do while to see how many records it finds and now it is already on 508 000 !
So in my t-sql server (2012) I did the EXACT same query and here it only results in 953 records...
So obviously tghere goes something wrong in the loop.
Here is the code I am using:
strSQL = "SELECT * FROM [qrySnipperKalender_B] WHERE [snipperdag] >= "& szStart &" AND [snipperdag]<= "& szEnd &" ORDER BY [FunctieGroep], [Relatienaam], [Datum] ASC"
response.write(strSQL & "<br> <br>")
set rst=con_sql.execute(strSQL)
CountCheck = 0
Do until rst.EOF or rst.BOF
response.write("Count is: " & CountCheck & "<br>")
CountCheck = CountCheck + 1
Loop
response.write("RST count :" & CountCheck)
response.end
The response.end and response.write RST count never get hit, it just keeps looping making the page very slow.
The response.write SQL results in: SELECT * FROM [qrySnipperKalender_B] WHERE [snipperdag] >= 15281 AND [snipperdag]<= 15355 ORDER BY [FunctieGroep], [Relatienaam], [Datum] ASC
When I run this query in the SQL server it results in 953 records (like it should).
So the question is, why is this loop broken / keeps it running?
I already tried to modify the loop with the rst.BOF (first I only had the EOF) but this doesn't have any effect. I also tried to use an IF condition inside the loop that if it hits EOF then exit the loop, but this also doesn't work.
Upvotes: 0
Views: 932
Reputation: 175766
You forgot to rst.MoveNext
within the loop to navigate to the next record
Do while not rst.EOF
CountCheck = CountCheck + 1
response.write("Count is: " & CountCheck & "<br>")
rst.MoveNext
Loop
Upvotes: 5