?
Solved

Methods for managing multiple application environments

Posted on 2006-03-20
7
Medium Priority
?
256 Views
Last Modified: 2013-12-03
I'd like to know what people have to say about managing an application within different environments. Imagine that you have four different machines, one is a Live webserver, Live dB server, Testing webserver and a Testing dB server. Now, you would like to create the same application in both webservers where they work with their respective dB server. My question regards how people manage this whether through 3rd party tools or methods/tricks.

From my research, I've found two ways of doing this and although both work, I figure there may be a better solution.
1. http://dallas.sark.com/SarkBlog/cboland/archive/2005/12/09/2287.aspx
Has a nice article on achieving this goal. Basically this amounts to a dialog that allows you to chose a configuration file when deploying an application.

2. In my case, I created the application on the testing server and used the <appSettings> tag in the web.config file to define a key called 'connection' that houses the dB connection string. This way, in my app I use the following command to run a query:
myConnection = new System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings["connection"]);
Then I used the command, Project->Copy Project to copy this app to the Live server and made sure to change the key 'connection' to point to the Live dB

Although number 2. works great, it would be annoying in the case that there are more changes than just the connection string. In that case, I could see that the article I mentioned would be an improvement. Regardless, everytime you write a new application you'd have to work this scheme into it. Is there a better way? Does Configuration Manager provide a way to manage this? I've played around with it and all I see is the ability to turn 'Build' off in a particular configuration.

Any help/suggestion is welcome.
0
Comment
Question by:wsbdc-questions
  • 3
  • 2
6 Comments
 

Author Comment

by:wsbdc-questions
ID: 16239007
I forgot to mention that I am using VS 2003. If possible, would anyone point out if there is a considerable improvement in VS 2005 concerning my question?
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 16239270
I use a 3rd party tool.

Beyond Compare:
http://www.scootersoftware.com/

It is fairly cheap, and very nice.
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 16242329
I don't spend any money at all to do this. You are most of the way there with your web.config appsettings. If you extend this slightly, you can have your key as:
<add key="ConnectionString.MACHINENAME1" value="..."/>
<add key="ConnectionString.MACHINENAME2" value="..."/>
<add key="ConnectionString.MACHINENAME3" value="..."/>

Then, create a class with a static method GetConnectionString(). This will get your machine name, append it to "ConnectionString." and pick the appropriate key.

I use this method to get round the same problem with multiple development machines, and a checked-in web.config file. It just happened to solve my deployment problems as well.

Andy
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:AGBrown
ID: 16460846
I think both mrichmon and myself offer solutions.

A.
0
 

Author Comment

by:wsbdc-questions
ID: 16471740
Thank you AGBrown. I see your point. Do you see any problems with taking your approach but rather than fetching the machine name and appending it to the connectionstring fetching the connectionstring from either an active or debug release? The reason I ask is because I have not found a way to figure out, within the code, what release mode you are in. I think it would be better doing it this way since different environments require different tweaks simply changing the machinename may not account for all changes. I feel as though MS dropped the ball with this but who knows, maybe 2005 takes care of it.
0
 
LVL 12

Accepted Solution

by:
AGBrown earned 750 total points
ID: 16476286
You can use preprocessor directives to determine your release mode (assuming C# here):
#if DEBUG
     // debug code
#else
     // non-debug code
#end if

I have a "Production" build defined through Visual Studio that defines a PRODUCTION symbol, so just before release to server I use:
#if DEBUG
     // debug code
#elif PRODUCTION
     // Production release
#else
    // other non-debug code
#end if

Using this you can run different code depending on your release, pick up different values from the config file etc. I actually run a class with a bunch of static properties that access the web.config file, they use both the preprocessor and machine name methods to get the right values.

Of course, I can see this becoming unattractive if you don't want to distribute connection strings for servers to all your developers. But I can't think of a better way in that case.

Here's the MSDN reference for the processor directive #if: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfIf.asp

Andy
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question