Kbase 19977: Error 1012 when when using CONNECTED Function
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  25/10/2010 |
|
Status: Verified
SYMPTOM(s):
Error 1012 when when using CONNECTED Function
Using the CONNECTED Function, e.g. If NOT CONNECTED ("Sports")
** Warning -- database <name> is already connected. (1012)
FACT(s) (Environment):
All Supported Operating Systems
Progress/OpenEdge Product Family
OpenEdge Category: Language (4GL/ABL)
CAUSE:
The above error can be generated, if the CONNECTED Function is used to test whether you are connected to the database, after a DISCONNECT Statement has been issued. One way this Error can occur, is if you have coded interaction with the database inside a CONNECT statement. For example, the following code will generate Error (1012). Connect to the Sports database before you run this code from the Procedure Editor.
IF CONNECTED ("sports") THEN
DO:
FIND FIRST customer NO-LOCK.
DISCONNECT sports.
MESSAGE "disconnecting Sports" VIEW-AS ALERT-BOX.
END.
IF NOT CONNECTED ("sports") THEN
DO:
CONNECT sports -1.
MESSAGE "Sports Connected" VIEW-AS ALERT-BOX.
END.
Notice the error is generated at the line: IF NOT CONNECTED ("sports"), even though a DISCONNECT command has been issued previously
FIX:
To get around this is to break up some of these statements into separate procedures, namely the Find Statement. The following code will connect to the database, find the first customer, disconnect from the database, reconnect to the database, find the last customer, and then finally disconnect from the database without Error.
RUN CONNECT.p.
RUN FindFirst.p.
IF CONNECTED ("sports") THEN
DO:
DISCONNECT sports.
MESSAGE "disconnecting sports" VIEW-AS ALERT-BOX.
END.
IF NOT CONNECTED ("sports") THEN
DO:
RUN CONNECT.p.
MESSAGE "reconnecting sports" VIEW-AS ALERT-BOX.
RUN FindLast.p.
DISCONNECT sports.
MESSAGE "Disconnect sports" VIEW-AS ALERT-BOX.
END.
Below are all the procedures used for this example.
/**************** Connect.p *************************/
CONNECT sports -1
/***************** FindFirst.p ***********************/
FIND FIRST customer NO-LOCK.
MESSAGE "First Customer number is " customer.cust-num
VIEW-AS ALERT-BOX.
/******************* FindLast.p ***********************/
FIND LAST customer NO-LOCK.
MESSAGE "Last Customer number is " customer.cust-num
VIEW-AS ALERT-BOX.