Last post Jul 22, 2009 05:17 PM by brettemiller
Member
10 Points
9 Posts
Jul 21, 2009 11:39 AM|brettemiller|LINK
I cannot seem to get my externally configured connectionstrings section to be loaded on the app startup. Any advice?
Code:
ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["default"]; if (settings == null || settings.ConnectionString.Trim() == "") throw new ConfigurationErrorsException("No default connection string.");
Error:
System.Configuration.ConfigurationErrorsException: No default connection string.
web.config:
<configuration> <configSections> <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </configSections> <enterpriseLibrary.ConfigurationSource selectedSource="File Configuration Source"> <sources> <add name="File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" filePath="demo.config" /> </sources> </enterpriseLibrary.ConfigurationSource> </configuration>
and demo.config:
<?xml version="1.0"?> <configuration> <connectionStrings> <clear/> <add name="default" connectionString="User Id=etc., etc."/> </connectionStrings> </configuration>
Jul 22, 2009 05:17 PM|brettemiller|LINK
Configuration settings in FileConfigSource are are not accessible via ConfigurationManager.
The best solution here is to use configSource attribute of the individual config sections as Tom Hollander points out in his blog:
http://blogs.msdn.com/tomholl/archive/2006/04/02/entlib2externalconfig.aspx
In this case:
<connectionStrings configSource="demo.config" />
where demo.config includes only the configuration element of interest:
<connectionStrings> <add name="Tom's Connection" connectionString="Database=EntLibQuickStarts;Server=(local)\SQLEXPRESS;Integrated Security=SSPI;" providerName="System.Data.SqlClient" /></connectionStrings>
Member
10 Points
9 Posts
FileConfigurationSource Not Loading
Jul 21, 2009 11:39 AM|brettemiller|LINK
I cannot seem to get my externally configured connectionstrings section to be loaded on the app startup. Any advice?
Code:
Error:
System.Configuration.ConfigurationErrorsException: No default connection string.
web.config:
and demo.config:
Member
10 Points
9 Posts
Re: FileConfigurationSource Not Loading
Jul 22, 2009 05:17 PM|brettemiller|LINK
Configuration settings in FileConfigSource are are not accessible via ConfigurationManager.
The best solution here is to use configSource attribute of the individual config sections as Tom Hollander points out in his blog:
http://blogs.msdn.com/tomholl/archive/2006/04/02/entlib2externalconfig.aspx
In this case:
<div style="color: Black; background-color: White;" mce_style="color: Black; background-color: White;"> </div>where demo.config includes only the configuration element of interest:
<div style="color: Black; background-color: White;" mce_style="color: Black; background-color: White;"> </div></div>