469,328 Members | 1,327 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

Will these objects be closed and destroyed?

In the code below I have a Response.End in the middle of a Do loop
that is run if the condition in a nested 'If...' statement is not met.
Will the rs and conn objects be closed and destroyed if the
Response.End is called or will they be left open?

connStr = "PROVIDER=OraOLEDB.Oracle; DATA SOURCE=xyz; etc..."
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connStr

rs = Set Conn.Execute("Select A,B,C from TblTableName Where Blah =
'Blah'")
Do While Not rs.eof
If rs("A") = "Tra la la" Then
'Do something
Else
Response.Write("Some message")
Response.End
End If
Loop

'Do other stuff...

rs.Close
Set rs = nothing
conn.Close
Set conn = nothing
Jul 19 '05 #1
2 1111
NO

--
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"Luis" <an****@webmail.co.za> wrote in message
news:69**************************@posting.google.c om...
In the code below I have a Response.End in the middle of a Do loop
that is run if the condition in a nested 'If...' statement is not met.
Will the rs and conn objects be closed and destroyed if the
Response.End is called or will they be left open?

connStr = "PROVIDER=OraOLEDB.Oracle; DATA SOURCE=xyz; etc..."
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connStr

rs = Set Conn.Execute("Select A,B,C from TblTableName Where Blah =
'Blah'")
Do While Not rs.eof
If rs("A") = "Tra la la" Then
'Do something
Else
Response.Write("Some message")
Response.End
End If
Loop

'Do other stuff...

rs.Close
Set rs = nothing
conn.Close
Set conn = nothing

Jul 19 '05 #2
The theory is that objects declared and instantiated in a page will be
released by IIS when server processing of the page ends. However, you
should *never* rely on server tear-down because it may not always occur when
you think it should (this is especially true in connection pooling or
ASP.Net environments). Proper practice is to organize your code so that
every exit will always pass through an explicit cleanup routine, and make
sure that you close and release "heavy" objects like recordsets and
connections at the earliest possible opportunity.

An easy solution for the code you posted is to set a boolean variable to
false in the 'else' clause of 'if rs("A")' doesn't meet your criteria, then
frame 'do other stuff' in an "If MyBooleanSaysDoOtherStuff Then...End If".
If the condition is true, you'll execute your 'other stuff' and then fall
into the cleanup code. If it's false, you'll simply fall right into the
cleanup code.

Alan
"Luis" <an****@webmail.co.za> wrote in message
news:69**************************@posting.google.c om...
In the code below I have a Response.End in the middle of a Do loop
that is run if the condition in a nested 'If...' statement is not met.
Will the rs and conn objects be closed and destroyed if the
Response.End is called or will they be left open?

connStr = "PROVIDER=OraOLEDB.Oracle; DATA SOURCE=xyz; etc..."
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connStr

rs = Set Conn.Execute("Select A,B,C from TblTableName Where Blah =
'Blah'")
Do While Not rs.eof
If rs("A") = "Tra la la" Then
'Do something
Else
Response.Write("Some message")
Response.End
End If
Loop

'Do other stuff...

rs.Close
Set rs = nothing
conn.Close
Set conn = nothing


Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Thomas Philips | last post: by
3 posts views Thread by joe martin | last post: by
13 posts views Thread by | last post: by
9 posts views Thread by Aguilar, James | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.