473,421 Members | 1,491 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,421 software developers and data experts.

ConfigurationSettings in Class Library

I'm writing a class library for my web app data access, but don't want to
hard code the database connection string in the class. Nor do I want to
pass the connection string in from the web app every time I access it. I
want to define the connection string in the web app ConfigurationSettings
and let the class library reference it itself whenever it needs a
connection.

How can I do this?
Nov 19 '05 #1
3 1525
Hello ?,

I don't understand why you don't want to put the connection string in the
web.config file. You can use can add a key to the appSettings node and
reference it in code:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="myconnstring" value="connectionstringgoeshere" />

In code:

db.connstring = ConfigurationSettings.AppSettings("myconnstring")

Ken

"Random" <ci*******@hotmail.com> wrote in message
news:OG**************@TK2MSFTNGP09.phx.gbl...
I'm writing a class library for my web app data access, but don't want to
hard code the database connection string in the class. Nor do I want to
pass the connection string in from the web app every time I access it. I
want to define the connection string in the web app ConfigurationSettings
and let the class library reference it itself whenever it needs a
connection.

How can I do this?


Nov 19 '05 #2
That's precisely where I do want to put it. My class library, however, is
not a part of the web application, but would be a referenced dll that runs
within the HttpContext.
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:ue**************@TK2MSFTNGP15.phx.gbl...
Hello ?,

I don't understand why you don't want to put the connection string in the
web.config file. You can use can add a key to the appSettings node and
reference it in code:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="myconnstring" value="connectionstringgoeshere" />

In code:

db.connstring = ConfigurationSettings.AppSettings("myconnstring")

Ken

"Random" <ci*******@hotmail.com> wrote in message
news:OG**************@TK2MSFTNGP09.phx.gbl...
I'm writing a class library for my web app data access, but don't want to
hard code the database connection string in the class. Nor do I want to
pass the connection string in from the web app every time I access it. I
want to define the connection string in the web app ConfigurationSettings
and let the class library reference it itself whenever it needs a
connection.

How can I do this?

Nov 19 '05 #3
Hello Random,

So?

ConfigurationSettings references the config file of the application using
it. This should not be a problem for you. A referenced assembly can use the
ConfigurationSettings of the parent application.

--
Matt Berther
http://www.mattberther.com
That's precisely where I do want to put it. My class library,
however, is not a part of the web application, but would be a
referenced dll that runs within the HttpContext.

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in
message news:ue**************@TK2MSFTNGP15.phx.gbl...
Hello ?,

I don't understand why you don't want to put the connection string in
the web.config file. You can use can add a key to the appSettings
node and reference it in code:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="myconnstring" value="connectionstringgoeshere" />
In code:

db.connstring = ConfigurationSettings.AppSettings("myconnstring")

Ken

"Random" <ci*******@hotmail.com> wrote in message
news:OG**************@TK2MSFTNGP09.phx.gbl...
I'm writing a class library for my web app data access, but don't
want to hard code the database connection string in the class. Nor
do I want to pass the connection string in from the web app every
time I access it. I want to define the connection string in the web
app ConfigurationSettings and let the class library reference it
itself whenever it needs a connection.

How can I do this?

Nov 19 '05 #4

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

Similar topics

3
by: serge calderara | last post by:
Dear all, I have define a configuration file for my application with different section groups and settings belonging to each individual group like as follow : ...
0
by: awf_ng | last post by:
I'm writing a MMC snapin in .NET. The problem I have is that I need to access configuration information, which needs to be stored in the App.config file. Being a MMC snapin, if I use the...
4
by: harvie wang | last post by:
In .Net,Through System.Configuration.ConfigurationSettings Get Application's Settings I can't find the Configuration Value from Register Where the ConfigurationSettings saved? How to Read it...
4
by: JMD | last post by:
I am curious to know if there are performance issues in choosing between A and B. Which performs best? A. store string values in the web.config and pull them using...
3
by: Andrew Fisher | last post by:
Hi all, I have set up some config options in the web.config file and have successfully used them in my test pages. When I came to abstract my code from the design - by using code behind files,...
1
by: Brad Wood | last post by:
I have a 1.1 web service that creates multiple threads and makes an http call within each thread. When many threads are created, the service fails every on other call with one of these 2 errors: ...
5
by: Simon Hart | last post by:
Hi, I want to use the ConfigurationSettings.AppSettings from within a .NET class library that gets called. If using the above class, what would the name of the config file be? would this be the...
1
by: Ken | last post by:
I'm currently using 1.1. Is there any way using the value of a ConfigurationSettings.AppSettings as a key of ConfigurationSettings.AppSettings.Tosting( )]? for example in web.config <add...
2
by: mark4asp | last post by:
In trying to get the C# conversion code for Head First Design Patterns to work I came accross a number of warnings. e.g. Warning Number: 10 Description: ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...
1
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...
0
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...

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.