我正在使用System.OracleClient.OracleCommand
和设置执行 ORACLE 存储过程CommandTimeout = 5; (for example)
但是我想设置一个超时,这样如果命令对象执行时间超过 5 分钟,它应该被中止(得到异常...... OracleException
),以便我可以向用户显示错误消息。让我知道如何做到这一点。这是我编写的代码示例。
try
{
_dbConnectionString.Open();
var cmdOracle = new OracleCommand("hfghgh", _dbConnectionString)
{
CommandType = CommandType.StoredProcedure
};
OracleCommandBuilder.DeriveParameters(cmdOracle);
cmdOracle.Parameters["inputParam"].Value = 1;
tran =_dbConnectionString.BeginTransaction(IsolationLevel.ReadCommitted);
cmdOracle.Transaction = tran;
cmdOracle.CommandTimeout = 5;
await cmdOracle.ExecuteNonQueryAsync();
tran.Commit();
return res = cmdOracle.Parameters["outputParam"].Value.ToString();
}
catch (OracleException ex)
{
dynamic exOra = ex;
int errorNo = exOra.Number;
if (errorNo == 01013)
{
throw new ResponseFailException(ex);
}
else
{
throw ex;
}
}