假设我跟踪了query
private void updateusers()
{
List<int> listRecords=new List<int>();
string strQuery="select * from table where role='Admin' and logged_in<=sysdate-1";
OracleCommand com=new OracleCommand(strQuery,objConnection);
OracleDataReader reader=com.ExecuteReader();
if(reader.HasRows)
{
while(reader.read())
{
listRecords.Add(int.Parse(reader["Row_ID"].toString()));
}
int i=0;
foreach(int row in listRecords)
{
try
{
OracleCommand command=new OracleCommand();
command.Connection=objConnection;
command.CommandText="Update table set Status='Y' where Row_ID="+listRecords[i];
command.CommandType=System.Data.CommandType.Text;
command.ExecuteNonQuery();
}
catch(OracleException ex)
{
//log the exception
}
}
}
}现在我的问题是,让我们假设select查询获取2000记录,foreach将继续更新每个record,并假设在第500 record上,DB连接丢失了,或者说数据库由于某种原因关闭了。现在,在这些场景中,我想迭代或尝试更新相同的记录3次,如果它第三次失败,从foreach-loop中出来,停止对剩余的1500记录执行update命令。
那么,是否有任何特定的方法来识别这些类型的Oracle异常,或者更好地说,环境例外?
OracleException是否为这些类型的异常提供了特定的messageCode?
发布于 2015-12-23 05:29:13
您可以使用ErrorCode类的OracleException属性来识别特定类型的错误。
https://stackoverflow.com/questions/34429081
复制相似问题