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

Closing objects correctly

83
Hi,

I believe this si the approved method for getting data out of a db in sql server ie. open connection, open obj, close obj, close connection

openDataConnection()
set rsID = CreateObject("ADODB.recordset")
rsID.Open " SELECT * from t_example, strConn
set newObj = rsID
rsID.close
set rsID = nothing
closeDataConnection()

By setting rsID = nothing i believe i am freeing up webserver resources correctly.

However, what happens to newObj, do i need to set that to nothing somewhere. If is is left open will the dataconnection have closed properly ?

Thanks,

Tim
Apr 7 '08 #1
2 1153
jeffstl
432 Expert 256MB
Hi,

I believe this si the approved method for getting data out of a db in sql server ie. open connection, open obj, close obj, close connection

openDataConnection()
set rsID = CreateObject("ADODB.recordset")
rsID.Open " SELECT * from t_example, strConn
set newObj = rsID
rsID.close
set rsID = nothing
closeDataConnection()

By setting rsID = nothing i believe i am freeing up webserver resources correctly.

However, what happens to newObj, do i need to set that to nothing somewhere. If is is left open will the dataconnection have closed properly ?

Thanks,

Tim
As long as you close your record set and your connection which you have done you do not need to remove Objects from memory also.

The only reason you would want to clear an object from memory is if you planned to re-use it on another page, or process where it may be re-populated or re-dimmed to hold new data.

In fact the beauty of the objects is that you can open your connection, your RS, populate your object, then close your RS and connection, then from that point forward you only need to work with the object instead of constantly connecting to the DB over and over.
Apr 7 '08 #2
TimSki
83
great, many thanks for clarifying this for me.
Apr 9 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: James | last post by:
Quick question about closing recordsets and connection objects. We're in the process of rewriting a TON of bad code. None of it is even remotely tabbed properly, it's impossible to read half the...
1
by: Ryan | last post by:
Hi, I am hoping somebody can provide a clear picture on this topic. When is it necessary to specifically close and/or set an object (recordset, database, variable, etc.)to nothing and what is...
13
by: Simon Harvey | last post by:
Hi All, I have a colleague that I wprk with that develops using ASP. I develop using ASP.net. He seems to make sites much faster than me and I am wondering if its because of the two different...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
7
by: rdemyan via AccessMonster.com | last post by:
I want to make sure that I'm closing an opened spreadsheet correctly. I've been having some locking up problems. The following code adds a dummy row to the spreadsheet to ensure that that the data...
3
by: Peter Kirk | last post by:
Hi do I need to explicitly close IDbConnection and IDbCommand objects? Or are they disposed of when the method they are used in ends? Normally I use a construct like: using (IDbConnection...
6
by: Steven D'Aprano | last post by:
Closing a file can (I believe) raise an exception. Is that documented anywhere? I've spent a lot of frustrating time trying to track this down, with no luck, which suggests that either my...
1
by: =?Utf-8?B?QW50aG9ueSBRdWVlbg==?= | last post by:
Hello All, I have created a custom "field" object in .Net that implements IOleObject. It inherits from "System.Windows.Forms.Label". It also has several public properties that contain data to be...
1
by: Paul Rubin | last post by:
it looks like contextlib.closing fails to be idempotent, i.e. wrapping closing() around another closing() doesn't work. This is annoying because the idea of closing() is to let you use legacy...
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: 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...
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
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...

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.