Click to See Complete Forum and Search --> : find the server (%path%)


August 2nd, 2000, 10:08 AM
Dear ladies and gentlemen,

Is it possible to let the system find the server and the volume for my application automatically without hard coded?

My code is:

With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Jet OLEDB:Database Password") = "Password"
.Open "\\ServerName\Volume\DataBaseDirectory\DatabaseName.mdb"
End With

What I want to do is “%path% \DataBaseDirectory\DatabaseName.mdb"
Instead if I am using "\\ServerName\Volume\DataBaseDirectory\DatabaseName.mdb”
The reason for that if they move the directory in the network.

I want the system fined the server and the volume for my application.
(Code please). I am using VB6.0 and Access 97

Thank in advance for your great help.

Jim

Johnny101
August 2nd, 2000, 03:01 PM
there is a great function of the Server object - its called MapPath and it takes a relative path and returns the physical path. For example, if your asp page is running in C:\InetPub\wwwroot\ and your database is in C:\inetpub\wwwroot\_private, you could add code like this in your asp page:

<%
dim cn
dim sconnectstring

sconnectionstring = "provider=Microsoft.Jet.OLEDB.4.0;user id=admin;password=password;"
sconnectionstring = sconnectionstring & "dbq=" & Server.MapPath("_private\database.mdb") & ";"

cn.connecionstring = sconnectionstring




then all you would have to do, no matter where your files were located, is make sure there is a directory underneath the running asp page named "_private". if you need to go up a level and then into another subdirectory do this:

'local path of asp c:\inetpub\wwwroot\admin\
'local path of the database c:\inetpub\wwwroot\_private\
<%
dim cn
dim sconnectstring

sconnectionstring = "provider=Microsoft.Jet.OLEDB.4.0;user id=admin;password=password;"
sconnectionstring = sconnectionstring & "dbq=" & Server.MapPath("..\_private\database.mdb") & ";"




play around with it, it's a really cool feature when it comes to finding physical paths. there are also several other ways of getting the local path using the server varaibles collection, but this way seems to be the easiest (at least to me anyway).

have fun,

John

John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org

August 3rd, 2000, 08:39 AM
Thanks for your help but how I can use this function in my code because I am not using VB script I am using ADO. , VB6.0 and access 97.

My code is:


Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Jet OLEDB:Database Password") = "Password"
.Open “\\ServerName\Volume\DirectoryName\FileName.mdb”
End With

.Open \\ServerName\Volume\DirectoryName\FileName.mdb this code is working in ADO but how can I write the mappath function. All examples were only for ASP nothing in ADO. I tried this code but is not working.
.Open " %=server.mappath(" \ DirectoryName\FileName.mdb”)%”

Thanks for your help and please let me know how could I apply the mappath function to ADO.

Jim

Johnny101
August 3rd, 2000, 10:43 AM
hehehe - sorry, i just came from the ASP forum.

as for the server name within VB, there are some APIs you could use, by why not use App.Path? it will return the physical path to the codebase and then from there you go into subdirectories.

if my app is running in C:\program files\micrsoft visual studio\vb98\tests\myexe.exe
when i ask for App.path, it will return the above path (without the "\myexe.exe"). then if you need to go into a subdirectory you could use app.path & "\database\databasename.mdb"

hope this applies more. :)

John

John Pirkey
MCSD
http://www.ShallowWaterSystems.com
http://www.stlvbug.org

August 3rd, 2000, 01:49 PM
Now we talk Thank you so much for your help. lol


Jim