473,670 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Web.config and Connection String Management

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, and
production all have the exact same Web.config file, connection strings and
all).

For connection strings they specify one connection string per computer the
application may run on, including all development machines, all test
servers, and production server. The name of each connection string includes
the name of each computer on which the application may run, plus the name of
the connection string. They have a computer naming convention where each dev
box name is an abbreviation of the developer's name. More formally, it's
like this:

[computer name] + [connection string name]

Here are examples:
<!-- Local DEV Workstations -->
<add name="BSmithCon nectionStringTo InventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />
<add name="RJohnsonC onnectionString ToInventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />
<add name="GBrooksCo nnectionStringT oInventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />
<!-- Test Server -->
<add name="Inventory TestServer1Conn ectionStringToI nventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />
<!-- Production Server -->
<add name="Inventory AppServer1Conne ctionStringToIn ventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />

You can see that the connection strings are identical except for the
computer name (which equates to developer name or "environmen t"). So yes,
for each new developer, the connection string must be duplicated and tweaked
(changing only the name).

The application, upon startup, looks to Environment.Mac hineName to determine
which connection string it is to use. So, if the application is running on a
machine for which there is an associated entry in Web.config, then it will
use that connection string.

WHY would they do this? From talking with the existing staff, it appears
that they don't want to deal with versioning Web.config. When moving the
application to different environments or their source control system, they
want to be able to copy the entire application, Web.config and all.

But their strategy (1) creates brittle connection strings, as one must
modify Web.config when moving to a new computer (or hiring another
developer; or a developer leaves...); (2) they in fact have a versioning
problem in that whenever a new connection string is needed, all developer's
copy of Web.config must be updated, etc.

What I'd like to propose to the client - and I'm requesting your thoughtful
responses on this proposal - is to break out the connection strings into a
separate .config file that is referenced from Web.config. This separate
config file would have only one set of connection strings per envoronment
(e..g, 3 connection strings total - one each to the dev, test, and
production). They wouldn't have to modify Web.config whenever a new
developer shows up or they need to run the app on a new computer. These
connection strings would not incorporate the host computer name at all.

Thoughts?

Thanks.

Thoughts? Is there something better I could do - other than breaking out
connection strings into a separate config file that is then referenced from
Web.config?
Nov 10 '08 #1
2 2202
If its 2.0 or above......its already done for you.
Note: In winforms or console apps, you'll have to add a POST BUILD EVENT
for the ExternalConnect ionStrings.conf ig file:
App.Config <<<<<<< This is the filename, not the contents of the file

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>

<connectionStri ngs configSource="E xternalConnecti onStrings.confi g" />

</configuration>

ExternalConnect ionStrings.conf ig<<<<<<< This is the filename, not the
contents of the file

<connectionStri ngs>
<add name="LocalData baseInstance"
connectionStrin g="server=.;dat abase=MYDB;User ID=user1;passwo rd=password1"
providerName="S ystem.Data.SqlC lient"/>

</connectionStrin gs>



"Johnson" <A@B.comwrote in message
news:eI******** *****@TK2MSFTNG P04.phx.gbl...
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, and production all have the exact same Web.config file, connection
strings and all).

For connection strings they specify one connection string per computer the
application may run on, including all development machines, all test
servers, and production server. The name of each connection string
includes the name of each computer on which the application may run, plus
the name of the connection string. They have a computer naming convention
where each dev box name is an abbreviation of the developer's name. More
formally, it's like this:

[computer name] + [connection string name]

Here are examples:
<!-- Local DEV Workstations -->
<add name="BSmithCon nectionStringTo InventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />
<add name="RJohnsonC onnectionString ToInventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />
<add name="GBrooksCo nnectionStringT oInventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />
<!-- Test Server -->
<add name="Inventory TestServer1Conn ectionStringToI nventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />
<!-- Production Server -->
<add name="Inventory AppServer1Conne ctionStringToIn ventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />

You can see that the connection strings are identical except for the
computer name (which equates to developer name or "environmen t"). So yes,
for each new developer, the connection string must be duplicated and
tweaked (changing only the name).

The application, upon startup, looks to Environment.Mac hineName to
determine which connection string it is to use. So, if the application is
running on a machine for which there is an associated entry in Web.config,
then it will use that connection string.

WHY would they do this? From talking with the existing staff, it appears
that they don't want to deal with versioning Web.config. When moving the
application to different environments or their source control system, they
want to be able to copy the entire application, Web.config and all.

But their strategy (1) creates brittle connection strings, as one must
modify Web.config when moving to a new computer (or hiring another
developer; or a developer leaves...); (2) they in fact have a versioning
problem in that whenever a new connection string is needed, all
developer's copy of Web.config must be updated, etc.

What I'd like to propose to the client - and I'm requesting your
thoughtful responses on this proposal - is to break out the connection
strings into a separate .config file that is referenced from Web.config.
This separate config file would have only one set of connection strings
per envoronment (e..g, 3 connection strings total - one each to the dev,
test, and production). They wouldn't have to modify Web.config whenever a
new developer shows up or they need to run the app on a new computer.
These connection strings would not incorporate the host computer name at
all.

Thoughts?

Thanks.

Thoughts? Is there something better I could do - other than breaking out
connection strings into a separate config file that is then referenced
from Web.config?

Nov 10 '08 #2
the seperate file is ok, but you still need to version it and have to be
careful with xcopy deployments. when I've used this approach, I generally end
using an approch like your customer, where every machine setting is in the
file.

you can also look at web deployment projects, which edit the web.config when
building the staging server. the main issue is you need to build a staging
for each enviroment.

you can reduce the number of connect strings by having a default
(localhost), as usually all the developers have the same settings.
-- bruce (sqlwork.com)
"Johnson" wrote:
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, and
production all have the exact same Web.config file, connection strings and
all).

For connection strings they specify one connection string per computer the
application may run on, including all development machines, all test
servers, and production server. The name of each connection string includes
the name of each computer on which the application may run, plus the name of
the connection string. They have a computer naming convention where each dev
box name is an abbreviation of the developer's name. More formally, it's
like this:

[computer name] + [connection string name]

Here are examples:
<!-- Local DEV Workstations -->
<add name="BSmithCon nectionStringTo InventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />
<add name="RJohnsonC onnectionString ToInventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />
<add name="GBrooksCo nnectionStringT oInventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />
<!-- Test Server -->
<add name="Inventory TestServer1Conn ectionStringToI nventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />
<!-- Production Server -->
<add name="Inventory AppServer1Conne ctionStringToIn ventoryDB"
connectionStrin g="server=DevSe rver1; InitialCatalog= "Inventory" ..." />

You can see that the connection strings are identical except for the
computer name (which equates to developer name or "environmen t"). So yes,
for each new developer, the connection string must be duplicated and tweaked
(changing only the name).

The application, upon startup, looks to Environment.Mac hineName to determine
which connection string it is to use. So, if the application is running on a
machine for which there is an associated entry in Web.config, then it will
use that connection string.

WHY would they do this? From talking with the existing staff, it appears
that they don't want to deal with versioning Web.config. When moving the
application to different environments or their source control system, they
want to be able to copy the entire application, Web.config and all.

But their strategy (1) creates brittle connection strings, as one must
modify Web.config when moving to a new computer (or hiring another
developer; or a developer leaves...); (2) they in fact have a versioning
problem in that whenever a new connection string is needed, all developer's
copy of Web.config must be updated, etc.

What I'd like to propose to the client - and I'm requesting your thoughtful
responses on this proposal - is to break out the connection strings into a
separate .config file that is referenced from Web.config. This separate
config file would have only one set of connection strings per envoronment
(e..g, 3 connection strings total - one each to the dev, test, and
production). They wouldn't have to modify Web.config whenever a new
developer shows up or they need to run the app on a new computer. These
connection strings would not incorporate the host computer name at all.

Thoughts?

Thanks.

Thoughts? Is there something better I could do - other than breaking out
connection strings into a separate config file that is then referenced from
Web.config?
Nov 10 '08 #3

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

Similar topics

2
4569
by: Shaun Ram | last post by:
Hi I have this constraint. A help would be greatly apprecitated. I have this Config file. <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <sectionGroup name="ITASCA"> <section name="ConnectionString" type="System.NamevaluesectionHandler,System" /> </sectionGroup>
0
1596
by: Shaun Ram | last post by:
Hi, I have this constraint. A help would be greatly appreciated. I have this Config file. <?xml version="1.0" encoding="utf-8" ?> <configuration> <configsections> <sectionGroup name="mainsection"> <section name="ConnectionString" type="System.NamevaluesectionHandler,System" /> </sectiongroup>
14
3491
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...
7
12596
by: John A Grandy | last post by:
If a SQLDataSource add the following to my web.config file, how to I programmatically extract the connection string: <configuration> <appSettings/> <connectionStrings> <add name="GUIDBConnectionString" connectionString="Data
8
1963
by: theWizard1 | last post by:
Using Asp.NET 1.1, and C#. I have a directory for the website, and a directory under it named Secure. I have a web.config in each of the above directories. The web.config in the Secure directory contains the connection string information for the database. How can I use ConfigurationSettings.AppSettings to show the path of the Secure directory when getting the connection string?
10
2048
by: eagle | last post by:
I have a web.config in my application that contains the connection strings to all my datasources. I want to move these connection strings to another web config up the folder hierarchy so that all my apps can use the same connection strings. That is supposed to be how it's done, no? Instead of the web.config being in c:\inetpub\wwwroot\myApp\web.config, I have it in c:\inetpub\wwwroot\web.config. However, I get an "Object reference not...
3
3821
by: rlueneberg | last post by:
Can someone explain the difference of using these functions below? And what is the advantage/disadvantage of each? static public SqlConnection GetConnectionString(string ConnectionStringName) { SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings.ConnectionString); return myConnection; }
3
2497
by: =?Utf-8?B?Sm9obkJhdGVz?= | last post by:
I'm trying to (programatically) backup and clear the security event log on the local machine. I can do this manually through the event viewer and I am logged on as an administrator. I can successfully connect to the local wmi service. I can step through and list all the log files on the local computer in a text box so I know I can get an System.Management.ManagementObject that is the security log. However when I try to execute the...
0
1544
by: TG | last post by:
Hi! Once again I have hit a brick wall here. I have a combobox in which the user types the server name and then clicks on button 'CONNECT' to populate the next combobox which contains all the databases in that server. Then after the user selects a database, I have another button that he/she click and I want to retrieve file groups from a specific table. At this point when he/she clicks on that button I get an error:
2
5388
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
8471
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
8386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
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...
1
8592
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
7421
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...
0
5686
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
4213
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
4393
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1795
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.