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.
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.
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.
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.
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:
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With