首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关于连接问题或数据库关闭的OracleException

关于连接问题或数据库关闭的OracleException
EN

Stack Overflow用户
提问于 2015-12-23 05:17:47
回答 1查看 82关注 0票数 0

假设我跟踪了query

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-23 05:29:13

您可以使用ErrorCode类的OracleException属性来识别特定类型的错误。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34429081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档