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

前端 未结 2 603
一个人的身影
一个人的身影 2020-12-13 22:36

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:



        
2条回答
  •  独厮守ぢ
    2020-12-13 22:44

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

提交回复
热议问题