title: How to set the DB ConnectionStringSettings in Code Behind
body: <p>Studio 2010 C# application accessing LUW DBs.  I am receiving an error when building my DB Conncetion settings in the code behind file rather than using the web.config.  We have a third party product where passwords are stored and retrieved.</p>
  
  <p>The old web.config file method currently establishs DB connection as follows:</p>
  
  <p>In the web.config file:</p>
  
  <pre><code>&lt;add name="myDBConnect" connectionString="Database=mydbname;User    
  ID=myuserid;Password=abcxyz" providerName="IBM.Data.DB2"/&gt;
  </code></pre>
  
  <p>In the code behind file the following is executed to open the DB connection:</p>
  
  <pre><code>ConnectionStringSettings settings = WebConfigurationManager.ConnectionStrings["myDBConnect"];
  ConnectionString = settings.ConnectionString;
  ConnectionStringSettingsCollection settings = ConfigurationManager.ConnectionStrings;
          if ((settings != null))
          {
              foreach (ConnectionStringSettings cs in settings)
              {
                  returnValue = cs.ProviderName;
              }
          }
  </code></pre>
  
  <p>The above logic works fine - but I am now trying to dynamically build the connection string after retrieving the appropriate password from our third party product as follows:</p>
  
  <p>(Note: connPW is the password retrieved from thrid party product)</p>
  
  <pre><code>ConnectionStringSettings settings = "Database=" + mydbname + ";User ID=" + myuserid + ";Password=" + connPW + " providerName=IBM.Data.DB2";
  </code></pre>
  
  <p>This line of code receives the following error:
  "Cannot implicitly convert type 'string' to 'System.Configuration.ConnctionStringSettings'</p>
  
  <p>Can someone please suggest how I can get past this error when defining settings. Thanks</p>