DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Feb 2004
    Posts
    24

    connectionString in web.Config

    Hello,

    I'm trying to use Server.MapPath("xxx/xxx.mdb") in my web.Config file.

    I used:
    <appSettings>
    <add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath + "\xxx\xxx.mdb" />
    </appSettings>

    ... and I got a Configuration Error: The '+' character, hexadecimal value 0x2B, cannot begin with a name. Line 4, position 85.

    If I Dim the full statement in a Sub/Function, it works - but I'm trying to get more use out of my web.Config file.

    Thanks,
    ~ Ben

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Config entries are not executable, so they may not include code. You can, however, do this:

    <add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}\xxx\xxx.mdb" />

    Then in your code-behind, read the ConnectionString and use String.Format to insert the path:

    ConnectionString = String.Format(ConnectionString, Server.MapPath)
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Feb 2004
    Posts
    24
    Thanks Phil for that insight on config not being executable...

    I ended up putting in my web.Config:
    <add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" />

    ... and in my VB code:
    Dim connectionString As String = ConfigurationSettings.AppSettings("ConnectionString") & Server.MapPath("xxx/xxx.mdb")

    I couldn't quite get using the {0} and String.Format to work.

    Thanks again for helping out a college student

    ~ Ben

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links