473,757 Members | 5,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

App.config and class libraries

Hi,

I am building a class library and want to store a connection string in a
configuration file.

I've read around and it appears that this is not possible because "by
design, class libraries don't have their own config file - they read the
config files from the application they are housed in, such as a WinForm app
or ASP.NET site "

So, with that in mind, is there an alternative solution?

Many thanks,

CR
Nov 17 '05 #1
12 2259

"CodeRazor" <Co*******@disc ussions.microso ft.com> wrote in message
news:8F******** *************** ***********@mic rosoft.com...
Hi,

I am building a class library and want to store a connection string in a
configuration file.

I've read around and it appears that this is not possible because "by
design, class libraries don't have their own config file - they read the
config files from the application they are housed in, such as a WinForm
app
or ASP.NET site "

So, with that in mind, is there an alternative solution?

Presumeably the code is only of real use when used in a Windows/Web app so
use the app/web.config file of the application that is using your code
library
and define the connection string there? Use the registry?

HTH

AP
Nottingham - UK
Nov 17 '05 #2

"CodeRazor" <Co*******@disc ussions.microso ft.com> wrote in message
news:8F******** *************** ***********@mic rosoft.com...
Hi,

I am building a class library and want to store a connection string in a
configuration file.

I've read around and it appears that this is not possible because "by
design, class libraries don't have their own config file - they read the
config files from the application they are housed in, such as a WinForm
app
or ASP.NET site "

So, with that in mind, is there an alternative solution?

Presumeably the code is only of real use when used in a Windows/Web app so
use the app/web.config file of the application that is using your code
library
and define the connection string there? Use the registry?

HTH

AP
Nottingham - UK
Nov 17 '05 #3
Your .dll (read .NET code library) should NOT be dependent upon anything.

If one of the objects you expose needs a connection string to work, you
should provide a property accessor to enable the user of your library to
get/set the string.

A .dll should operate as a "black box", i.e. you know what you need to put
in and you know what you expect to get out; anyone using your library does
not want to have to remember to copy the config file too (even you won't want
to do that)

--
Of all words of tongue and pen, the saddest are: "It might have been"

Bill.Richards @ greyskin .co .uk
http://greyskin.co.uk
"CodeRazor" wrote:
Hi,

I am building a class library and want to store a connection string in a
configuration file.

I've read around and it appears that this is not possible because "by
design, class libraries don't have their own config file - they read the
config files from the application they are housed in, such as a WinForm app
or ASP.NET site "

So, with that in mind, is there an alternative solution?

Many thanks,

CR

Nov 17 '05 #4
Your .dll (read .NET code library) should NOT be dependent upon anything.

If one of the objects you expose needs a connection string to work, you
should provide a property accessor to enable the user of your library to
get/set the string.

A .dll should operate as a "black box", i.e. you know what you need to put
in and you know what you expect to get out; anyone using your library does
not want to have to remember to copy the config file too (even you won't want
to do that)

--
Of all words of tongue and pen, the saddest are: "It might have been"

Bill.Richards @ greyskin .co .uk
http://greyskin.co.uk
"CodeRazor" wrote:
Hi,

I am building a class library and want to store a connection string in a
configuration file.

I've read around and it appears that this is not possible because "by
design, class libraries don't have their own config file - they read the
config files from the application they are housed in, such as a WinForm app
or ASP.NET site "

So, with that in mind, is there an alternative solution?

Many thanks,

CR

Nov 17 '05 #5
Hi,

You can do a couple of things:

1- Force the calling app to initialize it, this works better in an escenario
like yours, where only a couple of values needs to be defined.
2- Provide a config file and parse it yourself, depending of the requirement
this can be stored in the user's application data directory or the
installed location,
3- You can always store info in your old friend , the registry :) ,

OT: I just did a backup of my registry and it 's over 120 MB !!! and this
is computer has less than one year of use
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"CodeRazor" <Co*******@disc ussions.microso ft.com> wrote in message
news:8F******** *************** ***********@mic rosoft.com...
Hi,

I am building a class library and want to store a connection string in a
configuration file.

I've read around and it appears that this is not possible because "by
design, class libraries don't have their own config file - they read the
config files from the application they are housed in, such as a WinForm
app
or ASP.NET site "

So, with that in mind, is there an alternative solution?

Many thanks,

CR

Nov 17 '05 #6
Hi,

You can do a couple of things:

1- Force the calling app to initialize it, this works better in an escenario
like yours, where only a couple of values needs to be defined.
2- Provide a config file and parse it yourself, depending of the requirement
this can be stored in the user's application data directory or the
installed location,
3- You can always store info in your old friend , the registry :) ,

OT: I just did a backup of my registry and it 's over 120 MB !!! and this
is computer has less than one year of use
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"CodeRazor" <Co*******@disc ussions.microso ft.com> wrote in message
news:8F******** *************** ***********@mic rosoft.com...
Hi,

I am building a class library and want to store a connection string in a
configuration file.

I've read around and it appears that this is not possible because "by
design, class libraries don't have their own config file - they read the
config files from the application they are housed in, such as a WinForm
app
or ASP.NET site "

So, with that in mind, is there an alternative solution?

Many thanks,

CR

Nov 17 '05 #7
"billr" <bi***@discussi ons.microsoft.c om> wrote in message
news:18******** *************** ***********@mic rosoft.com...
Your .dll (read .NET code library) should NOT be dependent upon anything.
Aren't you making it dependent on the caller setting a connection string?

If one of the objects you expose needs a connection string to work, you
should provide a property accessor to enable the user of your library to
get/set the string.
The question that needs to be answered is, is the connection string part of
the blackness (of the black box) or should it be exposed to the user? Does
the caller even know that a database is used by the dll?

A .dll should operate as a "black box", i.e. you know what you need to put
in and you know what you expect to get out; anyone using your library does
not want to have to remember to copy the config file too (even you won't
want
to do that)
I don't see a difference between requiring the user to copy a configuration
file and requiring them to set a connection string property.

"CodeRazor" wrote:
Hi,

I am building a class library and want to store a connection string in a
configuration file.

I've read around and it appears that this is not possible because "by
design, class libraries don't have their own config file - they read the
config files from the application they are housed in, such as a WinForm
app
or ASP.NET site "

So, with that in mind, is there an alternative solution?

Many thanks,

CR

Nov 17 '05 #8
"billr" <bi***@discussi ons.microsoft.c om> wrote in message
news:18******** *************** ***********@mic rosoft.com...
Your .dll (read .NET code library) should NOT be dependent upon anything.
Aren't you making it dependent on the caller setting a connection string?

If one of the objects you expose needs a connection string to work, you
should provide a property accessor to enable the user of your library to
get/set the string.
The question that needs to be answered is, is the connection string part of
the blackness (of the black box) or should it be exposed to the user? Does
the caller even know that a database is used by the dll?

A .dll should operate as a "black box", i.e. you know what you need to put
in and you know what you expect to get out; anyone using your library does
not want to have to remember to copy the config file too (even you won't
want
to do that)
I don't see a difference between requiring the user to copy a configuration
file and requiring them to set a connection string property.

"CodeRazor" wrote:
Hi,

I am building a class library and want to store a connection string in a
configuration file.

I've read around and it appears that this is not possible because "by
design, class libraries don't have their own config file - they read the
config files from the application they are housed in, such as a WinForm
app
or ASP.NET site "

So, with that in mind, is there an alternative solution?

Many thanks,

CR

Nov 17 '05 #9
I have always felt the class libraries (or more specifically non ui layers)
should have config information passed into them via parameters instead
of having their own config files. I'll assume for the sake of argument
that you have a good reason for doing. So, no need to explain it here.

Here's how to duplicate the System.Configur ation.AppSettin gs class
to be a specific config file. This sample talks about the .NET Compact
Framework
but is applicable to anything.

http://www.eggheadcafe.com/articles/...app_config.asp

--
Robbe Morris - 2004/2005 Microsoft MVP C#

Earn money answering .NET Framework
messageboard posts at EggHeadCafe.com .
http://www.eggheadcafe.com/forums/merit.asp

"CodeRazor" <Co*******@disc ussions.microso ft.com> wrote in message
news:8F******** *************** ***********@mic rosoft.com...
Hi,

I am building a class library and want to store a connection string in a
configuration file.

I've read around and it appears that this is not possible because "by
design, class libraries don't have their own config file - they read the
config files from the application they are housed in, such as a WinForm
app
or ASP.NET site "

So, with that in mind, is there an alternative solution?

Many thanks,

CR

Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
3020
by: Maxim Khesin | last post by:
I want to have a config file with my python proggie, satisfying the following requirements: 1) support key->(value, default) 2) simple and intuitive to read and edit 3) easyly readable into a python datastructure (a dictionary?) 4) not requiring any heavy libraries needed (I am distributing my proggie as a py2exe executable and do not want to bloat the size) can you guys suggest some format for this? thanks, max
3
1819
by: Simon | last post by:
Hi everyone, I really need help with the following: It's common in app development to create numerous projects under one solution that as a whole combine to become your final application. For example I have a solution that has four subprojects - 3 class libraries and 1 windows forms app. Q - Some of these projects - both class library and win form application
3
2224
by: grs | last post by:
Can a class library have a app.config file. Reason for asking is that the microsoft application blocks all read from myApp.exe.config. How can you use the application blocks if you do not have an app.config file. Wish someone from microsoft would answer this, I am at a loss. thanks grs
7
21169
by: A.M-SG | last post by:
Hi, We have a class library application that needs to read some application settings from it's own app.config file. I assume that a ClassLibrary.DLL can have a app.config file, but during
1
1154
by: Erik J Sawyer | last post by:
Is there any documentation on using config files with multiple assemblies? For example, I have a class library installed to the GAC. This is then used in several ASPX pages. If the class library requests settings from a config file, whose will it get: - the app.config that was built with the library (but doesn't appear to have been installed to the GAC) - the web.config of the calling application
4
5023
by: kalyankp78 | last post by:
Hi, I have a question about config files. I have the following in my application.. 1. ASP.NET web application with a web.config 2. C# class library (BL and DAL) with an App.config 3. Two windows Console Applications with their own App.Config. Now I try to retrieve a value in the DAL using this code.
3
18535
by: Fernando Chilvarguer | last post by:
Hello! I created a Class Library project in VS2005. Then, using VS, I was able to add a connection string to the project settings, which automaticaly created an app.config file for me. If I try to access the configuration using System.Configuration.ConfigurationManager, I get a NullException. The code: string connectionString =
8
1657
by: =?Utf-8?B?Y2FsZGVyYXJh?= | last post by:
Dear all, I am building a set of libraries working in a n tiers architecture Some of those libraries use common configuration settings like the database connection string and some others. I can imgaine that I can get one config file per buisness library. What is teh best way and where to store configuration files ? Should I get only one with everything in and located in a particular common
8
3182
by: Bill McCormick | last post by:
<!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. --> I assume "libraries" here to mean DLL's. If that's the case, is there any way to supply both ends of a service (client and host) with the code for the class that describes the contact WITHOUT a duplication in source code? Thanks.
0
9487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9904
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9735
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8736
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6556
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.