A legacy C++ application routine pings our Oracle 11g database using the OCI C Library method OCIPing():
sword OCIPing ( OCISvcCtx *svchp,
OCIError *errhp,
ub4 mode );
This application is being replaced by a modern C#.Net application and I cannot see an obvious API providing the same functionality. Does one exist that allows calls either .Net library, REST interface, etc?
What is the right way to do this? I imagine the C API can be called through a .Net application but if there's a more modern replacement API it would be preferred.
I do not know how it is in case of C#.Net, but in case of Java Oracle managed to extend JDBC standard by adding
boolean isValid(int timeout) throws SQLException. Newer version of JDBC drivers do callOCIPing(). It is the simplest fastest way to detect that DB connection is still alive.If C#.Net does not have anything like that, you will have to call some simple SQL regularly.
Another option: you can also use TCP Keepalive in Oracle connection by adding
(ENABLE=BROKEN)into databases connection string and tuning some Kernel parameters(registers). Like:In such a case probe packets will not be sent by your application but by OS Kernel. By adding
(ENABLE=BROKEN), the driver will call specificioctl()on a TCP socket and instruct Kernel to send those probes. There are 3 tunables to be enabled in registry: