Bookmark and Share

Thursday, March 13, 2008

Load AppSettings and ConnectionString from an external shared file

You can share from different .Net applications (web & windows form) the same connection string and the same application configuration without duplicates, you can change the web.config with the code:

  
<connectionStrings configSource="@ConnectionStrings.config">
  </connectionStrings>

You ca do the same to the AppSettings:

  <appSettings configSource="@AppSettings.config">
  </appSettings>

If you are using the EnterpriseLibrary here is the right configuration string: 

<
configuration>
  <configSections>
    <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> . . . .

And add:
  <enterpriseLibrary.ConfigurationSource selectedSource="File Configuration Source">
    <sources>
      <add name="File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        filePath="@EnterpriseLib.config" />
    </sources>
  </enterpriseLibrary.ConfigurationSource> 

Hope it helps...

No comments:

Post a Comment