Relative path to Access db

D

dw

Hello, all. I have a site that I'm testing on my LOCALHOST and also on a
remote server, depending on whether I'm at work or at home. I don't want the
OLEDBDATAAdapter to be pointing to the remote Access db, but to the local
one. The OLEDBDATAAdapter wizard puts the entire path of the db
(\\myserver\.... or c:\myprojects\....).

The db resides within the site's folders; is there anyway to use relative
paths for it (something like "global/data/project1.mdb")? Thanks :)
 
K

Karl

Store the relative path in your web.config and do a Server.MapPath to get
the full path to the file...

Karl
 
G

Greg Burns

Dim cn As OleDb.OleDbConnection

cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath(ConfigurationSettings.AppSettings("path"))) ' -->>>
c:\inetpub\wwwroot\global\data\project1.mdb

web.config...

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="path" value="/global/data/project1.mdb" />
</appSettings>

<system.web>
.... etc

HTH,
Greg
 
G

Greg Burns

Another useful tip is to use comments in your web.config so you can just
uncomment your other "path" when you switch locations, lot less typing...

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<!--
<add key="path" value="/global/data/project1.mdb" />
-->
<add key="path" value="/global/data/project2.mdb" />

</appSettings>

<system.web>

Greg
 
K

Karl

Greg...an even better idea is to use a user.config file on one of the
machines to overwrite the default setting in the web.config

web.config -->
<appSettings file="user.config">
<a key="path" value="blah" />
</appSettings>

user.config -->
<appSettings>
<a key="path" value="otherblah" />
</appSettings>

if the user config is present, it'll return otherblah as the value..Great
for team development.

Karl
 
G

Guest

I'm resurrecting this thread because I need some clarification on settings.
So I too have made the db connection using th ui(designer) I check the
properties of the oledbconnection and can see the connection string. I can
also choose <dynamic properties> and add a key to the web.config with the
connection string (e.g. <add "dbConnect" value"string" />)

Now what I want to know is how do i use that config in place of the designer
generated string and how can I modify it to use a relative path (i.e.
server.mappath)

cheers
 

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

Top