Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 DEV-Group
 DEV Discussions (General)
 Q: Resource status on failure exit.
 New Topic  Topic Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 3

Deleted
deleted

4116 Posts

Posted - 09 February 2003 :  10:11:28  Show Profile
Suppose you have a connection and a record set object created. You check a condition and then stop execution using response.redirect or response.end.

Is it safe to handle such cases in this way?
What happens to the open resources?

Please think of all combinations (database & web server) Snitz is supporting...

Stop the WAR!

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 09 February 2003 :  10:29:16  Show Profile  Send ruirib a Yahoo! Message
I usually close recordsets and connections before redirecting or response.ending in my own code.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 09 February 2003 :  11:50:05  Show Profile
So do I, at least I try to. As far as I know IIS 5 can salvage the remaining resources but this is not the case for IIS 4. I don't know about others.

There are some places in the base code where they are left open. If they can result in a leak, repeated call to this kind of behaviour can cause problems on the server.

Stop the WAR!
Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 09 February 2003 :  13:02:49  Show Profile
AFAIK, even with IIS4 ado and other objects are destroyed automatically when they fall out of scope (i.e., the page is closed).

I follow the tips on this page and generally open and close connections immediately within functions or methods.

http://msdn.microsoft.com/library/default.asp?URL=/library/en-us/dnasp/html/ASPtips.asp



======
Doug G
======
Computer history and help at www.dougscode.com
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 09 February 2003 :  15:46:51  Show Profile
I use a custom function to access DB and close the recordset and connection within the function. The Thumb rule is "Open Late, Close Early".
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 09 February 2003 :  16:04:17  Show Profile
what does that do to performance though GB? Let's say you open multiple recordsets on one page, doesn't that open and close the db connection each time?

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 09 February 2003 :  17:11:12  Show Profile
I store the required information in variables or arrays. The site I am currently working on has html and asp code completely separate. I store the information to be displayed in constants or variables or arrays. The html page uses the variables or constants populated via asp code and is displayed to the user. It is not that hard once you get going. I can redisgn the presentation any time and any way.

Edited by - GauravBhabu on 09 February 2003 17:16:52
Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 09 February 2003 :  17:16:29  Show Profile
quote:
Originally posted by GauravBhabu

I use a custom function to access DB and close the recordset and connection within the function. The Thumb rule is "Open Late, Close Early".


Ditto. I pass the connection string and sql string to the function and get back an array from getrows. The db connection is opened and closed within the function (actually a vbs class module).

Nikkol, nearly all current IIS servers use connection pooling behind the scenes which reuses open connections if there is another call within a certain time frame, so performance is enhanced all around if you open and close right away.



======
Doug G
======
Computer history and help at www.dougscode.com
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 09 February 2003 :  17:19:50  Show Profile
So, Doug, if you open then close and the open and close again, this is essentially the same as just opening and closing once?

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 09 February 2003 :  17:26:33  Show Profile
I also have a library to build the connection strings depending on the database and get information from DB. Depending on the requirements It returns Records either using Get Rows or as Recordset. I intend to add XML options as well.
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 09 February 2003 :  17:30:06  Show Profile
quote:
Originally posted by Nikkol

So, Doug, if you open then close and the open and close again, this is essentially the same as just opening and closing once?


It is like opening your locker take what you need close it do whatever you want to do with the contents and if you need something more open your locker again, take what you need and close it. You do not want to leave your locker open, in case you get too busy somewhere else and the locker reemains open and...
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 09 February 2003 :  17:50:09  Show Profile
I get the idea. Just was wondering the efficiency of opening db connection ... opening and closing multiple recordsets ... closing db connection VERSUS open db conn, open recordset, close recordset, close db conn multiple times. I use GetRows almost exclusively when I get recordsets, but usually i only open one connection to db.

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 09 February 2003 :  18:23:51  Show Profile
Never looked in depth but I believe opening and closing connections and or recordsets consumes lesser resources then leaving the connections and recordsets open.

Think of Electric Power. The line connection is always there but the electricity is consumed only when you turn on the lights or electrical appliances.
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 09 February 2003 :  18:49:54  Show Profile
Well, I know all these and have similar libraries for my own work, but mostly related to IIS 5, Access & SQL DB...

But wrt our work here with the forum, we don't have such mechanisms granted and I don't want to redesign everything before v4f is out.

Snitz is meant to be compatible with web servers other than IIS 5. My main emphasis in the original question is those environments that I never examined (MySQL, Sun systems, other possible *nix systems).

Stop the WAR!
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 09 February 2003 :  19:04:43  Show Profile
I'm not talking about leaving them open ... this is what I mean ...

open db
open recordset1
close recordset1
open recordset2
close recordset2
close db

versus

open db
open recordset1
close recordset1
close db
open db
open recordset2
close recordset2
close db

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20600 Posts

Posted - 09 February 2003 :  19:05:06  Show Profile  Visit HuwR's Homepage
quote:
Originally posted by GauravBhabu

quote:
Originally posted by Nikkol

So, Doug, if you open then close and the open and close again, this is essentially the same as just opening and closing once?


It is like opening your locker take what you need close it do whatever you want to do with the contents and if you need something more open your locker again, take what you need and close it. You do not want to leave your locker open, in case you get too busy somewhere else and the locker reemains open and...



Mmm, not a particularly good analogy Doug, since it implies that if you leave it open something might happen to its contents, which is not correct.
It is more like a room with many doors , but while you hold a door open nobody else can pass through it, closing it quickly allows someone else to use the door rather than have to wait or open find another door
Go to Top of Page
Page: of 3 Previous Topic Topic Next Topic  
Next Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.21 seconds. Powered By: Snitz Forums 2000 Version 3.4.07