Oracle.DataAccess.Client.OracleException ORA-03135: connection lost contact

无人久伴 提交于 2019-11-28 18:59:38

It happens because your code requests a connection from the Oracle Connection Pool and the connection pool returns a disconnected / stale connection to the Oracle DB. ODP.NET does not itself test the connection status of the connection sent to client.

So to be safe, either you check the connection status == Open for the connection received from the pool when you do a Connection.Open()

OR

let ODP.NET do the checking for you by setting Validate Connection = true in your connection string in web.config.

Both this methods have a impact on performance as they test the connection status each time you need to connect to the database.

A third option which I use is use of exceptions. First be optimistic and use whateven connection is returned from the connection pool. If you get a ORA - 3135 then request a new connection and execute your query again like a while loop. In best case, you can get your 1st connection as valid and your query will execute. In worst case, all the connections in your pool are stale in which case the code will be executed N time (where N is the connection pool size).

I have seen this happen too; try turning off connection pooling with "Pooling=false" in the connection string. I have a theory that idle connections in the pool expire, but ODP.NET does not realize that they have expired, and then when your app grabs one and tries to do something you get that exception.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!