relative path to data base in web.config

Can I

Member
Joined
Oct 23, 2006
Messages
12
Location
Coventry, UK
Programming Experience
3-5
hello,

I'm setting a connectionString for my app
VB.NET:
<appSettings>
        <add key="connectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Ole DB Services=-4;
    
      Data Source=C:\Documents and Settings\Can I\Pulpit\asp.net\BookStore\App_Data\BookStore.mdb"/>
    </appSettings>
and I would like not to include absolute path to a data base as it's unconvenient when you move app between two servers. I've tried something like ~\App_Data\BookStore.mdb but it doesn't work. Can you help me with this one?
 
App_Data\BookStore.mdb should work for relative path, the ~ I think only resolves from a web app path lookup and not in a connection string.
 
not really, it is reslved to
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\App_Data\BookStore.mdb

and the Solution's files reside in
C:\Documents and Settings\Can I\Pulpit\asp.net\BookStore
 
Do you also know the Server.MapPath function? It can translate relative path to absolute. I found when doing some web surfing about this that many store the path in a separate string and do mappath it and combine with the other connection string before connecting. Try it.
 
Asking the question in the "Data Access" subforum of the "ASP.NET" section rather than the "VB.NET" section may illicit a more targeted response from an individual with relevant experience :)
 
Asking the question in the "Data Access" subforum of the "ASP.NET" section rather than the "VB.NET" section may illicit a more targeted response from an individual with relevant experience :)
It was in ASP.Net section yesterday, I don't know why it was moved, but I moved it back now.
 
Do you also know the Server.MapPath function? It can translate relative path to absolute. I found when doing some web surfing about this that many store the path in a separate string and do mappath it and combine with the other connection string before connecting. Try it.
I didn't know that, it's a good idea when you try it form within aspx site, but in my case it doesn't work. Consider this solution structure:
VB.NET:
solution
   - web site // contains all aspx and web controls
   - class library project // contains the code, DAOs in particular
   - class library project for tests // that's why I need the code in separate project
as a result I have no Server object availiable in DAO, so how to obtain that relative path then?
 
Pass Server instance to class then?
 
yes, that's the simplest solution ;)

// ok, I found nicer solution: HttpContext.Current.Server.MapPath :)
 
Last edited:
Nice! Easier to use that shared property as a "shortcut" to the instance.
 
Back
Top