473,671 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.CreateOb ject("ADODB.Con nection")
conn.Open Application("Co nnString")
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(Te st)
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 1528
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.goo glegroups.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.CreateOb ject("ADODB.Con nection")
conn.Open Application("Co nnString")
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(Te st)
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
3036
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 been for years. If the machine has memory to spare and windows can use it - I'm thinking "Why not?" I was wondering what some of you have to say about that, particularly any severe "gotchas" you've had the unfortunate experience to contend with.
18
8638
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 with const, but thereafter they are no longer variables. Just couldn't see the benefits of this practice. Any comments or advices are welcome. Thanks vib
24
2520
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 that I am using them appropriate in class in question. One typical example: This class initiates TCP session, keeps sending commands to the server app and gets messages and codes back, message and code are stored in global variables to be preserved...
5
9252
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 sub" in a program: dim mydata as (whatever) Public Sub Page_Load(etc..)
2
3488
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 which each page will use, but my question relates to how to use the database connection i create in all my classes. I have a database class, in a separate namespace and file, i created that handles all the connection opening, executing statements...
8
2699
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 variables that need to be accessed by a number of classes that exists in separate namespaces (files), what would be the best way to do this? So far, I have approached the problem by making the variables attributes of one class and passing...
10
7020
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, including main.cpp I have global variables that need defining in main.cpp and declaring in all other files in. The way I've seen it done is to define/declare everything in one header file (e.g. globalincludes.h) prefaced with the word EXTERN ...
2
1886
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 package and created a class there. Like this: Util.py: ~~~~~~~~ class Util: def __init__(self, debugFlag=False, vibranceLevel='good'):
6
1540
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, Rajesh.S
0
8390
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8667
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4221
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4399
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1801
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.