all groups > inetserver asp general > february 2004 >
You're in the

inetserver asp general

group:

Closing db connection and redirecting in a loop


Closing db connection and redirecting in a loop andyza NO[at]SPAM webmail.co.za
2/29/2004 10:39:38 PM
inetserver asp general:
set RS = conn.Execute("SELECT * FROM TblName")
do while not RS.eof
if X = "Blah" then
'do something
RS.close
set RS = nothing
response.redirect "report.asp"
end if
RS.movenext
loop
RS.close
set RS = nothing
conn.close
set conn = nothing

In the above code is it necessary close the RS object and set it to
nothing before the 'response.redirect "report.asp"', or is it ok to
just close everything at the end?

The 'RS.close : set RS = nothing' code is repeated twice so that the
RS object is closed regardless of whether the condition in the If
statement is met. Is there a better way to write this so that the
'RS.close : set RS = nothing' code isn't repeated?

Should I have a response.redirect in the middle of a loop?
If the X condition in the If statement is matched then the redirect is
Re: Closing db connection and redirecting in a loop Kindler Chase
3/1/2004 12:32:45 AM
[quoted text, click to view]

You've done it correct. The object isn't closed out if you redirect since
the code never made it that far.

If you really wanted to rewrite it:

Dim blnFound : blnFound = False

set RS = conn.Execute("SELECT * FROM TblName")

do while not RS.eof
if X = "Blah" then
blnFound = True
Exit Do
RS.movenext
loop

RS.close
set RS = nothing
conn.close
set conn = nothing

If blnFound Then response.redirect "report.asp"



--

kindler chase
http://www.ncubed.com
Home of SuperInvoice's Fortress of BeanCounters

news://news.ncubed.com/support
n3 Support Group

Re: Closing db connection and redirecting in a loop Kindler Chase
3/1/2004 12:41:30 AM
[quoted text, click to view]
Sorry, forgot the end if :)

Dim blnFound : blnFound = False

set RS = conn.Execute("SELECT * FROM TblName")

Do While Not RS.eof
If X = "Blah" Then
blnFound = True
Exit Do
End If
RS.movenext
Loop

RS.close
set RS = nothing
conn.close
set conn = nothing

--

kindler chase
http://www.ncubed.com
Home of SuperInvoice's Groove Thang

news://news.ncubed.com/support
n3 Support Group

AddThis Social Bookmark Button