server.mappath problem.

C

Cozmo

We have an .asp application , located in:

e:\myapp

In there we have directories like:

e:\myapp\db
e:\myapp\images
e:\myapp\utils
e:\myapp\working

In global.asa we have a server.mappath("db") & "mydb.mdb" to get the db
location

This works MOST of the time, but sometimes the browser shows an error like:

Cant find file e:\myapp\utils\mydb.mdg

This is CLEARLY the wrong file path. Restarting iis or the website or
reinitiallising the application will correct this and it generally works for
a long time and then will do it again, quite randomly. (long time meaning
sometimes months !)

It seems to be a bug of some kind - is anyone aware of this I cannot find
mention of it anywhere.
 
M

McKirahan

Cozmo said:
We have an .asp application , located in:

e:\myapp

In there we have directories like:

e:\myapp\db
e:\myapp\images
e:\myapp\utils
e:\myapp\working

In global.asa we have a server.mappath("db") & "mydb.mdb" to get the db
location

This works MOST of the time, but sometimes the browser shows an error like:

Cant find file e:\myapp\utils\mydb.mdg

This is CLEARLY the wrong file path. Restarting iis or the website or
reinitiallising the application will correct this and it generally works for
a long time and then will do it again, quite randomly. (long time meaning
sometimes months !)

It seems to be a bug of some kind - is anyone aware of this I cannot find
mention of it anywhere.

You don't understand how to use Server.MapPath().

server.mappath("db") will not do what you think it does.

server.mappath("/db/mydb.mdb") may be what you need.
 
C

Cozmo

Actually, I DO understand how it works (aside from the couple of typos in my
post), and it works just fine - about 99.9% of the time.

FYI , as you may not realize the difference, this is the functions method
from M/S:

If Path starts with either a forward (/) or backward slash (\), the MapPath
method returns a path as if Path were a full, virtual path. If Path doesn't
start with a slash, the MapPath method returns a path relative to the
directory of the .asp file being processed.

-- end clip --

I am using a 'relative' path which is necessary as I dont know where my
customers may install the application in relation to the root path or the
root of the website or virtual web - the example you gave is a 'fixed' path
from the root, where the one i showed allows the virtual path to be on the
2nd level of a tree, or the 12th level of the tree ! I cannot use the fixed
path, as I dont have control over where that may be - we may be at the root
or at some subdirectory of the root, perhaps several layers deep !!
 
M

McKirahan

Cozmo said:
Actually, I DO understand how it works (aside from the couple of typos in my
post), and it works just fine - about 99.9% of the time.

FYI , as you may not realize the difference, this is the functions method
from M/S:

If Path starts with either a forward (/) or backward slash (\), the MapPath
method returns a path as if Path were a full, virtual path. If Path doesn't
start with a slash, the MapPath method returns a path relative to the
directory of the .asp file being processed.

-- end clip --

I am using a 'relative' path which is necessary as I dont know where my
customers may install the application in relation to the root path or the
root of the website or virtual web - the example you gave is a 'fixed' path
from the root, where the one i showed allows the virtual path to be on the
2nd level of a tree, or the 12th level of the tree ! I cannot use the fixed
path, as I dont have control over where that may be - we may be at the root
or at some subdirectory of the root, perhaps several layers deep !!

[snip]

Try changing:
server.mappath("db") & "mydb.mdb"
to
server.mappath("db/mydb.mdb")
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top