I am writing a serviceapplication with doa. When the service is starting after a reboot of the server - how can the service detect that oracle is running.
You can check the availability of Oracle by using TOracleSession.CheckConnection. If connection has lost, you can use the method TOracleSession.Reconnect to reinstall the connection.
If you attempt to make a connection with a database instance that is not started you should get an ORA-01034 error (ORACLE not available). You can test for this in your service:
Code:
try
MySession.Connected := True;
except
on E: EOracleError do
begin
if E.ErrorCode = 01034 then
ShowMessage('Instance not started')
else
ShowMessage(E.Message);
end;
end;
Is TOracleSession.Reconnect still a valid method? It's not in the documentation. It worked with v3.4.6.4 but when I tried to recompile with v4.0.7 I received an error: "Undeclared Identifier: 'Reconnect'".
Should TOracleSession.CheckConnection(Reconnect: Boolean) be used instead?
This would indeed cause some overhead. It may also require additional application logic to recover from a lost connection, depending on where, when and how the connection was lost. It's not so easy to handle this completely transparent in the background.