How may I perform OCIPing (or equivalent) from a .Net application?

33 Views Asked by At

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.

1

There are 1 best solutions below

0
ibre5041 On

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 call OCIPing(). 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:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters\KeepAliveTime

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 specific ioctl() on a TCP socket and instruct Kernel to send those probes. There are 3 tunables to be enabled in registry:

  • delay before 1st probe is sent (KeepAliveTime)
  • delay between probes (KeepAliveInterval)
  • number of lost probes, after this limit is reached, TCP connection is just cut off and your app will not be able to write into se socket anymore.