473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to access app.config in a library

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
2 18123
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: joe | last post by:
Some time ago I set up an ASP application that used a login page which checked a username and password against a database to determine a users authorization to access certain pages on the site....
1
by: Microsoft News | last post by:
I have a web server sitting on computer 1, (QA1). Out on the network on my main server I have a folder with a zip file in it. All I want is for the web services that are on the web server to pick...
10
by: bradtm | last post by:
So I have this hierarchy: + Solution | |--- + Class Library Project | | | |--- LogError.vb | |--- + ASP .NET Web Application |
3
by: Shailesh Humbad | last post by:
I figured out what was causing the "Access is Denied" error when calling functions from referenced DLLs in my service. I've tried to be very detailed, so bear with me. It turns out that...
0
by: John Dalberg | last post by:
I am getting the error below many times when I am trying to use the Enterprise Library. The solution seems to be a reboot. I am using Windows 2003 as my dev box. The error also happens with other...
1
by: dhussong | last post by:
I am attempting to use Visual Studio 2005 (Visual Basic) and the Enterprise Library 2.0 Data Access Application Block with a Microsoft Access database. I know the names of my Access databases but I...
0
by: Anonieko | last post by:
A lot of times, web hostings for ASPNET 2.0 will offer only MS Access DB for database for basic plan, a question often asked is how can I use the membership services, role, web parts services, etc ...
3
by: daokfella | last post by:
In my solution, I have a project that is my data access layer. This layer simply consists of strongly-typed datasets created by dragging tables from the server explorer into the dataset designer....
8
by: ajos | last post by:
hi frnds, im trying to convert my servlets database configuration from ms access to mysql database.however im getting some error like no driver found exception. to verify this error ive...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.