大多数情况下它可以工作,但有时我会收到错误消息:
Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-03135: 连接失去联系
...在 C:\xxx\Controllers\XController.cs:108 行
所以第108行很return StatusCode(HttpStatusCode.ExpectationFailed);
奇怪......
class MyDbConfiguration : DbConfiguration
{
public MyDbConfiguration()
{
SetExecutionStrategy("Oracle.ManagedDataAccess.Client", () => new MyDbExecutionStrategy(3, TimeSpan.FromSeconds(0)));
}
}
public class MyDbExecutionStrategy : DbExecutionStrategy
{
public MyDbExecutionStrategy(int maxRetryCount, TimeSpan maxDelay)
: base(maxRetryCount, maxDelay) { }
protected override bool ShouldRetryOn(Exception ex)
{
return true; // for simplicity
}
}
我不得不做另一个包装器并手动捕获 Oracle 错误来克服这个问题。当我调试和模拟数据库错误时,执行始终进入ShouldRetryOn
方法。