【问题标题】:How to get ORA error code in C# exception?如何在 C# 异常中获取 ORA 错误代码?
【发布时间】:2012-07-13 08:51:26
【问题描述】:

我的代码如下所示:

    public bool myQuery(string cmd)
    {
        try
        {
            OracleCommand command = null;
            command = new OracleCommand(cmd, sqlConnection);
            command.ExecuteReader();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "error!");
            return false;
        }
        return true;            
    }

我的问题是当 Oracle 中出现错误 ORA-02291 时,它的异常未被捕获。没有显示错误,我该如何捕捉这个错误?

【问题讨论】:

  • 你使用的是ADO.Net还是ODP.Net的OracleClient?
  • 您的意思是消息框不包含文本,或者消息框从未显示?
  • 消息框从未显示。我正在使用 webgui 和 devart。我现在明白了.. 这是 webgui 问题。对此感到抱歉..

标签: c# winforms oracle


【解决方案1】:
catch (System.Data.OracleClient.OracleException ex)
{
    int code = ex.Code;

   // or

   string eCode = ex.ErrroCode;

    return false;
}
return true;  

【讨论】:

    【解决方案2】:

    检查一下:

    if (ex.InnerException != null)
    {
        MessageBox.Show(ex.InnerException.Message, "error!");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-05
      • 1970-01-01
      • 2018-05-23
      • 1970-01-01
      • 2013-06-14
      • 2016-07-20
      • 2020-11-20
      相关资源
      最近更新 更多