Best practices for deployment from dev to stage to production

D

dasomerville

We have different settings for our development, stage and production
environments. For example, our development environment connection strings
point to development database instances, stage connection strings point to
stage database instances and so forth.

Without having to maintain separate web.config files, what are the various
approaches to having environment-specific settings?
 
U

Uli

Hi,

here is the way I'm doing it.

Set a machine identity in the machine.config that says if it is a
development, stage or production server (e.g. d, s or p. It might be good to
add an "l" for local also).

for the Development-server
<add key="ApplEnv-l" value="d" />


Then you can put the connection strings for all environments into the
web.config

<add key="ConnectionString-l" value="server=(local);......."/>
<add key="ConnectionString-d" value="server=DEV-Server;......"/>
<add key="ConnectionString-s" value="server=STG_Server;....."/>
<add key="ConnectionString-p" value="server=PRD-Server;....."/>

In your code put something like:

private static string DbConnectionString
{
get
{
string strApplEnv = ConfigurationSettings.AppSettings["ApplEnv"];
string paramSuffix = strApplEnv.ToLower().Substring(0,1);
return ConfigurationSettings.AppSettings["ConnectionString-" +
paramSuffix] ;
}


This way you can use the web.config for all environments.

Regards,
Uli
 
U

Uli

sorry, it has to be:

<add key="ApplEnv" value="d" />
and not
<add key="ApplEnv-l" value="d" />


--
Wer nicht fragt, stirbt dumm.
If you don''''''''t ask, you''''''''ll die as a dumba**.


Uli said:
Hi,

here is the way I'm doing it.

Set a machine identity in the machine.config that says if it is a
development, stage or production server (e.g. d, s or p. It might be good to
add an "l" for local also).

for the Development-server
<add key="ApplEnv-l" value="d" />


Then you can put the connection strings for all environments into the
web.config

<add key="ConnectionString-l" value="server=(local);......."/>
<add key="ConnectionString-d" value="server=DEV-Server;......"/>
<add key="ConnectionString-s" value="server=STG_Server;....."/>
<add key="ConnectionString-p" value="server=PRD-Server;....."/>

In your code put something like:

private static string DbConnectionString
{
get
{
string strApplEnv = ConfigurationSettings.AppSettings["ApplEnv"];
string paramSuffix = strApplEnv.ToLower().Substring(0,1);
return ConfigurationSettings.AppSettings["ConnectionString-" +
paramSuffix] ;
}


This way you can use the web.config for all environments.

Regards,
Uli
--
Wer nicht fragt, stirbt dumm.
If you don''t ask, you'll die as a dumba**.


dasomerville said:
We have different settings for our development, stage and production
environments. For example, our development environment connection strings
point to development database instances, stage connection strings point to
stage database instances and so forth.

Without having to maintain separate web.config files, what are the various
approaches to having environment-specific settings?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top