473,387 Members | 1,721 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.

Switch connectiong string in web.config file base on configuration

How can I switch connection strings stored in config file based on the build
configuration? Or my real question is how most people maintain different
connection strings when their code is running in different environment, like
development, building, testing....

Thanks.

Daniel
Aug 23 '07 #1
5 2162
Daniel,

Well, personally, I would have two separate config files (just like you
have two separate binaries) which have two separate connection strings.

You could have a preprocessor statement for a constant which sets
different values based on the build type. However, that means you would
have to put both values into your config file. That's a little hokey to me,
and it's easier to just have two config files, IMO, as you don't want to
distribute the debug connection string in the release file.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Daniel" <da*********@newsgroup.nospamwrote in message
news:88**********************************@microsof t.com...
How can I switch connection strings stored in config file based on the
build
configuration? Or my real question is how most people maintain different
connection strings when their code is running in different environment,
like
development, building, testing....

Thanks.

Daniel

Aug 23 '07 #2
Thanks Nicholas. I think your approach can work. But for me, it's a little
bit inconvenient, as our application is still growing quickly, the config
file changes all the time, lots of stuffs from the enterprise library. Keep
two or more config files be synchronized could be error prone. Can I just
seperate a little part of the config file and make two of them to adopt
different configurations?

Daniel
Aug 24 '07 #3
Thanks Steven, that's what I want.

Daniel
Aug 24 '07 #4
You're welcome!

Enjoy it! :)

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 24 '07 #5
On Aug 24, 6:22 am, Daniel <daniel.s...@newsgroup.nospamwrote:
Thanks Nicholas. I think your approach can work. But for me, it's a little
bit inconvenient, as our application is still growing quickly, theconfig
file changes all the time, lots of stuffs from the enterprise library. Keep
two or moreconfigfilesbe synchronized could be error prone. Can I just
seperate a little part of theconfigfile and make two of them to adopt
different configurations?

Daniel
Hi Daniel,

i have another requirement. i need a config file in which i can define
appSettings.
but with the above one i am not able to do that..can you help me
regarding this.
if possible can you let me know how to define connection string
property also in the custom config file

Sep 11 '07 #6

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

Similar topics

3
by: Peter Blum | last post by:
I have built an assembly (dll) from which I expect third parties to subclass. As a result, when my assembly has a version change, it will cause any third party assembly based on it to break unless...
2
by: Tony Jones | last post by:
Is it possible for me to create a class library DLL and have it read it's configuration settings from the web.config of the ASP.NET application referencing it? IE - if I call...
3
by: Lee Chapman | last post by:
Hi, I want my ASP.NET web application to use a custom HtmlTextWriter. i.e. I want the object that the Framework passes to System.Web.UI.Control.Render() to be my own object, MyHtmlTextWriter,...
16
by: Timm | last post by:
I'm trying to use ASP objects (basically formed and populated based on Web.Config settings) and I want to use them in a different non-asp program with minimal reprogramming. So, my question is how...
9
by: Benny Ng | last post by:
Hi,all, How to let the sub-directory to avoid the authentication control from Root's webconfig? I heard that we can add a new web.config to the sub-directory. And then we can slove the problem....
19
by: Jaime Stuardo | last post by:
Hi all.. I have created a business logic component that is used from my ASP.NET webform. It works, but connection string to the database is hard coded, as in this method : public DataSet...
7
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
0
by: Massimiliano Polito | last post by:
It seems the option '/useenv' is no longer supported in in Microsoft Visual .NET 2005. If I run 'devenv /?' I get the following: ------------------------ Microsoft (R) Visual Studio Version...
10
by: =?Utf-8?B?U3RlZmFuIEJhcmxvdw==?= | last post by:
This has been working perfectly for months. Since we switched from ASP.NET 1.1 to 2.0, we have constant and sporadic issues with updating our applications. Touching the web.config works about...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.