title: how to stop oracledatareader from reading
body: <p>I have created a software to read data from Oracle DB send it by SMS but I want to stop datareader from reading when I hit C key on the keyboard but when I done this I get this exception message:</p>
  
  <pre><code>Operation is not valid due to the current state of the object
  </code></pre>
  
  <p>stack trace:</p>
  
  <pre><code>at Oracle.DataAccess.Client.OracleDataReader.Read()
     at Test_SMS_AT_Command.Program.OnTimer(Object obj, EventArgs args)
  </code></pre>
  
  <p>and this my code:</p>
  
  <pre><code>   oraCommand.ExecuteNonQuery();
  
                  OracleDataAdapter oraDataAdapter = new OracleDataAdapter(oraCommand);
                  Oracle.DataAccess.Types.OracleRefCursor refCursor = (Oracle.DataAccess.Types.OracleRefCursor)oraParameter.Value;
                  OracleDataReader reader = refCursor.GetDataReader();
                  while (reader.Read())
                  {
                      if (cki.Key == ConsoleKey.C)
                      {
                          cancel();                     
  
                          if (reader != null)
                          {
                              reader.Close(); //Closed
                          }
  
                          break;
  
                      }
  
                      if (sms.sendSms(reader["MOBILE_NO"].ToString(), reader["TEXT"].ToString()))
                      {
                          Console.WriteLine("Message successfully sent to " + reader["MOBILE_NO"].ToString() + ": " + DateTime.Now);
                          setStatus(Convert.ToInt32(reader["GORANNET_SMS_ID"]));
                          writeToFile(reader["TEXT"] + " sent to " + reader["MOBILE_NO"] + " at: " + DateTime.Now);
                      }
                      else
                      {
                          Console.WriteLine("Message was not sent");
                      }
                      System.Threading.Thread.Sleep(15000);
                  }
  </code></pre>
  
  <p>Thank you</p>