title: The connection is open
body: <p>A few months ago I made a test program for a project and everything worked fine there.
  Now I am working on the program itself, so I copied the code from the test program and
  changed the the names of the columns,buttons etc. so it would fit the current program.
  When I try to add something into the database it does nothing on the first click, on the 
  second pops up an error which says that the connection is open.. I really got no idea what's
  the problem. I tried to check again if I made a mistake in a column name or the database name
  but everything seems to be correct.
  Note: I also have a function that show data from the database and it works without any problem.</p>
  
  <pre><code>private void InsertData()
  {
      string NewCode = GenerateCode();
      string NewSentence = txtSentence.Text;
      string NewRow = NewRowNum();
      try
      {
          string AddData = "INSERT INTO ShopSentences (BinaryStrings,Sentence,RowNumber) VALUES (@NewBinaryString,@NewSentence,@NewRowNumber)";
          SqlCommand DataAdd = new SqlCommand(AddData, Connection);
          DataAdd.Parameters.AddWithValue("@NewBinaryString", NewCode);
          DataAdd.Parameters.AddWithValue("@NewNewSentence", NewSentence);
          DataAdd.Parameters.AddWithValue("@NewRowNumber", NewRow);
          Connection.Open();
          DataAdd.ExecuteNonQuery();
          Connection.Close();
      }
      catch (Exception e)
      {
          Console.WriteLine(e.ToString());
      }
  }
  //Checking the banary code in the last row
  string GenerateCode()
  {
      string RowNo = RowFind();
      int Row = int.Parse(RowNo);
      int Code = Row + 1;
      string Cd = Convert.ToString(Code, 2);
      int Ln = Cd.Trim().Length;
      if (Ln == 3)
      {
          Cd = "100" + Cd;
      }
      else if (Ln == 4)
      {
          Cd = "10" + Cd;
      }
      else if (Ln == 5)
      {
          Cd = "1" + Cd;
      }
      return Cd;
  }
  //Finding the last row
  string RowFind()
  {
      Connection.Open();
      string queryString = string.Format("SELECT * FROM ShopSentences");
      SqlDataAdapter sda = new SqlDataAdapter(queryString, Connection);
      DataTable dt = new DataTable("ShopSentences");
      sda.Fill(dt);
      Connection.Close();
      return dt.Rows[dt.Rows.Count - 1]["RowNumber"].ToString();
  }
  string NewRowNum()
  {
      string Row = RowFind();
      int CalcRow = int.Parse(Row) + 1;
      Row = CalcRow.ToString();
      return Row;
  }
  </code></pre>
  
  <p>The connection that appears to be open is the one in the string RowFind().</p>
  
  <p>Here are the other related things to the database:</p>
  
  <pre><code>public partial class frmShop : Form
  {
      System.Data.SqlClient.SqlConnection Connection;
  
      public frmShop()
      {
          string DatabaseConnection = WindowsFormsApplication1.Properties.Settings.Default.BinaryStringsDictionaryConnectionString1;
          Connection = new System.Data.SqlClient.SqlConnection();
          Connection.ConnectionString = DatabaseConnection;
          InitializeComponent();
      }
  
      private void frmShop_Load(object sender, EventArgs e)
      {
          // TODO: This line of code loads data into the 'binaryStringsDictionaryDataSet.ShopSentences' table. You can move, or remove it, as needed.
          this.shopSentencesTableAdapter.Fill(this.binaryStringsDictionaryDataSet.ShopSentences);
  
      }
  
      private void GetSentence()
      {
          try
          {
              Connection.Open();
              SqlDataReader ReadSentence = null;
              Int32 BinaryInt = Int32.Parse(txtBinaryString.Text);
              string CommandString = "SELECT Sentence FROM ShopSentences WHERE BinaryStrings = @BinaryString";
              SqlCommand Command = new SqlCommand(CommandString, Connection);
              Command.Parameters.Add("@BinaryString", System.Data.SqlDbType.Int).Value = BinaryInt;
              ReadSentence = Command.ExecuteReader();
              while (ReadSentence.Read())
              {
                  txtSentence.Text = (ReadSentence["Sentence"].ToString());
                  Fit = 1;
              }
              Connection.Close();
          }
          catch (Exception e)
          {
              Console.WriteLine(e.ToString());
          }
      }
  }
  </code></pre>