472,803 Members | 971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,803 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 1748
"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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.