Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 904
Grzenio Avatar asked Jul 30 '10 09:07

Grzenio


People also ask

What is the ora-03135 connection lost contact error?

In this article i would like to give more information about the ORA-03135: connection lost contact error in detail. With this i would also like to give the resolution of this error. The error is most common error coming in the oracle and i need to explain it with detail.The ORA-03135 is an error that stems from the latter.

Why is my connection to the Oracle DB not working?

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.

What is Connection Lost error in Salesforce?

The error is connection lost error. It simply means the server unexpectedly terminated or was forced to terminate and due to that the connection has lost. There are so many times this error will occur when we are working with complex set of tables.

Does ora-03135 work for large files?

It works fine for really small files (<5 KB), but for larger ones (e.g. 44 KB) I get an error: "ORA-03135: connection lost contact". I don't think it's timing out, as the exception occurs within a second of executing the command. I tried setting both of the following in my connection string, but to no avail:


1 Answers

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

like image 114
sandyiit Avatar answered Nov 03 '22 03:11

sandyiit