Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > ASP.Net > Server.MapPath in Web.Config


Reply
 
Thread Tools Display Modes
  #1  
Old 02-24-2007, 04:04 AM
Eduardo Lorenzo's Avatar
Eduardo Lorenzo Eduardo Lorenzo is offline
Senior Contributor
 
Join Date: Jun 2006
Location: Manila, Philippines
Posts: 846
Default Server.MapPath in Web.Config


Ok, here it is.

I put this:

Quote:
<appSettings>
<add key="SqlConnStrO" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Documents and Settings/Desktop/dbJoyMarble.mdb;Persist Security Info=False;"/>
</appSettings>
in the Web.Config. But when I try to use Server.MapPath, it gives back an error! Server --- not defined.

What gives?
__________________
Pinoy ako.. ipinagmamalaki ko.
Reply With Quote
  #2  
Old 02-24-2007, 04:22 AM
Eduardo Lorenzo's Avatar
Eduardo Lorenzo Eduardo Lorenzo is offline
Senior Contributor
 
Join Date: Jun 2006
Location: Manila, Philippines
Posts: 846
Default

also.. I am calling the appsetting in my DAL, in the class, and Server.MapPath also does not function there.
__________________
Pinoy ako.. ipinagmamalaki ko.
Reply With Quote
  #3  
Old 02-24-2007, 05:58 AM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

Is this a webforms application? If it is, then you don't need Server.MapPath to find the web.config. If it isn't, then duh.
__________________
~ Quod non mortiferum, fortiorem me facit ~

Avatar by lebb
Reply With Quote
  #4  
Old 02-25-2007, 04:38 PM
Eduardo Lorenzo's Avatar
Eduardo Lorenzo Eduardo Lorenzo is offline
Senior Contributor
 
Join Date: Jun 2006
Location: Manila, Philippines
Posts: 846
Default

yes this is a webform, that's why I have a web.config

I'm not using server.mappath to find web.config, I'm trying to change the connection string. The static connection string "C:/.../mytable.mdb" won't work because the table is now located in the webhost and I can't seem to use the url "www.sitename.com/tables/mytable.mdb" as part of the connection string.
__________________
Pinoy ako.. ipinagmamalaki ko.
Reply With Quote
  #5  
Old 02-27-2007, 08:09 PM
shaul_ahuva shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

Most hosting providers will give you either the physical path of your site or an ODBC DSN to use. Do you have anything from them regarding the physical location of your files?
Reply With Quote
  #6  
Old 02-27-2007, 08:20 PM
Eduardo Lorenzo's Avatar
Eduardo Lorenzo Eduardo Lorenzo is offline
Senior Contributor
 
Join Date: Jun 2006
Location: Manila, Philippines
Posts: 846
Default

just the URL.

I have resolved this issue (a bit) by placing the Server.MapPath call within the pages and the Driver, password, and other connection string information in Web.Config.
__________________
Pinoy ako.. ipinagmamalaki ko.
Reply With Quote
  #7  
Old 02-27-2007, 08:33 PM
shaul_ahuva shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

Quote:
I have resolved this issue (a bit) by placing the Server.MapPath call within the pages...
That was going to be my next suggestion with the caveat that you should check to ensure you site is not being hosted in a web farm/garden (which would obviously cause serious problems with any file references).
Reply With Quote
  #8  
Old 02-28-2007, 09:58 AM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

The whole point of a .config file is that it probably changes from machine to machine. I have a hardcoded path in my web.config on my test machine. I have a different hardcoded path in my web.config on my production machine. When I move files to production, I just don't change the config.

Using .NET 2.0, Microsoft has a Tool (Web Deployment Projects) that makes the process a little easier. See Scott Guthrie's blog here: http://weblogs.asp.net/scottgu/archi...06/429723.aspx
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->