Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-13-2005, 07:37 PM
ADAM Web Design's Avatar
WebProWorld 1,000+ Club
 

Join Date: Dec 2003
Location: Toronto, Ontario, Canada
Posts: 2,217
ADAM Web Design RepRank 0
Default ASP resource question

Even though I've been using ASP for nearly 5 years, I have managed to come up with a question that I cannot figure out the answer to myself, since I can see it going both ways.

Back in 2000 (wow, does that seem a generation away!) I learned of the wonderful concept called "include files". And as soon as I figured out that they could encapsulate code and layout, I became a religious user of at least one per project.

Within that include file, I would have an Initialize sub, which would be executed before anything else. Contained within the Initialize sub would be a connection object to the database for the site (assuming it had one), as well as a recordset object to be able to work with it.

When the page was successfully loaded (no errors, etc.) the last line of my PageFooter (layout) sub would be a call to a sub called ClearObjects, which would...you guessed it, destroy the objects.

Back when I started this coding methodology, I was unaware of things such as GetRows() and arrays and wonderful things like that, so I would need the connection and recordset objects open from beginning to end, just because I wasn't sure when I was going to need them.

Now that I'm older and wiser, however, the thought has occurred to me that I can code in such a way as to use my include files to create objects only when I need them and destroy them otherwise.

For example, when querying a database, I could create a sub that would create the database and recordset objects (or call another sub to do the same thing), query the database, retrieve the results, and destroy the object all in one shot. This is as opposed to opening up the objects, waiting to use them, and then killing them at the very end.

This would prove advantageous from a server resource standpoint because, if I made an error outside of my data retrieval stage, then the objects would not exist and therefore not remain in memory.

The problem would potentially occur if a database was to be queried multiple times from within a page.

Let's say for example that I query a database six times within a page, for whatever reason I have. Would creating and destroying the connection and recordset objects six times be more efficient, even though the server has to work to create the objects, or would it be more efficient just to open it once and shut it down at the end?
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0