Global.asa good practice?

A

Andyza

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?
 
A

Andyza

Ok, bad idea! I wasn't thinking! It won't work - the subs will be out
of scope in the Global.asa...
 
A

Aidy

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Opening/Closing Connections global.asa 4
Global.asa 5
OLEDB Connection String 2
cleaner ASP pages using subs 13
GLOBAL.ASA and IIS 6.0 7
RS EOF question 8
paging error handling 1
basic global.asa thingy 2

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top