简体   繁体   中英

Watching state of OracleConnection

I'm using ODP on my Oracle DB application.I registered to OracleConnection.StateChange event for watching the state of the connection. When i disconnect the db connection the event fires but for example if the internet connection is lost there is no action.

How can i handle these kind of(internet conenction lost etc.) situations via the StateChange event?

Or do i have to create a thread for checking the connnection state regularly? If yes how can i check the connection because i checked the state and it seems to be open even i unplug the internet cable.

Regards.

The common way is to issue an unexpensive sql statement just before the connection is used for something. On oracle it is something like 'select 1 from dual', on ms-sql 'select 1'. This sql forces a roundtrip to the server and lost connection to the server is reported.

JBoss is using something called check-valid-connection-sql . Others have other names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM