title: How to create dynamic database connection string C#
body: <p>I just created a desktop Winforms application with <code>localhost</code> database. 
  The connect string I am using is this:</p>
  
  <pre><code>SqlConnection connect = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Administrator\Desktop\learningsystem\LearningSystem\LearningSystem\LearningSystem.mdf;Integrated Security=True");
  </code></pre>
  
  <p>If I want to run my application on other computers, how should I make it work?</p>
  
  <p><strong>EDIT：SOLUTION</strong>
  Thank for all the help! I tried the following steps. I think it is working now. But please correct me if I did something tricky. 
  1. add a new setting item in project property setting. App.config will automatically update: </p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="LearningSystem.Properties.Settings.LearningConn" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\LearningSystem.mdf;Integrated Security=True;Connect Timeout=30"
          providerName="System.Data.SqlClient" /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>2. In my program, just add the following statement to connect to the sql server</p>
  
  <pre><code>        SqlConnection connect = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename=|DataDirectory|\LearningSystem.mdf;Integrated Security = True; Connect Timeout = 30");
  </code></pre>
  
  <p><strong>Further question</strong>
  If others will run this application on their computer(not in the same network), they just go into the project setting and change the value by selecting the database file I provide to them,the connectionString will automatically change, right? </p>
  
  <p>Thanks!</p>