Hi Guys,
Is there any way to handle "database *** was disconnected" condition in progress client? I have a small task to create agent that will pull data from database and make some calculations. And in case when DB stopped, this agent must wait when connection will be restored. Checking database connection and reconnecting to database is not an issue. But I have trouble when database stops in the middle of "for each", for example. Then I get message "database *** was disconnected" and I haven't found any way to catch or suppress it.
My simple example:
DO ON ERROR UNDO, RETRY
ON STOP UNDO, RETRY
ON QUIT UNDO, RETRY
ON END-KEY UNDO, RETRY:IF RETRY THEN
DO:
MESSAGE "(2)" ERROR-STATUS:GET-MESSAGE(1) ERROR-STATUS:GET-NUMBER(1)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
LEAVE.
END.run testConnect.
END.
PROCEDURE testConnect:FOR EACH Order ON ERROR UNDO, RETRY
ON STOP UNDO, RETRY
ON QUIT UNDO, RETRY
ON END-KEY UNDO, RETRY:IF RETRY THEN
DO:
MESSAGE (1) ERROR-STATUS:GET-MESSAGE(1) ERROR-STATUS:GET-NUMBER(1)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
LEAVE.
END.
PAUSE 1 NO-MESSAGE.
END.end.
if you stop database right after you run this procedure you will see this message:
database sports2000 was disconnected (1015)
and none of retries catched this condition.
OpenEdge 10.1C04.
An db disconnect is an "untrappable stop" condition, which means that the AVM will transfer control to the top-level ".p" program. That is the only place where this kind of "stop" condition can be caught and handled.
I had a program which had to deal with this kind of thing before as well, and IIRC it looked something like this:
REPEAT:
IF RETRY THEN
RUN recovery-code.
DO ON STOP UNDO, RETRY:
RUN something.p.
END.
LEAVE.
END.
This was written and stored in the top-level ".p" program.
And at the top level you can have code to check your database connections. So you can do stuff like this:
IF RETRY THEN DO:
IF (NOT CONNECTED ("foo")) THEN RUN reconnect-code ("foo").
IF (NOT CONNECTED ("bar")) THEN RUN reconnect-code ("bar").
RUN recovery-code.
END.
I forgot to also mention that when you lose your database connection, the server will roll back an incomplete transaction if there was one and release all your locks. So when you later reconnect, you are starting in a clean state with nothing of yours active in the database.
thank you, guys! now it is working.
But I have another issue I can't suppress stop messages:
Error reading socket, ret = ******, errno = *. (778)
Press space bar to continue.
and
Disconnect from server; database is being shutdown. (2959)
I tried:
DEFAULT-WINDOW:HIDDEN = TRUE.
PAUSE 0 BEFORE-HIDE.
and it doesn't help.
In the attachment you can find my example (connection client-server).
What's interesting, that if I take off "no-error" from find first, it works as expected (I just see "GOT IT!!!").
find first Order no-error.
run Sleep (3000).
find first Order no-error.
but it doesn't help either because I just can't change all "find first" places in my procedure.
Is there any way to suppress these message once and forever?
as long as one is not doing 2-phase commits, in which case there's the risk of getting a "limbo transaction".