我创建了一个软件来从 Oracle DB 读取数据,通过 SMS 发送它,但是当我按下键盘上的 C 键时,我想阻止 datareader 读取,但是当我这样做时,我收到以下异常消息:
Operation is not valid due to the current state of the object
堆栈跟踪:
at Oracle.DataAccess.Client.OracleDataReader.Read()
at Test_SMS_AT_Command.Program.OnTimer(Object obj, EventArgs args)
这是我的代码:
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);
}
谢谢