friendo9876
friendo9876

Reputation: 121

How to make it access database path relative in asp.net web.config file

I am trying to change the path of my access database from an absolute path to a relative one in my web.config file. I have search on stack overflow and tried to use the suggestion they have had, but they didn't work. here is my current connection string:

<add name="2007 SoundAssist VER 1.0.5  05-12-2011 ConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot;C:\Users\Esfahanian\Dropbox\Anderson\ SoundAssist VER 1.0.5  05-12-2011.mdb&quot;" providerName="System.Data.OleDb"/>

Any help would be most excellent. Thank you guys for your time

Upvotes: 0

Views: 2047

Answers (1)

suff trek
suff trek

Reputation: 39777

Declare partial connection string in the Web.Config:

<add name="2007 SoundAssist VER 1.0.5  05-12-2011 ConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" providerName="System.Data.OleDb"/>

And then in code augment it with something like this (this example is in VB)

Dim connectionString As String = ConfigurationManager.ConnectionStrings("2007 SoundAssist VER 1.0.5  05-12-2011 ConnectionString").ConnectionString & Server.MapPath("/your/application/path/SoundAssist VER 1.0.5  05-12-2011.mdb")

UPDATE: C# Version

string connectionString = ConfigurationManager.ConnectionStrings["2007 SoundAssist VER 1.0.5  05-12-2011 ConnectionString"].ConnectionString + Server.MapPath("/your/application/path/SoundAssist VER 1.0.5  05-12-2011.mdb");

Upvotes: 1

Related Questions