Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 725251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:18:57+00:00 2026-05-14T06:18:57+00:00

my ASP.NET application reads an xml file to determine which environment it’s currently in

  • 0

my ASP.NET application reads an xml file to determine which environment it’s currently in (e.g. local, development, production).

It checks this file every single time it opens a connection to the database, in order to know which connection string to grab from the Application Settings.

I’m entering a phase of development where efficiency is becoming a concern. I don’t think it’s a good idea to have to read a file on a physical disk ever single time I wish to access the database (very often).

I was considering storing the connection string in Application[“ConnectionString”]. So the code would be

public static string GetConnectionString
        {
            if (Application["ConnectionString"] == null)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(HttpContext.Current.Request.PhysicalApplicationPath + "bin/ServerEnvironment.xml");
                XmlElement xe = (XmlElement) xnl[0];

                switch (xe.InnerText.ToString().ToLower())
                {
                    case "local":
                        connString = Settings.Default.ConnectionStringLocal;
                        break;

                    case "development":
                        connString = Settings.Default.ConnectionStringDevelopment;
                        break;

                    case "production":
                        connString = Settings.Default.ConnectionStringProduction;
                        break;

                    default:
                        throw new Exception("no connection string defined");
                }
                Application["ConnectionString"] = connString; 
            }
            return Application["ConnectionString"].ToString();
        }

I didn’t design the application so I figure there must have been a reason for reading the xml file every time (to change settings while the application runs?) I have very little concept of the inner workings here. What are the pros and cons? Do you think I’d see a small performance gain by implementing the function above?

THANKS

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:18:57+00:00Added an answer on May 14, 2026 at 6:18 am

    Wow. Throw that in the bin.

    All .config files (web or app.config) have a section dedicated to connection strings and these can be read using the ConfigurationManager.ConnectionStrings property.

    For local and test environments, I simply set up three connection strings as follows

    <connectionStrings>
        <add name="default.local" connectionString="etc ..>
        <add name="default.test" connectionString="etc ..>
        <add name="default" connectionString="etc ..>
    </connectionStrings>
    

    Determine which connection stirng to fetch based on another setting in the config file. A small utility function utilises this information to pick the correct connection string.

    In this way, the config file stays the same across the different deployments apart from the environment setting.

    EDIT: forgot to mention these values are cached in memory and the app restarts when they are changed (may be a problem, may be useful) Performance is absolutely fine going directly to the .config file through the ConfigurationManager class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a asp.net application which reads and updates and xml file in my
I have an ASP.NET web application which does the following: Reads an Excel file.
I have an asp.net web application. The application reads data from an xml. The
The ASP.NET application that I am currently responsible for at my day job has
I'm developing a web application with asp.net and I have a file called Template.docx
I have a console application that reads an XML file and outputs everything into
I work on an ASP.Net application which is a web version of an already
I have read that viewstate is not there in asp.net MVC application. I am
Simple ASP.NET application. I have two drop-down controls. On the first-drop down I have
For ASP.Net application deployment what type of information (if any) are you storing in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.