title: Getting "Invalid Operation. The Connection is closed" error while trying to update oracle from visual c# program
body: <p>I've got a visual c# program running, but I'm getting a connection is closed error whenever I try to update. Here's what my code looks like:</p>
  
  <pre><code>private void Update()
  {
      try
      {
          String OneMachineScheduleOrder = "";
          String series = "";
          String oven = "";
          String battery = "";
          int x,y;
  
          var sortedTextboxes = panel1.Controls
                  .OfType&lt;TextBox&gt;() // get all textboxes controls
                  .OrderBy(ctrl =&gt; ctrl.TabIndex); // order by TabIndex
          foreach (TextBox txt in sortedTextboxes)
          {
              //Console.WriteLine(Convert.ToInt32(txt.TabIndex/2+1) + ": " + txt.Text);
              OneMachineScheduleOrder = (txt.TabIndex / 2 + 1).ToString();
              series = txt.Text.Substring(0, 1);
              oven = txt.Text.Substring(1, 2);
              battery = txt.Text.Substring(4).Trim();
              if (Char.IsLetter(series[0]) &amp;&amp; int.TryParse(oven, out y) &amp;&amp; int.TryParse(battery, out x) &amp;&amp; txt.Text[3].Equals('/'))
              {
                  using (OracleConnection con = new OracleConnection(connectString))
                  {
                      OracleCommand cmd = connection.CreateCommand();
                      cmd.CommandType = CommandType.Text;
                      cmd.CommandText = "update Oven_Master set SERIES = '" + series + "', OVEN = '" + oven + "', BATTERY = '" + battery + "' where ONE_MACHINE_SCHEDULE_ORDER = '" + OneMachineScheduleOrder + "'";
                      cmd.Connection = con;
                      cmd.ExecuteNonQuery();
                      Console.WriteLine(cmd.CommandText);
                      con.Close();
                  }
              }
              else { MessageBox.Show("Number: " + OneMachineScheduleOrder + " Is Invalid!"); }                           
          }
      }
      catch (Exception ex)
      {
          MessageBox.Show(ex.ToString());
      }
      finally
      {
          connection.Close();
      }
  }
  </code></pre>
  
  <p>Basically, I've got a bunch of textboxes on the form that are filled in in the format <code>A01/01</code>.  I'm sorting the textboxes into a variable, and then for each textbox, I parse out the relevent data (OneMachineScheduleOrder, series, oven, and battery).  If the data is in the right format, I use an oracleConnection with a connectionstring that is global (and I checked with the debugger that it has the correct value) to create an execute and OracleCommand.  Otherwise, alert the user that the data is in the wrong format.  </p>
  
  <p>However, I'm getting an error that the connection is open.  I tried putting a breakpoint on that line, and I'm getting that <code>con = OracleConnection</code>, so I can see that there <em>is</em> a connection.  No idea where to go from here. </p>