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

if statement in web.config file

Hello,

Currently, I have two web.config files on different machines (test and
production). The only difference between the two is that the
connectionstring and appsettings point to different data sources (testdb and
productiondb). Is there a way to use something like an if statement or case
statement in a web.config file to determine which connection string or app
settings to use depending on the machine name?
--
Thanks in advance,

sck10

Data Source # 1
------------------------
<configuration>
<connectionStrings>
<add
name="cnnSQL"
connectionString="Data Source=DataSource01;
Persist Security Info=True;
Initial Catalog=MyDB;
User ID=MyUser;
Password=MyPswd"
providerName="System.Data.SqlClient" />
</connectionStrings>

<appSettings>
<add
key="cnnSQL"
value="Server=DataSource01;
User ID=MyUser;
Password=MyPswd;
Database=MyDB;
Persist Security Info=True;
Network Library=dbmssocn"/>
</appSettings>
Data Source # 2
------------------------
<configuration>
<connectionStrings>
<add
name="cnnSQL"
connectionString="Data Source=DataSource02;
Persist Security Info=True;
Initial Catalog=MyDB;
User ID=MyUser;
Password=MyPswd"
providerName="System.Data.SqlClient" />
</connectionStrings>

<appSettings>
<add
key="cnnSQL"
value="Server=DataSource02;
User ID=MyUser;
Password=MyPswd;
Database=MyDB;
Persist Security Info=True;
Network Library=dbnmpntw"/>
</appSettings>
Mar 20 '06 #1
3 11679
Where I work, we using something like:

<add "sqlDev" connectionString="...dev sql connection string" />
<add "sqlTest" connectionString="...dev sql connection string" />
<add "sqlProd" connectionString="...dev sql connection string" />
Then, use application logic in the code to determine which connection string
the app should use.

You can't put the logic directly in the .config file, so I'd say you'll
either have to maintain separate config files (and hope no one accidentally
uses a test one in production for a month before anyone notices) or put the
logic in your app code.

Ray at work

"sck10" <sc***@online.nospam> wrote in message
news:ez**************@tk2msftngp13.phx.gbl...
Hello,

Currently, I have two web.config files on different machines (test and
production). The only difference between the two is that the
connectionstring and appsettings point to different data sources (testdb
and
productiondb). Is there a way to use something like an if statement or
case
statement in a web.config file to determine which connection string or app
settings to use depending on the machine name?
--
Thanks in advance,

sck10

Data Source # 1
------------------------
<configuration>
<connectionStrings>
<add
name="cnnSQL"
connectionString="Data Source=DataSource01;
Persist Security Info=True;
Initial Catalog=MyDB;
User ID=MyUser;
Password=MyPswd"

Mar 20 '06 #2
That sort of thing isn't possible.

Is your code doing different things depending on the value of the
connection string?

The only time I've done something similar is using #if statements to do
additional steps if I'm in a debug build,ie using #if (DEBUG)

Mar 20 '06 #3
Hi sck10,

As for the configuration setting/sections, in .net 2.0, most configuration
sections provide the "configSource" attribute that can help us separate a
certain configurationSection's setting into a separate external file(other
than the application config file). So in your scenario, you can consider
provide two version of such external files for your <appSettings> and
<connecitonStrings> ...

#appSettings Element (General Settings Schema)
http://msdn2.microsoft.com/en-us/lib...54(VS.80).aspx

#SectionInformation.ConfigSource Property
http://msdn2.microsoft.com/en-us/lib...sectioninforma
tion.configsource(VS.80).aspx

Hope this also helps.

regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Mar 21 '06 #4

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

Similar topics

2
by: Job Lot | last post by:
I am trying to write value for a key in <appSettings><add key="LidbsdPath" value="" /></appSettings> section of config file from vb.net app, using statement below ...
4
by: UJ | last post by:
Is there a way to write into the .config file? In other words treat it like a .ini file. (I may be confused on what the exact nature of the .config file may be.) I can read from it fine but...
3
by: Esteban404 | last post by:
I a connection string stored in the app.config file. What is the best way, if any, to modify the file to broaden a setting? For example, the default value needs to be written on setup to look...
4
by: Jeff smith | last post by:
I am reading the value from config file using the below statement. System.Configuration.ConfigurationSettings.AppSettings("MY_DATA") How to write data back to the same location? I am using...
4
by: Greg Scharlemann | last post by:
I thought I had a workable approach to specifing which pages required a redirect in a config file, but it appears the way I'm attempting to do it is not going to work. The idea is that I can...
3
by: Assembly file locked | last post by:
I'm trying to put a SQL statement in a web.config file. But I'd like to have a customized column name as I normally do in ORACLE: e.g. select reg_date "Registration" from patient But when I...
3
by: John K | last post by:
I am trying to eliminate the capability of displaying the details of a web service by disabling WSDL generation in the web.config file. I have made the following changes to the web.config: ...
12
by: dbuchanan | last post by:
Hello, (Is this the proper newsgroup?) === Background === I am building a solution with two projects. One project is my data access layer which contains my DataSet as an xsd file. The XSD...
5
by: =?Utf-8?B?RGFuaWVs?= | last post by:
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...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
0
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,...

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.