1

使用 ASP.NET Core 2.2、Dapper Oracle 1.0.1 和托管 Oracle ODP 驱动程序 2.19.50 使用以下代码发出简单的读取查询。下面的代码可能每分钟被不同的 API 使用者调用约 10 次。

// connectionString = Data Source=thehost:1521/blah;User Id=bob;Password=bob
using (IDbConnection dbConnection = new OracleConnection(this.connectionString))
{
    dbConnection.Open();
    var results = dbConnection.Query<MyDBModelClass>(myQuery);
    return results;
}

大多数情况下,上述工作正常,但出现了看似随机的 .NET 异常,如下所示。

SocketException:连接尝试失败,因为连接方一段时间后没有正确响应,或者连接的主机没有响应,建立连接失败

OracleInternal.Network.ReaderStream.Read(OraBuf OB) NetworkException: ORA-12570: Network Session: Unexpected packet read error

OracleInternal.Network.ReaderStream.Read(OraBuf OB) OracleException:

ORA-12570:网络会话:意外的数据包读取错误 Oracle.ManagedDataAccess.Client.OracleException.HandleError(OracleTraceLevel 级别,OracleTraceTag 标记,OracleTraceClassName 类名,OracleTraceFuncName funcName,异常 ex,OracleLogicalTransaction oracleLogicalTransaction)

打开跟踪后OracleConfiguration.TraceLevel = 7,驱动程序记录了很多异常,这些异常发生在这些块中:

(PRI) (EXT) Connection.connect()
(PRI) (ONS) (EXT) Connection.connect()
(PRI) (ONS) (EXT) ReceiverThread.establishConnection()
(PRI) (ONS) (ENT) Concurrency.setListFailed()
(PRI) (ONS) (EXT) Concurrency.setListFailed()
(PRI) (ONS) (ENT) ONS.nodeListFailOver()
(PRI) (ONS) (EXT) ONS.nodeListFailOver()
(PRI) (ONS) (ENT) ReceiverThread.establishConnection()
(PRI) (ONS) (ENT) Connection.connect()
(PRI) (ENT) Connection.connect()
(PRI) (ONS) (ERR) Connection.connect() (txnid=n/a) System.IO.IOException: The operation is not allowed on non-connected sockets.
   at System.Net.Sockets.NetworkStream..ctor(Socket socket, FileAccess access, Boolean ownsSocket)
   at OracleInternal.NotificationServices.Connection.connect()

上述异常使我相信我可能不会创建/处置/等。连接是否正确,因为它看起来像是在尝试从关闭的连接中读取?

上面的代码中有什么明显导致这种情况的吗?

4

1 回答 1

0

这修复了正在发生的随机错误。不知道为什么。更新连接字符串以包含超时,例如;Connection Timeout=600

于 2019-11-07T16:57:39.247 回答