Oracle.DataAccess.Client.OracleException ORA-03135:连接失去联系 [英] Oracle.DataAccess.Client.OracleException ORA-03135: connection lost contact

查看:4052
本文介绍了Oracle.DataAccess.Client.OracleException ORA-03135:连接失去联系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.net服务连接到Oracle数据库在每次请求。它工作正常,在开始,但要求一定次数后,我开始越来越:

I have a .Net service that connects to an Oracle database on every request. It works fine at the beginning, but after some number of requests I start getting:

Oracle.DataAccess.Client.OracleException ORA-03135: connection lost contact
   at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure)
   at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src)
   at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
   at Oracle.DataAccess.Client.OracleCommand.ExecuteReader()
   at MyApp.Services.OracleConnectionWithRetry.ExecuteReader(OracleCommand command)
   ...

任何想法可能是什么问题?我处理所有的连接,结果和参数。在此服务的负荷,很好,非常低的。

Any idea what might be the problem? I dispose all the connections, results and parameters. The load on this service is, well, very low.

推荐答案

这是因为你的code请求从Oracle连接池的连接,并连接池返回到Oracle数据库断开连接/无效连接。 ODP.NET本身并不测试发送到客户端的连接的连接状态。

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.

因此​​,为了您检查连接状态==是安全的,无论是打开从池中当你接收到的连接Connection.Open()

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

让ODP.NET做检查,你通过设置验证在web.config中连接字符串连接=真

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.

我用第三种方法是使用异常的。首先是乐观的,并使用whateven从连接池返回的连接。如果你得到一个ORA - 3135然后请求一个新的连接,并再次执行查询像一个while循环。在最好的情况下,你可以得到你的第一个有效的连接和您的查询将执行。在最坏的情况下,在池中的所有连接均失效在这种情况下,code将被执行N次(其中N是连接池的大小)。

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).

这篇关于Oracle.DataAccess.Client.OracleException ORA-03135:连接失去联系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆