title: How do I retrieve both the server name and database name from a connection string in web.config
body: <p>How do I retrieve both the Server Name and Database Name from a web.config connection string programatically through the .net api?  Preferably without using an html or xml parser I create.  Looking for the simplest way to retrieve this type of information.
  Example web.config snippet:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
    &lt;connectionStrings&gt;
      &lt;add name="ConnectionString" connectionString="Provider=SQLOLEDB;Data Source=MyServer;User ID=admind;password=ju7mpst@rterz_Fak3;Initial Catalog=dbDatabase" providerName="System.Data.OLEPlethora"/&gt;
    &lt;/connectionStrings&gt;
  &lt;system.web&gt;
  </code></pre>
  
  <p>result:
  server=MyServer
  database=dbDatabase</p>
  
  <p>Found this <a href="https://stackoverflow.com/questions/8177223/sql-server-connection-string-in-code-vs-config-file-in-asp-net-site">link</a> regarding retreiving connection string settings. This appears to be much simplier, however, I'm not sure if I can iterate over many connection string.</p>