How to access app.config in a library

B

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("BBAssurConnString");
}


But I have two problems:
First, I get the following warning:

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

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("BBAssurConnString"); 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
 
M

Michael Nemtsev

Hello bz,

use ConfigurationManager.OpenMappedExeConfiguration
see the description there http://www.codeproject.com/csharp/SystemConfiguration.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


b> Hi,
b>
b> I have a library project that implements a Business Layer for a web
b> and a desktop application
b> All my business classes are in this lib, so I have here the
b> connection
b> string to database as app setting (in app.config
b> The 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
b> Catalog=MyDB;Integrated Security=True</value>
b> </setting>
b> </BB.InsuranceService.Lib.Properties.Settings>
b> </applicationSettings>
b> App.config belongs to project name BB.InsuranceService.Lib
b>
b> I have a utility class with a Static member which should return the
b> Connection string, to use it in constuctors of BO, as below
b>
b> namespace BB.InsuranceService
b> {
b> class DBUtility
b> {
b> public static string ConnectionString()
b> {
b> return
b> ConfigurationSettings.AppSettings.Get("BBAssurConnString");
b> }
b> But I have two problems:
b> First, I get the following warning:
b> Warning 1 'System.Configuration.ConfigurationSettings.AppSettings' is
b> obsolete: 'This method is obsolete, it has been replaced by
b> System.Configuration!
b> System.Configuration.ConfigurationManager.AppSettings...
b>
b> But I cannot find ConfigurationManager, it is not in
b> System.Configuration. Where is this?
b>
b> And the second problem is (and this is a problem), the call to
b> ConfigurationSettings.AppSettings.Get("BBAssurConnString"); returns
b> null.
b>
b> I have the app.config in the same folder as the library project.
b>
b> And as I mentioned, this library is used by two projects, a web and
b> and win forms project. Web app has its own web.config (without any
b> connection string setting) and Win forms project also has its own
b> app.config file (also without any connection string setting)
b>
b> Can anyone help me with this, please?
b>
b> Thanks,
b> Bogdan
 
M

Mr. Arnold

bz said:
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("BBAssurConnString");
}


But I have two problems:
First, I get the following warning:

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

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("BBAssurConnString"); 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.
 
V

Vikas Dangwal

By default you wont get the ConfigurationManager. You need to add the System.Configuration DLL mannually from the Add Reference. Once you add this dll and get the ConfigurationManager, you can see the options to open the exe configuration.



bz wrote:

How to access app.config in a library
05-Oct-07

Hi

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

The section in app.config looks like thi

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

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

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

namespace BB.InsuranceServic

class DBUtilit

public static string ConnectionString(

retur
ConfigurationSettings.AppSettings.Get("BBAssurConnString")


But I have two problems
First, I get the following warning

Warning 1 'System.Configuration.ConfigurationSettings.AppSettings' i
obsolete: 'This method is obsolete, it has been replaced b
System.Configuration
System.Configuration.ConfigurationManager.AppSettings..

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

And the second problem is (and this is a problem), the call t
ConfigurationSettings.AppSettings.Get("BBAssurConnString"); return
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 an
and win forms project. Web app has its own web.config (without an
connection string setting) and Win forms project also has its ow
app.config file (also without any connection string setting

Can anyone help me with this, please

Thanks
Bogdan

Previous Posts In This Thread:

How to access app.config in a library
Hi

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

The section in app.config looks like thi

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

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

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

namespace BB.InsuranceServic

class DBUtilit

public static string ConnectionString(

retur
ConfigurationSettings.AppSettings.Get("BBAssurConnString")


But I have two problems
First, I get the following warning

Warning 1 'System.Configuration.ConfigurationSettings.AppSettings' i
obsolete: 'This method is obsolete, it has been replaced b
System.Configuration
System.Configuration.ConfigurationManager.AppSettings..

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

And the second problem is (and this is a problem), the call t
ConfigurationSettings.AppSettings.Get("BBAssurConnString"); return
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 an
and win forms project. Web app has its own web.config (without an
connection string setting) and Win forms project also has its ow
app.config file (also without any connection string setting)

Can anyone help me with this, please?

Thanks,
Bogdan

Hello bz,use ConfigurationManager.
Hello bz,

use ConfigurationManager.OpenMappedExeConfiguration
see the description there http://www.codeproject.com/csharp/SystemConfiguration.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


b> Hi,
b>
b> I have a library project that implements a Business Layer for a web
b> and a desktop application
b> All my business classes are in this lib, so I have here the
b> connection
b> string to database as app setting (in app.config
b> The 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
b> Catalog=MyDB;Integrated Security=True</value>
b> </setting>
b> </BB.InsuranceService.Lib.Properties.Settings>
b> </applicationSettings>
b> App.config belongs to project name BB.InsuranceService.Lib
b>
b> I have a utility class with a Static member which should return the
b> Connection string, to use it in constuctors of BO, as below
b>
b> namespace BB.InsuranceService
b> {
b> class DBUtility
b> {
b> public static string ConnectionString()
b> {
b> return
b> ConfigurationSettings.AppSettings.Get("BBAssurConnString");
b> }
b> But I have two problems:
b> First, I get the following warning:
b> Warning 1 'System.Configuration.ConfigurationSettings.AppSettings' is
b> obsolete: 'This method is obsolete, it has been replaced by
b> System.Configuration!
b> System.Configuration.ConfigurationManager.AppSettings...
b>
b> But I cannot find ConfigurationManager, it is not in
b> System.Configuration. Where is this?
b>
b> And the second problem is (and this is a problem), the call to
b> ConfigurationSettings.AppSettings.Get("BBAssurConnString"); returns
b> null.
b>
b> I have the app.config in the same folder as the library project.
b>
b> And as I mentioned, this library is used by two projects, a web and
b> and win forms project. Web app has its own web.config (without any
b> connection string setting) and Win forms project also has its own
b> app.config file (also without any connection string setting)
b>
b> Can anyone help me with this, please?
b>
b> Thanks,
b> Bogdan

Re: How to access app.config in a library

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.


Submitted via EggHeadCafe - Software Developer Portal of Choice
Telerik RadControls For Silverlight (3 and 4) Q1 2010
http://www.eggheadcafe.com/tutorial...2-7a7fa36e63a1/telerik-radcontrols-for-s.aspx
 
A

Arne Vajhøj

By default you wont get the ConfigurationManager. You need to add the System.Configuration DLL mannually from the Add Reference. Once you add this dll and get the ConfigurationManager, you can see the options to open the exe configuration.
How to access app.config in a library
05-Oct-07
But I cannot find ConfigurationManager, it is not in
System.Configuration. Where is this?

I would think the original poster had figured it out during
the two and a half year ...

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top