473,395 Members | 2,798 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,395 software developers and data experts.

Global.asa and database connections..

Hello group,

I have a question hope it does not turn out to be a silly on....

On everyone of my pages I have an a include page at the top and at the
bottom of the page

one is the database connection and one is for the database disconnection.

is there anyway I can automaticly connected to the database using a string
without adding it to every page ?

I checked in IIS and I can add a footer but not a header, or anyway using
global.asa file

Kind Regards

Graham Mattingley
Jul 19 '05 #1
6 5040
> is there anyway I can automaticly connected to the database using a string
without adding it to every page ?


Isn't that what the include file is for? When your database moves or you
otherwise have to change your connection string, you change one file.

If you're hoping to have a single connection object throughout your session,
or worse yet, a single connection object shared by all sessions, it is not a
good idea. It doesn't sound intuitive at first, but believe me, it is more
efficient to open the database, get in, get out and close it on every single
page than it is to have a connection remain open (and unusable by other
sessions) throughout the life of a session.

Perhaps useful reading:
http://www.aspfaq.com/2053

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
Jul 19 '05 #2

I agree with Aaron ... you need to get in and get out of your database
as fast as possible. You don't need your database connection the
entire time the page is loading. Try out my
/coolpier_scripts/DBConn.asp script at ...

http://www.coolpier.com/cp/cp_script...ile=DBConn.asp

This will allow you to get in and out pretty quick ... then loop
through the 2-dimensional array of your recordset.
<!-- #include virtual="/coolpier_scripts/DBConn.asp" -->
<%
Dim yourSQL, yourArray

cp_ConnectionString = "DSN=yourDSN;"
yourSQL = "select * from yourTable where this = 'that';"

'// ****** INTO DATABASE ******
cp_DBConn.asp("open")
yourArray = cp_SqlArray(yourSQL)
cp_DBConn("close")
'// ****** OUT OF DATABASE ******

If Not IsArray(yourArray) Then
'// No Records Found Code
Else
'// Display Records Code

'//SAMPLE LOOP
Dim columnCount, rowCount
columnCount = ubound(yourArray,1)
rowCount = ubound(yourArray,2)

With Response
.Write "<table border=""1"">"
For zRow = 0 to rowCount
.Write "<tr>"
For zColumn = 0 to columnCount
.Write "<td>" & yourArray(zColumn, zRow) & "</td>"
Next
.Write "</tr>"
Next
.Write "</table>"
End With

End If
%>
On Mon, 12 Jan 2004 19:37:23 -0500, "Aaron Bertrand - MVP"
<aa***@TRASHaspfaq.com> wrote:
is there anyway I can automaticly connected to the database using a string
without adding it to every page ?


Isn't that what the include file is for? When your database moves or you
otherwise have to change your connection string, you change one file.

If you're hoping to have a single connection object throughout your session,
or worse yet, a single connection object shared by all sessions, it is not a
good idea. It doesn't sound intuitive at first, but believe me, it is more
efficient to open the database, get in, get out and close it on every single
page than it is to have a connection remain open (and unusable by other
sessions) throughout the life of a session.

Perhaps useful reading:
http://www.aspfaq.com/2053

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


I participate in the group to help give examples of code. I do not guarantee the effects of any code posted. Test all code before use!

Brynn
www.coolpier.com
Jul 19 '05 #3
Hi Graham,

If you are always showing the same data (for example to fill dropdownboxes)
from the database, you can use an application variable to store the
recodset in.
Storing recordsets in session variables is absolute not something you
should do.
Maybe reading article
http://support.microsoft.com/default...b;en-us;258939

Regards,

Ralph
Microsoft

Jul 19 '05 #4
"Ralph Hodenius [MS]" <ra*****@online.microsoft.com> wrote in message
news:O8**************@cpmsftngxa07.phx.gbl...
Hi Graham,

If you are always showing the same data (for example to fill dropdownboxes) from the database, you can use an application variable to store the
recodset in.
Storing recordsets in session variables is absolute not something you
should do.
Maybe reading article
http://support.microsoft.com/default...b;en-us;258939

Regards,

Ralph
Microsoft


Recordsets (and other non-threadsafe) objects should be stored in
neither session nor application variables.
http://aspfaq.com/show.asp?id=2053

HTH
-Chris Hohmann
Jul 19 '05 #5
Agreed. Throw it into GetRows(), and store the array in such a scope, at
least. Or build a string and store the string there. But not a recordset
object, blecch. WHat's the point of storing the object? The data is
already stale, so you're not really getting the benefit of "dynamic"...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Chris Hohmann" <no****@thankyou.com> wrote in message
news:OZ**************@TK2MSFTNGP11.phx.gbl...
"Ralph Hodenius [MS]" <ra*****@online.microsoft.com> wrote in message
news:O8**************@cpmsftngxa07.phx.gbl...
Hi Graham,

If you are always showing the same data (for example to fill

dropdownboxes)
from the database, you can use an application variable to store the
recodset in.
Storing recordsets in session variables is absolute not something you
should do.
Maybe reading article
http://support.microsoft.com/default...b;en-us;258939

Regards,

Ralph
Microsoft


Recordsets (and other non-threadsafe) objects should be stored in
neither session nor application variables.
http://aspfaq.com/show.asp?id=2053

HTH
-Chris Hohmann

Jul 19 '05 #6

I think this question is leading more towards that of "ease of
development" ... keeping the DB open all the time. This obviously
should not be done, and hence my post.

Everyone elses points here are also very valid ...

If I am showing the same data over and over, and that data doesn't
change very often, I build a backend where I can use the database to
store the data, and where I can update it ... but I also have an
"UPDATE WEBSITE" button to recreate the 'static' file on the website
that has the info ... many times, I will have it take my recordset ...
for example ...

values, labels

1234, Option1Name
2345, Option2Name
3456, Option3Name

my backend will take this data, and write a n ASP file with the html
written out for the dropdown box. Then include it in the write spot.

Another example, a products database that only a small handful of
people have access to update, delete, add. I will create each product
it's own formatted static html info in a folder with it's item number
as it's file name, etc...

I want my database open only when completely necessary. But then
again, I am a crazy, performance hungry fiend ... hehe.

Brynn
www.coolpier.com
On Tue, 13 Jan 2004 16:19:16 GMT, ra*****@online.microsoft.com (Ralph
Hodenius [MS]) wrote:
Hi Graham,

If you are always showing the same data (for example to fill dropdownboxes)
from the database, you can use an application variable to store the
recodset in.
Storing recordsets in session variables is absolute not something you
should do.
Maybe reading article
http://support.microsoft.com/default...b;en-us;258939

Regards,

Ralph
Microsoft


I participate in the group to help give examples of code. I do not guarantee the effects of any code posted. Test all code before use!

Brynn
www.coolpier.com
Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: RooLoo | last post by:
Hey all In my GLOBAL.ASA file I'm trying to create a session variable for reference in the various webpages of my site.... Sub Session_OnStart Session("LoggedOn")="Y" End Sub When...
7
by: Matt Calhoon | last post by:
Hi there, How does IIS 6.0 treat the global.asa file? I had the following problem; 1. uploaded a new site to the win3k server 2. had incorrect db connection string in Session_OnStart in...
9
by: Mike P | last post by:
I am converting a VB6 app to C# and the VB6 app has 1 connection and 3 recordsets, all global and open all the time so that all the required procedures can use them. Using C#, would it be best to...
9
by: Newbie | last post by:
Hello, I need to declare a global variable e.g. database connection handle. So that I hava an access to this variable all over my class. How can I do it in c#? Do I have to declare it as static...
2
by: Bryan | last post by:
Hello, I'm just starting to develop in asp.net and i have a question about using a database connection globally in my app. I have set up the procedures for getting all my connection string info...
7
by: g | last post by:
hello! I wanna use a global variable,witch is the best way(I don't want to use a Singleton for an integer)? I try : #ifndef DUMY_H_ #define DUMY_H_ int connections; #endif /*DUMY_H_*/
35
by: Terry Jolly | last post by:
Web Solution Goal: Have a global database connection Why: (There will be 30+ tables, represented by 30+ classes) I only want to reference the database connection once. I put the connection...
37
by: Joshua Ruppert | last post by:
When I'm using FastCGI do I need to code differently than I do when using regular CGI? Because the PHP.exe processes don't go away do global variables stick around from page request to page...
5
by: john | last post by:
All: I have a MS background and am having fun in the open source world of PHP and MySQL --- and I have a question. With PHP and MySQL, is it considered better practice to open a single...
4
by: =?Utf-8?B?SlA=?= | last post by:
I have a C# DLL project I have created. The DLL plugs into other C#.NET applications. This DLL has several classes and methods comprised for 4 namespaces that are used by other programmer to...
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.