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

How to access app.config in a library

P: n/a
bz
Hi,

I have a library project that implements a Business Layer for a web
and a desktop application
All my business classes are in this lib, so I have here the connection
string to database as app setting (in app.config

The section in app.config looks like this

<applicationSettings>
<BB.InsuranceService.Lib.Properties.Settings>
<setting name="BBAssurConnString" serializeAs="String">
<value>Data Source=.\SQLEXPRESS;Initial
Catalog=MyDB;Integrated Security=True</value>
</setting>
</BB.InsuranceService.Lib.Properties.Settings>
</applicationSettings>

App.config belongs to project name BB.InsuranceService.Lib

I have a utility class with a Static member which should return the
Connection string, to use it in constuctors of BO, as below

namespace BB.InsuranceService
{
class DBUtility
{
public static string ConnectionString()
{
return
ConfigurationSettings.AppSettings.Get("BBAssurConn String");
}
But I have two problems:
First, I get the following warning:

Warning 1 'System.Configuration.ConfigurationSettings.AppSet tings' is
obsolete: 'This method is obsolete, it has been replaced by
System.Configuration!
System.Configuration.ConfigurationManager.AppSetti ngs...

But I cannot find ConfigurationManager, it is not in
System.Configuration. Where is this?

And the second problem is (and this is a problem), the call to
ConfigurationSettings.AppSettings.Get("BBAssurConn String"); returns
null.

I have the app.config in the same folder as the library project.

And as I mentioned, this library is used by two projects, a web and
and win forms project. Web app has its own web.config (without any
connection string setting) and Win forms project also has its own
app.config file (also without any connection string setting)

Can anyone help me with this, please?

Thanks,
Bogdan

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


P: n/a
Hello bz,

use ConfigurationManager.OpenMappedExeConfiguration
see the description there http://www.codeproject.com/csharp/Sy...figuration.asp
---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
bHi,
b>
bI have a library project that implements a Business Layer for a web
band a desktop application
bAll my business classes are in this lib, so I have here the
bconnection
bstring to database as app setting (in app.config
bThe section in app.config looks like this
b>
b<applicationSettings>
b<BB.InsuranceService.Lib.Properties.Settings>
b<setting name="BBAssurConnString" serializeAs="String">
b<value>Data Source=.\SQLEXPRESS;Initial
bCatalog=MyDB;Integrated Security=True</value>
b</setting>
b</BB.InsuranceService.Lib.Properties.Settings>
b</applicationSettings>
bApp.config belongs to project name BB.InsuranceService.Lib
b>
bI have a utility class with a Static member which should return the
bConnection string, to use it in constuctors of BO, as below
b>
bnamespace BB.InsuranceService
b{
bclass DBUtility
b{
bpublic static string ConnectionString()
b{
breturn
bConfigurationSettings.AppSettings.Get("BBAssurCon nString");
b}
bBut I have two problems:
bFirst, I get the following warning:
bWarning 1 'System.Configuration.ConfigurationSettings.AppSet tings' is
bobsolete: 'This method is obsolete, it has been replaced by
bSystem.Configuration!
bSystem.Configuration.ConfigurationManager.AppSett ings...
b>
bBut I cannot find ConfigurationManager, it is not in
bSystem.Configuration. Where is this?
b>
bAnd the second problem is (and this is a problem), the call to
bConfigurationSettings.AppSettings.Get("BBAssurCon nString"); returns
bnull.
b>
bI have the app.config in the same folder as the library project.
b>
bAnd as I mentioned, this library is used by two projects, a web and
band win forms project. Web app has its own web.config (without any
bconnection string setting) and Win forms project also has its own
bapp.config file (also without any connection string setting)
b>
bCan anyone help me with this, please?
b>
bThanks,
bBogdan
Oct 6 '07 #2

P: n/a

"bz" <bz*****@gmail.comwrote in message
news:11**********************@w3g2000hsg.googlegro ups.com...
Hi,

I have a library project that implements a Business Layer for a web
and a desktop application
All my business classes are in this lib, so I have here the connection
string to database as app setting (in app.config

The section in app.config looks like this

<applicationSettings>
<BB.InsuranceService.Lib.Properties.Settings>
<setting name="BBAssurConnString" serializeAs="String">
<value>Data Source=.\SQLEXPRESS;Initial
Catalog=MyDB;Integrated Security=True</value>
</setting>
</BB.InsuranceService.Lib.Properties.Settings>
</applicationSettings>

App.config belongs to project name BB.InsuranceService.Lib

I have a utility class with a Static member which should return the
Connection string, to use it in constuctors of BO, as below

namespace BB.InsuranceService
{
class DBUtility
{
public static string ConnectionString()
{
return
ConfigurationSettings.AppSettings.Get("BBAssurConn String");
}
But I have two problems:
First, I get the following warning:

Warning 1 'System.Configuration.ConfigurationSettings.AppSet tings' is
obsolete: 'This method is obsolete, it has been replaced by
System.Configuration!
System.Configuration.ConfigurationManager.AppSetti ngs...

But I cannot find ConfigurationManager, it is not in
System.Configuration. Where is this?

And the second problem is (and this is a problem), the call to
ConfigurationSettings.AppSettings.Get("BBAssurConn String"); returns
null.

I have the app.config in the same folder as the library project.

And as I mentioned, this library is used by two projects, a web and
and win forms project. Web app has its own web.config (without any
connection string setting) and Win forms project also has its own
app.config file (also without any connection string setting)

Can anyone help me with this, please?
For the Web application, if there is not a physical separation of the tiers,
meaning the Web server has the logical tiers of UI, Business, and Data
Access Layer on the Web server, then Web.config can have an AppSettings in
it for the SQL connection string. Web.config is the Root.Config for the
entire Web application, The logical tiers will look for the AppSetting to
be in the Web.config

For the Windows desktop application, a DLL.Config can be applied to a DLL.
The way you use a DLL.config for a DLL is the DLL.Config must be in the
Windows/system32 directory where DLLHOST.exe resides that host all DLL(s).
The other options you may have is to create you own DLLConfig.INI file and
make your DLL get the connection string information for the INI file, or you
pass the Connection string as a parameter to the Business Object.

Oct 7 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.