[thelist] ASP using Access as the DB: How to find the path to the DB if you don't have the actual one?

Gary Pupurs garyp at speakeasy.net
Wed Feb 28 16:25:09 CST 2001


>ASP using Access as the DB:
>How to find the path to the DB if you don't have the actual one?
>

> is there any other way than what I have below?
>
> :::::::::::::::the code::::::::::::::
>  Dim strPathInfo, strPhysicalPath, objFSO, objFile,
> objFolder
>  strPathInfo = Request.ServerVariables("SCRIPT_NAME")
>  strPhysicalPath = Server.MapPath(strPathInfo)
>  Set objFSO = CreateObject("Scripting.FileSystemObject")
>  set objFile = objFSO.GetFile(strPhysicalPath)
>  set objFolder = objFile.ParentFolder
>  'set objFolder = objFolder.ParentFolder
>  'set objFolder = objFolder.ParentFolder


Not sure why you're going to all this trouble to find the DB.  Why exactly
do you need objFile and objFolder?  Are you uploading a new database via a
web form or something complex? If not, there's a better way to access the
DB.

>From your message, I assume you have the DB in your web folders someplace.
(Note below why this can be insecure and not usually the best way).

But if your database is at, say, http://www.mysite.com/_databases/bigDB.mdb
then the way to get to it is with this:

Dim strDBConn, connDB
strDBConn = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource="
strDBConn = strDBConn & Server.MapPath("/_databases/bigDB.mdb")
connDB.Open strDBConn

Then use as needed with a recordset (rsInfo.open strSQL, connDB). Is this
not what you need?

<alert!>
Unless you change that directory's permissions in the IIS manager by
unchecking 'read' access, be aware that anyone guessing your DB path and
name can download your database.  Search on 4guysfromrolla.com for an
article about this. Also, you'll have to change the NT permissions (not the
IIS permissions) on the directory or DB file to allow 'write' access from
the user that IIS runs as or you won't be able to insert data into the DB.
</alert!>

Generally, if you can, it's better to set up a database directory outside
the web root as a known path.  Here we use "D:\ASPDatabases\" on all our web
servers.  So the above becomes:

Dim strDBConn, connDB
strDBConn =
"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=D:\ASPDatabases\bigDB.mdb"
connDB.Open strDBConn

Of course, you really should be setting DB connection info in /global.asa,
not in each file, so you can move the DB later or rename it or make it a SQL
Server DB and change your code in only one place, in global.asa.  Then it
would look like this:

Dim connDB
connDB.Open Application("Mysite_DBConnString")

Much simpler, easier to maintain.  Hope that helps someone, if not you!

-g









More information about the thelist mailing list