title: How can I connect C# with Db with App.config?
body: <p>I need to connect C# with SQL Server database using <code>app.config</code>.</p>
  
  <p>My code is:</p>
  
  <pre><code>public partial class Form1 : Form
  {
      string  connectionString = ConfigurationManager.ConnectionStrings["Conn"].ConnectionString;     
  
      public Form1()
      {
              InitializeComponent();
      }
  
      public void InsertDeleteUpdate(string query)
      {
              try
              {
                  SqlConnection Conn = new SqlConnection(connectionString);
                  Conn.Open();
                  SqlCommand comm = new SqlCommand(query, Conn);
                  comm.ExecuteNonQuery();
                  Conn.Close();
                  MessageBox.Show("Succeeded");
              }
              catch (Exception ex)
              {
                  MessageBox.Show(ex.Message);   
              }
          }
  </code></pre>
  
  <p>and in <code>app.config</code> I have:</p>
  
  <pre><code>&lt;connectionStrings&gt;
      &lt;add name="Test1" 
           providerName="System.Data.SqlClient"
           connectionString="Data Source=KSPR1WS126;Initial Catalog=Test1;User ID=sa" /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>but I get an error and I can't fix it:</p>
  
  <blockquote>
    <p>ConfigurationErrorExeption was Unhandled  Configuration system
    failed to initialize</p>
  </blockquote>
  
  <p>Can anyone help me please ?</p>