title: An unhandled exception in the designer
body: <p>I've created a project in Visual Studio 2019 which has several user controls in a form called <code>Home</code>.</p>
  <p>All goes right until today. After rebuilding my project <code>Home</code> form shows an error saying</p>
  <pre><code>The control system.windows.forms.form has thrown an unhandled exception in the designer and has been desabled. 
  Exception :
  An attempt to attach an auto-named database for file c:\program files(x86)\Microsoft Visual Studio\2019\Enterprise\common7\ide\database\pharmacy.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on unc share.
  </code></pre>
  <p>I checked the connection code, and it looks ok. But still the error isn't solved.</p>
  <p>Code:</p>
  <pre><code>SqlConnection con = new SqlConnection(@&quot;Data Source=LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\Final Project BCA\PharmacyManagementSystemCSharp\Database\pharmacy.mdf;Integrated Security=True&quot;);
  con.Open()
  String str = &quot;Select max(id) from supp;&quot;;
  SqlCommand cmd = new SqlCommand(str, con);
  SqlDataReader dr = cmd.ExecuteReader();
  if (dr.Read())
  {
  String val = dr[0].ToString();
  if (val == &quot;&quot;)
  {
  .....
  }
  private void button1_Click(object sender, EventArgs e)
  {
  SqlConnection con = new SqlConnection(@&quot;Data Source= (LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\Final Project BCA\PharmacyManagementSystemCSharp\Database\pharmacy.mdf;Integrated Security=True&quot;);
              con.Open();
              try
              {
                  String str = &quot;Insert into supp(name,email,mobile,addr,s_code) values('&quot; + Sup_Name.Text + &quot;','&quot; + Sup_Email.Text + &quot;','&quot; + Sup_Mobile.Text + &quot;','&quot; + Sup_Add.Text + &quot;','&quot; + Sup_Code.Text + &quot;');&quot;;
                  SqlCommand cmd = new SqlCommand(str, con);
                  cmd.ExecuteNonQuery();
                  String str1 = &quot;select max(ID) from supp;&quot;;
                  SqlCommand cmd1 = new SqlCommand(str1, con);
                  SqlDataReader dr = cmd1.ExecuteReader();
                  if (dr.Read())
                  {
                      MessageBox.Show(&quot;Inserted Supplier Data SuccessFully..&quot;);
                      using (SqlConnection con1 = new SqlConnection(@&quot;Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\Final Project BCA\PharmacyManagementSystemCSharp\Database\pharmacy.mdf;Integrated Security=True&quot;))
                      {
                          String str2 = &quot;Select * from supp&quot;;
                          SqlCommand cmd2 = new SqlCommand(str2, con1);
                          SqlDataAdapter sda = new SqlDataAdapter(cmd2);
                          DataTable dt = new DataTable();
                          sda.Fill(dt);
                          SupplierDataGV.DataSource = new BindingSource(dt, null);
                      }
                      Sup_Name.Text = &quot;&quot;;
                      Sup_Code.Text = &quot;&quot;;
                      Sup_Email.Text = &quot;&quot;;
                      Sup_Mobile.Text = &quot;&quot;;
                      Sup_Add.Text = &quot;&quot;;
  
                  }
              }
              catch (SqlException ex)
              {
                  MessageBox.Show(ex.Message);
              }
          }
     
  </code></pre>