471,852 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,852 software developers and data experts.

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 1142
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
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.