using different web.config for development and deployment

G

Guest

We have several settings in web.config that are different on the developer
side than the production side. Our website sourcecode is under sourcesafe
control, so before we code, we check out the web.config and change our
connection strings to point to development databases, and change
"debug=true". Before we deploy, we change everything back. We can't
dynamically select the proper connection string in code because we are using
the tableadapter and dataset designer, which uses settings from web.config,
besides, there are other settings in the web.config that need to be different
while developing/debugging. Any suggestions for managing this better?

Joel
 
G

Guest

The standard appSettings section has an optional "file=" attribute that lets
you handle this kind of situation quite nicely.
Peter
 
A

Arthur Dent

It wouldnt be terribly pretty, but could you do something like the
following?
(forgive syntax, i dont use the tableadapter/dataset things so dont know
their props/methods)

Public Module General
Public Const devServer As String = "test.mycompany.com"
Public Const prdServer As String = "www.mycompany.com"
End Module

Then in your page (or control) do something like:

Sub Page_Load(...) Handles Me.Load
Select Case Request.ServerVariables("SERVER_NAME")
Case General.devServer
myTableAdapter.ConnectionString =
howEverYouGetConfigConnString("ConnectionStringDev")

Case General.prdServer
myTableAdapter.ConnectionString =
howEverYouGetConfigConnString("ConnectionStringProd")

End Select
End Sub
 
R

Rick Strahl

Hi Joel,

I would suggest not publishing your web.config with your deployment. That's
probably the easiest and best solution because there's really little reason
to update web.config. If changes are required they should be made
explicitly.

If that's not possible then I would suggest Web Deployment Projects which
allows you to configure configuration section values to be changed on
compilation. You can put your configuration sections into seperate files
that the compiler will pick up when the project is precompiled to disk
before deployment. Also WDP can compile into a single assembly which is also
much better than deploying the entire mess of compiled files that hte stock
pre-compiler uses.

http://msdn.microsoft.com/asp.net/reference/infrastructure/wdp/

+++ Rick ---

--


Rick Strahl
West Wind Technologies
http://www.west-wind.com/weblog
http://www.west-wind.com/wwThreads/
 
G

Guest

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" 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
 

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,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top