0

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

2
  • 1
    You may have to specify path in code via call to Server.MapPath Commented Jul 12, 2013 at 16:24
  • What @YuriyGalanter said. This is especially important because it is not a good practice to store your database in your web site folder. It can potentially allow people to download the file. Commented Jul 12, 2013 at 16:30

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

13 Comments

I am doing my project in c#, is there any way that you can show how to do the second part using c#?
I put this in <string connectionString=ConfigurationManager.ConnectionString["2007 SoundAssist VER 1.0.5 05-12-2011 ConnectionString"].ConnectionString + Server.MapPath("/Dropbox/Anderson/2007 SoundAssist VER 1.0.5 05-12-2011.mdb");></string> What am i doing wrong exactly?
The solution consists of 2 parts: 1st - <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"/> goes into your Web.Config ConnectionStrings section. 2nd - C# code - goes int your ASPX.CS file - this one without the tags, just variable declaration and assignment 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");
Unfortunately that didn't work for me. But thank you for your help
Could u elaborate what exactly didn't work? If you found the other solution then good luck :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.