Oracleexception is not fired!

Asked

Viewed 71 times

0

Someone has already come across the following problem: When an error occurs that should be of the type Oracleexception, but in its place an exception is triggered, then the oracle treatment is not applied because of this (the "..." are suppressed implementations).

See example:

using (OracleConnection connection = new     OracleConnection(ConfigurationManager.ConnectionStrings["Oracle"].ConnectionString))
using (OracleCommand command = connection.CreateCommand())
{
    try
    {
        //connection.Open(); //PARA PROVOCAR ERRO ORACLE
        (...)

        //Captura resultado em um DataReader
        //AO EXECUTAR ISTO NÃO LEVANTA ERRO ORACLE E SIM UM EXCEPTION SIMPLES.
        using (Oracle.ManagedDataAccess.Client.OracleDataReader retornoBanco =     command.ExecuteReader()) 
        {
            (...)
        }
        (...)
    }
    catch (OracleException oe)
    {                           
          (...)
          switch (erroCodeOracle)
          {
              case 12571:
                  (...)
                  break;
              default:
                  (...)
                  break;
          }
    }

}

Do not enter CATCH above! But the error that returns is "Connection is not open..."

1 answer

0


I edited the answer because the previous one had low quality.

Observing the binary inside I found (THE HORROR) some possible cases of exception, one of them corroborates its placement of simple Exception:

if (this.m_isFromEF && this.m_connection.m_majorVersion < 12 && this.m_commandText.Contains(" APPLY "))
        {
          throw new Exception(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.ODP_NOT_SUPPORTED, "Oracle " + ((object) this.m_connection.ServerVersion).ToString(), "APPLY"));
        }

No more in my tests the error is the same as in the Oracle documentation: An unhandled Exception of type 'System.Invalidoperationexception' occurred in Oracle.ManagedDataAccess.dll

This error will always occur because there is a call to ValidateStatePriorToExecution in executing the command:

private void ValidateStatePriorToExecution()
    {
      if (this.m_disposed)
        throw new ObjectDisposedException(this.GetType().Name);
      if (this.m_connection == null)
        throw new InvalidOperationException();
      if (this.m_connection.m_connectionState != ConnectionState.Open)
        throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.CON_CLOSED));
      if (this.m_commandImpl == null)
      {
        this.m_commandImpl = this.GetInitializedCommandImpl();
        if (this.m_commandImpl == null)
          throw new InvalidOperationException();
      }
      if (this.m_arrayBindCount > 1 && (this.m_parameters == null || this.m_parameters.Count == 0))
        this.m_commandImpl.m_arrayBindCount = 0;
      else
        this.m_commandImpl.m_arrayBindCount = this.m_arrayBindCount;
    }

I could not find out how it could be possible to exit an Oracleexception from this code, since the Oracle documentation also says that the exception is of type: InvalidOperationException and if you don’t give open the error will be caught in Validate above.

Except the first IF that comes from the EF with those conditions of version and use of the word APPLY is only Exception.

  • Dear, I am using the Oracle client (using Oracle.ManagedDataAccess.Client). Thank you anyway...

  • Okay, I researched and edited my answer.

  • Dear, thank you again for your commitment. With your response I am determined to change my strategy and protect the code in another way, since I will not be able to treat this event as expected. I have already marked your review as a valid reply. Thanks again!

  • I understand your frustration, even though I don’t use Oracle I was frustrated with the documentation. I’m not even gonna tell you the quality of the code inside Assembly because I have nothing good to say. In my understanding the Oracleexception is used for errors from within the BD.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.