title: Pros/cons of reading connection string from physical file vs Application object (ASP.NET)?
body: <p>my ASP.NET application reads an xml file to determine which environment it's currently in (e.g. local, development, production).  </p>
  
  <p>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.  </p>
  
  <p>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).  </p>
  
  <p>I was considering storing the connection string in Application["ConnectionString"].  So the code would be</p>
  
  <pre><code>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();
          }
  </code></pre>
  
  <p>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?</p>
  
  <p>THANKS</p>