-
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
-
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!
-
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks