By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,687 Members | 2,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,687 IT Pros & Developers. It's quick & easy.

Opinions please on global.asa vars

P: n/a
Hello gurus
Can I ask you opions on the best compromise for storing Access
Ado connection strings in a IIS4 standard ASP environment.
For any method I use, there seems to be an article somewhere
that says 'never' do this, or that.

1. I have 3 site folders s1, s2, s2 and a common DB folder outside
the site roots.
/sites/s1
/sites/s2
/sites/s3
/sites/db

Each site 'had' a global.asa containing something like -

Application("db1")= "Provider .... = " &
Server.MapPath("../db/db1.mdb")

At least once a week, my sites would fail with 'no db found' related
errors. Weeks of work demonstrated that global.asa was occasionally
not firing on my ISP's remote server causing Server.MapPath to return
nonsense paths.
In a state of shock, I quickly wrote a temporary include function (on
end of this post) to always retrieve the correct path and keep the
sites operational whilst I pondered.
I hate it (as you will), it must be slow, is certainly not elegant,
but it does seem bulletproof and never fails to return the correct
path for any folder structure and page location.

My questions are

1. If Application vars can be flaky, (or certainly using
server.mappath in global.asa is), what alternative options are viable
without compromising too much speed.

2. I have read things like 'avoid Server.MapPath'-
<http://authors.aspalliance.com/wiseasp/codingstandards.asp>
So if I use literal paths in include file, is there an elegant way of
switching connection strings between local the PC folder structure
and the remote server structure so I don't have to keep different
global.asa and/or include files on the local PC and remote server.

Any helpful advice will be immensely appreciated

Thank you in advance - Kenny

' Function returns absolute path for any dbname in folder
' /database, irrespective of page path making the call

Function GetCNS(dbname)
Dim a, i
GetCNS = "Driver={Microsoft Access Driver (*.mdb)};DBQ="
a = split(request.ServerVariables("PATH_TRANSLATED"), "\")
For i = 0 To UBound(a) - 1 -
UBound(split(request.ServerVariables("SCRIPT_NAME" ), "/"))
GetCNS = GetCNS & a(i) & "\"
Next
GetCNS = GetCNS & "database\" & dbname
End Function

Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I always use an INCLUDE FILE
Jul 19 '05 #2

P: n/a
Be careful with variables in a Function (livetime)the file DB.INC looks
like<% Dim a, i GetCNS = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" a
= split(request.ServerVariables("PATH_TRANSLATED"), "\") For i = 0 To
UBound(a) - 1 - UBound(split(request.ServerVariables("SCRIPT_NAME" ), "/"))
GetCNS = GetCNS & a(i) & "\" Next GetCNS = GetCNS & "database\" & dbname%>
The header of your pageshtml>
<head>
<!--#include file="DB.INC"--></head>
</html>
http://www.w3schools.com/asp/asp_incfiles.asp

"Kenny Ashton" <as***********@ctv.es> schreef in bericht
news:1s********************************@4ax.com...
Hello gurus
Can I ask you opions on the best compromise for storing Access
Ado connection strings in a IIS4 standard ASP environment.
For any method I use, there seems to be an article somewhere
that says 'never' do this, or that.

1. I have 3 site folders s1, s2, s2 and a common DB folder outside
the site roots.
/sites/s1
/sites/s2
/sites/s3
/sites/db

Each site 'had' a global.asa containing something like -

Application("db1")= "Provider .... = " &
Server.MapPath("../db/db1.mdb")

At least once a week, my sites would fail with 'no db found' related
errors. Weeks of work demonstrated that global.asa was occasionally
not firing on my ISP's remote server causing Server.MapPath to return
nonsense paths.
In a state of shock, I quickly wrote a temporary include function (on
end of this post) to always retrieve the correct path and keep the
sites operational whilst I pondered.
I hate it (as you will), it must be slow, is certainly not elegant,
but it does seem bulletproof and never fails to return the correct
path for any folder structure and page location.

My questions are

1. If Application vars can be flaky, (or certainly using
server.mappath in global.asa is), what alternative options are viable
without compromising too much speed.

2. I have read things like 'avoid Server.MapPath'-
<http://authors.aspalliance.com/wiseasp/codingstandards.asp>
So if I use literal paths in include file, is there an elegant way of
switching connection strings between local the PC folder structure
and the remote server structure so I don't have to keep different
global.asa and/or include files on the local PC and remote server.

Any helpful advice will be immensely appreciated

Thank you in advance - Kenny

' Function returns absolute path for any dbname in folder
' /database, irrespective of page path making the call

Function GetCNS(dbname)
Dim a, i
GetCNS = "Driver={Microsoft Access Driver (*.mdb)};DBQ="
a = split(request.ServerVariables("PATH_TRANSLATED"), "\")
For i = 0 To UBound(a) - 1 -
UBound(split(request.ServerVariables("SCRIPT_NAME" ), "/"))
GetCNS = GetCNS & a(i) & "\"
Next
GetCNS = GetCNS & "database\" & dbname
End Function

Jul 19 '05 #3

P: n/a
"Kenny Ashton" <as***********@ctv.es> wrote in message
news:1s********************************@4ax.com...
Hello gurus
Can I ask you opions on the best compromise for storing Access
Ado connection strings in a IIS4 standard ASP environment.
For any method I use, there seems to be an article somewhere
that says 'never' do this, or that.
To be clear, storing "strings" in session or app vars is OK, storing
"objects" is bad. So go ahead, store your connection strings and don't
store your database objects.
http://www.aspfaq.com/show.asp?id=2053
At least once a week, my sites would fail with 'no db found' related
errors. Weeks of work demonstrated that global.asa was occasionally
not firing on my ISP's remote server causing Server.MapPath to return
nonsense paths.
You said IIS 4 right?
http://support.microsoft.com/default...b;en-us;173742
My questions are

1. If Application vars can be flaky, (or certainly using
server.mappath in global.asa is), what alternative options are viable
without compromising too much speed.
They're not inherently flaky and it's pretty much the accepted practice to
store connection strings in global.asa. Alternatively, use code or include
files on every db access page.
2. I have read things like 'avoid Server.MapPath'-
<http://authors.aspalliance.com/wiseasp/codingstandards.asp>


While the statement "decreased performance" is true, how much of a
performance hit do you think it actually causes. My guess is that in this
case it's minimal and you'll see more benefit from using it rather than
dealing with the inconsistant paths.

--
Tom Kaminski IIS MVP
http://www.microsoft.com/windowsserv...y/centers/iis/
http://mvp.support.microsoft.com/
http://www.iisfaq.com/
http://www.iistoolshed.com/ - tools, scripts, and utilities for running IIS
http://www.tryiis.com

Jul 19 '05 #4

P: n/a
Gentlemen, that was perfect

I cannot believe the speed of your responses, hardly a pause in my
coding. Your lack of hesitation in confirming that 'using includes for
connection strings' is perfectly acceptable and common is very
reassuring.

My ISP is actually on IIS6, locally I'm on IIS4. It certainly seems
their are a lot of queries out there with 'losing session vars/event
failing to fire etc are very common. Think I will stick with hard
coded includes.

Many thanks again guys, for sharing your knowledge.

Kenny
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.