简体   繁体   中英

Catch time out exception

I am trying to catch if timeout error occurs in Oracle. After googling a lot i did not find any specific fix for it. I have done below

 try{}
   catch (OracleException ex)
    {
        if (ex.Number == 01013)
           CatchException(ex);

    }

But i am not sure if timeout exception number is 01013.

Yes the code is 01013. Please refer the Oracle docs :

Default is 0 seconds, which enforces no time limit.

When the specified timeout value expires before a command execution finishes, the command attempts to cancel. If cancellation is successful, an exception is thrown with the message of ORA-01013 : user requested cancel of current operation. If the command executed in time without any errors, no exceptions are thrown.

In a situation where multiple OracleCommand objects use the same connection, the timeout expiration on one of the OracleCommand objects may terminate any of the executions on the single connection. To make the timeout expiration of a OracleCommand cancel only its own command execution, simply use one OracleCommand for each connection if that OracleCommand sets the CommandTimeout property to a value greater than 0.

Please note that there are possibly two other error codes which will throw when the .CommandTimeout is exceeded. Those are ORA-00936 and ORA-00604 . Found in the docs .

When the specified timeout value expires before a command execution finishes, the command attempts to cancel. If cancellation is successful, an exception is thrown with the message of ORA-01013 : user requested cancel of current operation. Other possible exceptions thrown after a command timeout expiration occurs include ORA-00936 and ORA-00604 . If the command executed in time without any errors, no exceptions are thrown.

So your code should be:

try
{
    // Data Access
}
catch (OracleException ex)
{
    if (ex.Number == 01013 ||  ex.Number == 00936 || ex.Number == 00604)
        CatchException(ex);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM