Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 15th, 2004, 04:24 PM
Authorized User
 
Join Date: Aug 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default db connection scope

while writing my first asp app i created my db connection object in every asp page that i wrote then set it to nothing at the end of each page. since then i've learned that i can create that connection object in my global.asa file and create it in the application_onStart or session_onStart events. So as I see it i'm presented with 3 options:

1 - connection object with script level scope
2 - connection object with session level scope
3 - connection object with application level scope

i only need one connection object that hooks a single access file.

what do you asp gurus suggest? something inside me is saying i need to create a single application level connection object and do away with all the script level creating and killing.
 
Old January 15th, 2004, 04:42 PM
Authorized User
 
Join Date: Dec 2003
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default

While you can do it this way, it is heavy on server resources. If you prefer to not constantly type the connection info just type it into a include file. Then, you only include it on the pages that are necessary. Also, if for some reason a user does not allow cookies the application and session events won't fire.

Finally, session on end is notorious for not firing. This will result in way to many open connections and greatly deteriorate server performance

One other thing, why have an open connection if you have pages that don't necessarily need the connection 'always open'

John

 
Old January 15th, 2004, 05:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Make sure that if you use an include file that you give it an asp extension so it won't return in text the path to your database if someone guesses the name of it.
 
Old January 16th, 2004, 05:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

You absolutely should not store connection objects in the application or session collection. It will choke your application. Put it in an include file instead and open the connection only when you need it.
 
Old January 16th, 2004, 07:35 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I agree with the "one connection per file" method. There are plenty of ways to simplify the use of a single connection object thruout the life of a page, but like pgtips says, you should not leave a connection object in session or application scope.

If you are concerned about connections being constantly created, don't be. Once you have created a connection and closed it, the connection will remain in connection pooling. If another page request comes long that uses the same connection string, the pooled connection will be used and that will same some time when you create the object.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old August 9th, 2005, 06:19 PM
Authorized User
 
Join Date: Aug 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In the book on ASP I am reading, it says that having one DB connection with application scope would be better than having it open and close over and over again. (on a high traffic site with one database and many connections)
I don't understand how keeping the connection, not the recordset but just the single application level, database connection open would be more of a resource hog than having it open a hundred times or more in one minute.
If you have a website where every page uses the database then wouldn't an application level connection be the best way to go?

I may be way off on this since I just started learning asp but this just seems the way it would logically work.
if i'm wrong, please tell me.


on another note, anyone know how i can use methods and properties on session/application level variables?
Application("Connection").open ?

------------------------------
Fezzic, are there rocks ahead?
If there are, we'll all be dead.
NOW STOP THAT RHYMING, Now I Mean it.
Any-body want a Peanut?





Similar Threads
Thread Thread Starter Forum Replies Last Post
db connection dfeuerborn VB Databases Basics 1 August 19th, 2005 02:08 PM
db connection dfeuerborn Excel VBA 1 August 19th, 2005 02:24 AM
db connection dfeuerborn Access VBA 1 August 17th, 2005 10:33 AM
DB Connection with Application/Page Scope Hazzardusa Classic ASP Databases 0 August 14th, 2005 10:10 PM
DB Connection stu9820 ASP.NET 1.0 and 1.1 Basics 1 September 26th, 2004 09:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.