Can you declare your database connection in your global.asa file rather than your asp file? I think you can.. but what would the benefits of doing it that way be?
I've heard it's wrong to do your database connection(s) in your asp pages.. even if you're using include files to do this..?
Last edited by geekazoid; 03-01-2005 at 04:29 PM.
I haven't heard any such thing. I declare my connection string in my global.asa but I actually create the connection in an include file. The only reason I can think of that someone might say not to create the connection in each page (or in an include file) is because of the time to repeatedly connect and disconnect each time a page is requested. I have not found this to be a problem for the sites I have worked on -- but, then again, perhaps a high-volume site would need greater advantages.
you should create an include file for your connection strings. use UDLs if at all possible for the actual connection parameters, then define constants in the include file that point to the UDL. This enhances security and allows you to change the connection string should u ever need to, in one place -- the UDL.
open the database connection just b4 you need it and close it immediately after. at worst, open it at the start of the page, and close it at the end. never open it just because. database conections are the *most* precious resource in your system. don't waste them (and add overhead) by unnecessarily creating them, or by leaving then open longer than needed.
quite the opposite, close 'em right away.
The only reason I can think of that someone might say not to create the connection in each page (or in an include file) is because of the time to repeatedly connect and disconnect each time a page is requested
of course, the best way is to create the actual connection in a DLL and instantiate a COM object, but for a pure asp answer...
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)