[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

web.config  Server.MapPath connection string

Posted on 2006-03-28
11
Medium Priority
?
3,944 Views
Last Modified: 2010-05-18
Hi,

I'm new to Asp.NET, up to now have been using plainold ASP.

Is it possible (YES or NO) to use the Server.MapPath function in the Web.Config file?

I'm asking for the obvious reason of not having to change everything when I copy files from my test server to a live site.

Right now on my ASPX page, I have:
Dim connectionString As String = ConfigurationSettings.AppSettings("ConnectionString")
Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)

and in my Web.Config file, I have tried to use :
<appSettings>
   <add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Ole DB Services=-4;Data Source=" & Server.MapPath("data\mydatbase.mdb") & ";" />
</appSettings>

This gives me an error message.

If it is NOT possible to use Server.MapPath in the Web.Config file, do I have to use something like :
<appSettings>
   <add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Ole DB Services=-4;Data Source={0}" />
</appSettings>

and then how would I call that from my aspx page:
Dim connectionString As String = ConfigurationSettings.AppSettings("ConnectionString")????????

thanx for any help!!
0
Comment
Question by:tom_burkhardt
  • 7
  • 4
11 Comments
 
LVL 5

Accepted Solution

by:
intreeg earned 2000 total points
ID: 16312541
What about the file will change?

If you use something like: Data Source="data/mydatbase.mdb", it does not find the file?

0
 

Author Comment

by:tom_burkhardt
ID: 16312633

sonofagun, that worked!!!!
Didn't think you could use a relative path for Server.Mappath; I've always thought you had to put the entire physical path starting from the root directory(i.e:C:\Inetpub\myfoldermysubfolder\etc).
0
 

Author Comment

by:tom_burkhardt
ID: 16312654
well, at least for databases. I have used the MapPath for other file types.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:tom_burkhardt
ID: 16312688
ooops .... typo, meant to say :

well, at least for databases. I have used the MapPath with relative path for other file types.
0
 
LVL 5

Expert Comment

by:intreeg
ID: 16312693
I think the web.config accepts either full or relative for most things...

also just fyi (though you might already know this) the new syntax for web site root is ~/ instead of doing ../../ etc.


Thanks for the A btw!




0
 

Author Comment

by:tom_burkhardt
ID: 16312758
Thanks for the extra comment, no I was not aware of that.

So, if I understand correctly
~/mysite/default.htm

would replace
C:\inetpub\mysite\default.htm ?
0
 

Author Comment

by:tom_burkhardt
ID: 16312842

or is the ~/ only for relative links within a site?
0
 
LVL 5

Expert Comment

by:intreeg
ID: 16312858
Not exactly, more like...

If the full Filesystem path to your webfolder is c:\intepub\mysite, then you have a subfolder called sub1 that contains file1.aspx. You can reference the file1.aspx from anywhere in your site by using "~/sub1/file1.aspx" or to get your "default.aspx" in your root you would use "~/default.aspx"

Its just a shortcut from doing ../default.aspx from a file in the sub1 folder.

I have a feeling im not explaing this very well... i hope that made sense. It is only used for relative paths inside of the website.
0
 

Author Comment

by:tom_burkhardt
ID: 16312908

 Thanks, that made perfect sense!
0
 

Author Comment

by:tom_burkhardt
ID: 16312918

 actually, it seems this is yet another thought Microsoft has "borrowed" from the Unix systems.
0
 
LVL 5

Expert Comment

by:intreeg
ID: 16313171
lol, very true... but really can we complain about that? Vista looks to use more than a few 'Nix concepts... and right on! Maybe we can count down on the virus, worm etc epidemic using some good ol' fashion DONT RUN AS ROOT JACK@$$ theory.....

This conversation can easily and has started to drift, so I will leave it at that...
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month20 days, 9 hours left to enroll

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question