473,796 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reusing connection strings in config files?

Jen
..NET 2.0 introduced the <connectionStri ngs> section in .config files,
but how do I reuse the connection strings defined under
<connectionStri ngs> in other parts of the config files?

<connectionStri ngs>
<add name="connStr1" .../>
</connectionStrin gs>

Now I want to reuse the connection string defined by the name
"connStr1" in 25 other places in the same configuration file by
referencing the "connStr1" name instead of hard-coding the same
connection string 25 times. How do I do this? (I know how they can be
referenced using ConfigurationMa nager programmaticall y. This is WITHIN
the same config file, non-programatticall y.)

Jun 14 '06 #1
1 1783
Jen,
Sorry but this simply "does not compute". If you already have it in one
place, why on earth do you need to have it in 25 more places? A config file
is nothing but an xml document - a text file. It has no "internal
programmatic awareness" of itself.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Jen" wrote:
..NET 2.0 introduced the <connectionStri ngs> section in .config files,
but how do I reuse the connection strings defined under
<connectionStri ngs> in other parts of the config files?

<connectionStri ngs>
<add name="connStr1" .../>
</connectionStrin gs>

Now I want to reuse the connection string defined by the name
"connStr1" in 25 other places in the same configuration file by
referencing the "connStr1" name instead of hard-coding the same
connection string 25 times. How do I do this? (I know how they can be
referenced using ConfigurationMa nager programmaticall y. This is WITHIN
the same config file, non-programatticall y.)

Jun 14 '06 #2

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

Similar topics

1
2870
by: stewart | last post by:
I've got the standard SqlCacheDependency working just fine , ie. I've defined (and encrypted) the connectionStrings section in the web.config, and I've also defined an an sqlCacheDependency in the caching section. So, in my code I add an item to the cache with an sqlCacheDependency, referencing the named sqlCacheDependency in the web.config and the database table it is to be based on (have enabled notificiations for that table). Fine. ...
14
3508
by: WebMatrix | last post by:
Hello, I have developed a web application that connects to 2 different database servers. The connection strings with db username + password are stored in web.config file. After a code review, one developer suggested that it's a security flaw; therefore connection strings should be kept somewhere else or encrypted. My argument is that web.config file is protected by IIS and Windows security which is the case. And another argument is that...
3
3944
by: ad | last post by:
I have a web application and a class library in a solution. The class library is make of typed datasets, and include many Table in it. The connection strings of the TableAdapters is come from the app.config of that class library. The Web application refer the class library, and the connection strings of WebApp is come from the web.config of it. It is ok in developing step, I can make both connection string identical in
4
5381
by: Matt Colegrove | last post by:
I'm working on a web app that is published to a hosting service. I'm developing it on my local PC with VS 2005 and SQL Express. The hosting service DB is SQL Server 2000. I have two connectionStrings defined in my web.config file, one for the development db and another for the production db. When I publish my app to the hosting site, I rename the two connection strings so that the production string will be the active string in the...
2
1841
by: =?Utf-8?B?U2JhdGNodQ==?= | last post by:
How will i read connection strings in all web.config files in one particualr machine?
2
3066
by: Mike P | last post by:
I've always put my connection strings in the web.config, but I've just recently seen an example of a connection string in a resource file. What are the advantages of doing this, and could you do it for other stuff that you would normally put in your web.config? *** Sent via Developersdex http://www.developersdex.com ***
11
2288
by: =?Utf-8?B?UGF0Qg==?= | last post by:
Is there a way in ASP.NET 2.0 to have different connection strings settings in a web.config files that are dynamically used based upon the server that the web application is running on? For example, you have have two test web servers (TEST1 and TEST2) and a production web server (PROD1). Each of these connection to a different database for general data access and for membership/role providers. <connectionStrings> <add name="Test1DB"...
9
2776
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a question about storing the connection strings to the database in a config file or database. My manager wants me to store all the connection strings in a database, but I think it is easier and faster to store the connection strings in the config file. I was wondering if anyone has any opinion on this issue so that I can convince my manager. Thanks.
2
5397
by: Johnson | last post by:
I'm trying to fix a "sub optimal" situation with respect to connection string management. Your thoughtful responses will be appreciated. I just started with a new client who has a bunch of legacy ASP.NET applications that all manage connection strings in Web.config the same way, like this: This client has one Web.config file per application, and that one Web.config file is duplicated across all environments (i.e., dev machines, test,...
0
10457
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10231
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...
0
10013
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
9054
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
7550
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
5443
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
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.