OracleException is not triggered!

0

Someone has already encountered the following problem: When an error occurs that should be of type OracleException, but in its place an Exception is triggered, then the oracle processing is not applied because of this (the "..." are deprecated 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 you return is "Connection is not open ..."

    
asked by anonymous 26.02.2015 / 22:58

1 answer

0

I edited the answer because the previous one was of poor quality.

Looking at the binary inside I found (THE HORROR) some possible exception cases, 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"));
        }

In my tests the error is the same as 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 at the command execution:

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 get an OracleException of this code, since the Oracle documentation also says that the exception is of type: InvalidOperationException and if you do not give open the error will get caught in the Validate above.

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

    
26.02.2015 / 23:29