473,378 Members | 1,482 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,378 software developers and data experts.

Do I need close veriables?

Hello,

I have a general question. In my asp page, I have DB connection, Recordset,
and some variables like

dim name, conn, rs
set conn = Server.CreateObject("ADODB.Connection")
....
set rs= server.createObject("ADODB.Recordset")

name = rs("username")

I know I need to close the connection like
conn.close
set conn = nothing

Do I need to close the recordset and variables? What is the reason?

Thanks,

Lin
Jul 22 '05 #1
2 1777
"Lin Ma" <a@a.com> wrote in message
news:ef**************@TK2MSFTNGP09.phx.gbl...
Hello,

I have a general question. In my asp page, I have DB connection, Recordset, and some variables like

dim name, conn, rs
set conn = Server.CreateObject("ADODB.Connection")
...
set rs= server.createObject("ADODB.Recordset")

name = rs("username")

I know I need to close the connection like
conn.close
set conn = nothing

Do I need to close the recordset and variables? What is the reason?

Thanks,

Lin

My habit is to
.Close
if I
.Open
and to
Set {object} = Nothing
if I
Set {object} = CreateObject()

The purpose if to free up resources when they're no longer needed.
Jul 22 '05 #2
Lin Ma wrote:
Hello,

I have a general question. In my asp page, I have DB connection,
Recordset, and some variables like

dim name, conn, rs
set conn = Server.CreateObject("ADODB.Connection")
...
set rs= server.createObject("ADODB.Recordset")

name = rs("username")

I know I need to close the connection like
conn.close
set conn = nothing

Do I need to close the recordset and variables? What is the reason?


Just the recordset. Unless you've disconnected the recordset by setting its
ActiveConnection property to nothing, then the recordset should be closed
before the connection is closed and destroyed, based on the general
principle that child objects should be cleaned up before their parent
objects. If the recordset is in the process of performing some sort of
activity, then the connection may not be able to close, leaving it orphaned
in your server's memory when your page goes out of scope (this is known as a
memory leak). Enough orphans, and the web server can crash.

In general, most variables are cleaned up when they go out of scope. With
ADO objects, however, it is recommended that you take control of the
process:

1. It is a good idea to close connections as soon as you are finished using
them since they consume resources both on the web server and on the database
server - the general principle is to release expensive objects as soon as
possible
2. It helps overall performance of your server to close connections as soon
as possible because doing so maximizes the usage of ADO Session Pooling,
which re-uses connections that are closed and released to the pool upon
closing. Keeping connections open unnecessarily can cause the creation of
more connections than are needed by your application

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JatP | last post by:
hi Everyone I am trying to create a server and client to send files from one side to the other. I can send files from one side to the other using bufferedinput/output streams but when trying to...
3
by: Steve | last post by:
Hi, I have a nice little script that works well displaying images on my website. It's a script where if you clik a thumbnail image a pop up window opens that contains a larger version of the same...
2
by: kevin dalby | last post by:
I use the script below to open a side panel on my desktop without all the buttons and menu items. IE 6 It works well. What I'd like to add is add a line of code that will close the calling...
6
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334,...
11
by: Karl Irvin | last post by:
My program looks like this: Dim db As DAO.Database, rst As DAO.Recordset Set db = CurrentDb Set rst = db.OpenRecordset("SELECT * FROM tUnpaidInvoiceIDs WHERE TxnType = 'Invoice'") Do some...
4
by: Paul H | last post by:
A typical chunk of code...... Set db = CurrentDb Set rs = db.OpenRecordset("tblFoo") <Do some stuff here> 'How much of the stuff below do I need? 'Do I need to close the recordset?...
5
by: Eric Layman | last post by:
Hi, Many years ago when I first learnt abt web dev in school, I was taught this methodology: <html> blah blabh
6
by: zaina | last post by:
hi everybody i am nwebie in this forum but i think it is useful for me and the member are helpful my project is about connecting client with the server to start exchanging messages between...
3
by: Eric_Dexter | last post by:
I am trying to take some data in file that looks like this command colnum_1 columnum_2 and look for the command and then cange the value in the collum(word) number indicated. I am under...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.