473,385 Members | 1,753 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,385 software developers and data experts.

Global.asa good practice?

In my Global.asa file I have the following 2 subs for opening and
closing my db connection:

Sub OpenConn()
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open Application("ConnString")
End Sub

Sub CloseConn()
conn.Close
Set conn = nothing
End Sub

Then in my asp pages I simply call the subs when I need to open and
close the db connection.

Eg.:

Dim Test
Test = "Select XXX from SomeTable"
OpenConn()
Set rs = conn.Execute(Test)
Do While Not rs.eof
Response.Write(rs("XXX"))
rs.MoveNext()
Loop
CloseConn()

Is this good practice to have the 2 db subs in the Global.asa?

Aug 25 '05 #1
3 1518
Ok, bad idea! I wasn't thinking! It won't work - the subs will be out
of scope in the Global.asa...

Aug 25 '05 #2
Andyza wrote:
Ok, bad idea! I wasn't thinking! It won't work - the subs will be out
of scope in the Global.asa...


Not only that, but read this:
http://www.aspfaq.com/show.asp?id=2053

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Aug 25 '05 #3
As you have found out, that doesn't work, but you can put those pages in a
separate file and INCLUDE them in each ASP page you need them.

"Andyza" <an****@webmail.co.za> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
In my Global.asa file I have the following 2 subs for opening and
closing my db connection:

Sub OpenConn()
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open Application("ConnString")
End Sub

Sub CloseConn()
conn.Close
Set conn = nothing
End Sub

Then in my asp pages I simply call the subs when I need to open and
close the db connection.

Eg.:

Dim Test
Test = "Select XXX from SomeTable"
OpenConn()
Set rs = conn.Execute(Test)
Do While Not rs.eof
Response.Write(rs("XXX"))
rs.MoveNext()
Loop
CloseConn()

Is this good practice to have the 2 db subs in the Global.asa?

Aug 25 '05 #4

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

Similar topics

33
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have...
18
by: vib | last post by:
Hi there, By chance, I came to learn that it is bad programming practice to initialize global variables at outside of programs. Is it that bad? In order to fullfil this, I had to declare them...
24
by: LP | last post by:
After a code review one coworker insisted that global are very dangerous. He didn't really give any solid reasons other than, "performance penalties", "hard to maintain", and "dangerous". I think...
5
by: Fred Nelson | last post by:
Hi: I'm a relative newby so hopefully this is a simple question! I have found that I can create global variables easily on a web page by placing the dim statement before the first "private...
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...
8
by: newbie | last post by:
Hello, I have questions about global variables in OOP (in general) and Python (in specific). I understand (I think) that global variables are generally not a good idea. However, if there are...
10
by: Jay Wolfe | last post by:
Hello, I'm trying to make sure I use best practices (and hence save myself some headaches) with the declaration and definition of global variables. Let's say I have an app with 30 files,...
2
by: Christoph Haas | last post by:
Evening, I'm currently working on a larger Python project that consists of multiple programs and packages. As I need a few utility functions time and again I moved them all into a Utility...
6
by: Rajesh | last post by:
I read Global Object's constructor will be called before main() function; In which situation it can be really helpful? Is it good practice use Global object and its constructor ? Thanks,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.