Limit ConnectionTimeout for Oracle Database

我与影子孤独终老i 提交于 2019-12-25 01:44:18

问题


How can I limit timeout for connecting to Oracle Database? I use devart dotConnect Express Edition on data access layer. I tried add Connection timeout=30; to connection string but it doesn't give right result (even a little weird, first time it really limits to 30 seconds, but not on all connection attempts). Then I find out that

Connection Timeout Time (in seconds) to wait while trying to establish a connection before terminating the attempt and generating an error. A value of 0 indicates no limit. The default value is 15 seconds. Available in Direct mode only.

from Devart site

I can't use direct mode because I use Express Edition. Then I tried to set this parameters in TNSNAMES.ORA

DB1 =
  (DESCRIPTION =
    (CONNECT_TIMEOUT=11)
    (TRANSPORT_CONNECT_TIMEOUT=10)
    (ADDRESS_LIST =
       (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.100.8)(PORT = 1521)
       )
    )
    (CONNECT_DATA =
       (SERVICE_NAME = DB1)
    )
  )

Still works incorrect. OK, going down and try yo set connection timeout in SQLNET.ORA

SQLNET.INBOUND_CONNECT_TIMEOUT = 5

Another one fail! Does anyone know how can I set timeout restricting allowing time to connect to DB1? It now finishes connection (connection fails) for approximately 20 seconds.


回答1:


I've never used Devart's dotConnect library, but looking at the OracleConnection class it seems that you should be able to close the connection after a certain period of time by calling OracleConnection.Close(). This should take you out of the blocking state while you're trying to Open the connection.

This is not exactly like setting the timeout, but it may work. Furthermore, check the ConnectionTimeout property when you're debugging this code in order to confirm that the timeout is properly set.




回答2:


OracleConnection.ConnectionTimeout works in Direct mode only. It is ignored when connection is established via Oracle client, which manages connection in this case.



来源:https://stackoverflow.com/questions/8077885/limit-connectiontimeout-for-oracle-database

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