title: How can I make LINQ to SQL use a connection string which is being modified at runtime?
body: <p>I'm experimenting some difficulties trying to use <a href="http://msdn.microsoft.com/en-us/library/ms254947.aspx" rel="noreferrer"><strong>Connection String Builders (ADO.NET)</strong></a> within LINQ to SQL. Let me show you guys what I'm trying to do:</p>
  
  <blockquote>
    <p>the <strong>app.config</strong> file:</p>
  </blockquote>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;configSections&gt;
      &lt;/configSections&gt;
      &lt;connectionStrings&gt;
          &lt;add name="LoremIpsum"
               connectionString="Data Source=SomeServer;Initial Catalog=SomeDB;User ID=joe;"
               providerName="System.Data.SqlClient" /&gt;
      &lt;/connectionStrings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <blockquote>
    <p>and a snippet of the form:</p>
  </blockquote>
  
  <pre><code>ConnectionStringSettings settings = 
      ConfigurationManager.ConnectionStrings["LoremIpsum"];
  if (null != settings)
  {
      string connection = settings.ConnectionString;
      SqlConnectionStringBuilder builder = 
           new SqlConnectionStringBuilder(connection);
  
      // passwordTextBox being the control where joe the user actually 
      // enters his credentials           
      builder.Password = passwordTextBox.Text;
  }
  
  LINQTOSQLDataClassDataContext db = new LINQTOSQLDataClassDataContext();
  
  // finally some rather anecdotic LINQ sentence here:
  var foo = db.Table.Single(bar =&gt; bar.Table == whatever);
  </code></pre>
  
  <blockquote>
    <p>On the other hand checking the <strong>Immediate Window</strong>:</p>
  </blockquote>
  
  <pre><code>?builder.ConnectionString
  "Data Source=SomeServer;Initial Catalog=SomeDB;User ID=joe;Password=swordfish"
  </code></pre>
  
  <p>I'm always getting an exception: Login failed for user 'joe'. Any ideas? Thanks much in advance.</p>