none
Server.MapPath in Web.config file RRS feed

  • Question

  • I am trying to connect to an Accesss Database on my website.(I am using ipower.com and Access is supported.)

    The application works on my local server, but I can't get it to work on the remote server. According to my host provider, the connection string should be

    connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\all-holiday-rentals\App_Data\Vacation Rental Sites.mdb")

    However, when I try to use this, it appears that Expressionweb does not like the " inside the Server.MapPath function. I am getting the message"the tag is marked invalid because it has an extra quote"

    Can anyone help?

    Thanks,

    Kevin

     

     

     

    Sunday, September 11, 2011 4:36 PM

Answers

  • You can't use the & "..." construct in the web.config becasue it's an xml file not a code behind file.

    The solution is to split the connectionstring details between your web.config and a code declaration, ideally on a masterpage, so you don't have to repeat it.

    In the web.config:

    <add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" />

    Then in code:

    Dim connectionString As String = ConfigurationSettings.AppSettings("ConnectionString") & Server.MapPath("\all-holiday-rentals\App_Data\Vacation Rental Sites.mdb")

    HTH


    Ian Haynes

    EW V4 Add-Ins
    EW resources, hints and tips
    • Marked as answer by Kevincohr Monday, September 12, 2011 6:36 PM
    Sunday, September 11, 2011 6:21 PM

All replies

  • You can't use the & "..." construct in the web.config becasue it's an xml file not a code behind file.

    The solution is to split the connectionstring details between your web.config and a code declaration, ideally on a masterpage, so you don't have to repeat it.

    In the web.config:

    <add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" />

    Then in code:

    Dim connectionString As String = ConfigurationSettings.AppSettings("ConnectionString") & Server.MapPath("\all-holiday-rentals\App_Data\Vacation Rental Sites.mdb")

    HTH


    Ian Haynes

    EW V4 Add-Ins
    EW resources, hints and tips
    • Marked as answer by Kevincohr Monday, September 12, 2011 6:36 PM
    Sunday, September 11, 2011 6:21 PM
  • Ian,

    Many thanks!

     

    Kevin

     

     

    Monday, September 12, 2011 6:36 PM