By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,253 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,253 IT Pros & Developers. It's quick & easy.

dll config issue...

P: n/a
I have a "business logic" dll that has a connectionString and some
my.mysettings.default values that I need to change based on the system
the dll is running on (i.e.: a development, test vs. a production
system).

So far, I've not been successful in getting the .dll to access
connectionStrings and other settings from the calling applications
web.config file (sample below).

1) How do I get a connectionString into a .dll at runtime (and
overwrite the "default" one compiled in)?
2) How do I get a my.mysettings.default setting into a .dll at runtime
(and overwrite the "default" one compiled in)?

The only thing that works below (in terms of accessing from the .dll)
is the "key" in the <appSettingssection - but that's going through
Configuration.ConfigurationManager.AppSettings(key String), not
my.mysettings (which is OK, I guess, but it doesn't work for
connectionStrings). Other than that one, I can't access anything else
in the web.config file from the .dll at runtime.
--------------------
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="MyWebApp.My.MySettings"
type="System.Configuration.ClientSettingsSection, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
<section name="MyDll.My.MySettings"
type="System.Configuration.ClientSettingsSection, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
</configSections>
<appSettings>
<add key ="CAN_READ_THIS_FROM_BOTH_WEB_AND_DLL" value ="IT_WORKS"/
>
</appSettings>

<connectionStrings>
<add name="aConnectionString" connectionString="Data
Source=localhost;Initial Catalog=&quot;C:\PROGRAM FILES\MICROSOFT SQL
SERVER\MSSQL.1\MSSQL\DATA\GENERIC.MDF&quot;;Integr ated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>

<applicationSettings>
<MyWebApp.My.MySettings>
<setting name="ONLY_FROM_WEB_APP" serializeAs="String">
<value>Can only access this from the web app</value>
</setting>
</MyWebApp.My.MySettings>
<MyDll.My.MySettings>
<setting name="WORTHLESS" serializeAs="String">
<value>Can't access this value from anywhere</value>
</setting>
</MyDll.My.MySettings>
</applicationSettings>

</configuration>

Oct 2 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
....nevermind - figured it out.

Oct 3 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.