473,394 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 1178
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Philips | last post by:
I'm teaching myself OOP using Michael Dawson's "Python Programming For The Absolute Beginner" and have a question about deleting objects. My game has two classes: Player and Alien, essentially...
0
by: Evin | last post by:
How can I access values from variables (global variables) from other running applications (Java Script in IE). I need to get the value using VB.NEt is it possible. B'coz the server generates...
21
by: Rabbit63 | last post by:
Hi: I want to show a set of records in the database table on the clicnt browser. I have two ways to do this (writen in JScript): 1.The first way is: <% var sql = "select firstname from...
3
by: joe martin | last post by:
Does anyone know when or if destructors for statically declared objects are called? I am just wondering if I am leaking system resources each time i exit my program. Thanks, -Joe ...
13
by: | last post by:
Hi, Why doesnt the runtime set the object to null when the finalizer has been called? Wouldnt this prevent a slew of bugs? I just called the obj.__dtor(); from a MC++ wrapper class I made and...
9
by: Aguilar, James | last post by:
Hey guys. A new question: I want to use an STL libarary to hold a bunch of objects I create. Actually, it will hold references to the objects, but that's beside the point, for the most part. ...
5
by: Alan Howard | last post by:
We're getting "ERROR (0x8007000E) Not enough storage is available to complete this operation" errors on a fairly large, busy ASP/SQL Server web site. The error is being thrown on a line calling...
7
by: puginews | last post by:
I was wondering when you create a new xmltextreader (or any other object for that matter), is it destroyed/closed (memory/resources freed) when an exception occurs ? Dim xmlrdr As New...
10
by: Jess | last post by:
Hello, I have a program that stores dynamically created objects into a vector. #include<iostream> #include<vector> using namespace std;
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.