demo1.ec
Posted in 2000
A user compiling the ESQL/C demo1.ec on Linux against a remote HP-UX database server found the program died at the start with error -404 ("cursor released with FREE"), which made no sense for the code shown, and wondered whether the server was refusing remote connections or listening on a different port than /etc/services says. Art Kagel first claimed there was no CONNECT (then retracted); Rudy Fernandes suggested the CONNECT was silently failing and advised checking sqlca/error codes right after it; Jonathan Leffler asked which CSDK/engine versions, whether "1. step" actually printed, and the sqlhosts/INFORMIXSERVER/services settings, and disputed the claim that WHENEVER SQLERROR ignores CONNECT failures. No resolution is recorded in the thread.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL, Platform-Specific Issues
Hi All,
I can't run properly the demo1.ec (an ESQL/C example program)
Our environment is composed of an application server and a database
server. Both run HP-UX.
I want to run ESQL/C programs on my Linux that will query the database
server. Compilation is fine, but when I start the program, the
"WHENEVER
SQLERROR STOP" throws exception 404 (statement names a cursor that has
been released with the FREE statement"), which I believe is not true.
I was wondering that maybe the database server configuration forbids
communication with any other machine except the application server, or
that maybe it listens on a different port than that mentioned in
/etc/services (port 1525, service name execsql). How can I check this?
Below is the source I'm using. It does not get past "1.step".
-------------------------cut----------------
#include <stdio.h>
EXEC SQL define ID_LEN 1;
/* EXEC SQL define AMOUNT_LEN 40;*/
EXEC SQL define TEXT_LEN 20;
main()
{
EXEC SQL BEGIN DECLARE SECTION;
char id[ ID_LEN + 1 ];
int amount;
char text[ TEXT_LEN + 1 ];
EXEC SQL END DECLARE SECTION;
printf( "Testing program for ESQL-C.\\n\\n");
EXEC SQL WHENEVER SQLERROR STOP;
EXEC SQL connect to 'test';
printf( "1. step\\n");
EXEC SQL declare my cursor for
select id, text
into :id, :text
from primary;
printf( "2. step\\n");
EXEC SQL open my;
for (;;)
{
EXEC SQL fetch my;
if (strncmp(SQLSTATE, "00", 2) != 0)
break;
printf("%s %s\\n",id, text);
}
if (strncmp(SQLSTATE, "02", 2) != 0)
printf("SQLSTATE after fetch is %s\\n", SQLSTATE);
EXEC SQL close my;
EXEC SQL free my;
EXEC SQL disconnect current;
printf("\\nEnd of the test program.\\n\\n");
}
-------------------- cut -------------------------
--
Milos Prudek
Your code never connects to the database server! You need either a CONNECT
TO statement or at least a DATABASE statement.
Art S. Kagel
Milos Prudek wrote:
>
> Hi All,
>
> I can't run properly the demo1.ec (an ESQL/C example program)
>
> Our environment is composed of an application server and a database
> server. Both run HP-UX.
>
> I want to run ESQL/C programs on my Linux that will query the database
> server. Compilation is fine, but when I start the program, the
> "WHENEVER
> SQLERROR STOP" throws exception 404 (statement names a cursor that has
> been released with the FREE statement"), which I believe is not true.
>
> I was wondering that maybe the database server configuration forbids
> communication with any other machine except the application server, or
> that maybe it listens on a different port than that mentioned in
> /etc/services (port 1525, service name execsql). How can I check this?
>
> Below is the source I'm using. It does not get past "1.step".
>
> -------------------------cut----------------
>
> #include <stdio.h>
>
> EXEC SQL define ID_LEN 1;
> /* EXEC SQL define AMOUNT_LEN 40;*/
> EXEC SQL define TEXT_LEN 20;
>
> main()
> {
> EXEC SQL BEGIN DECLARE SECTION;
> char id[ ID_LEN + 1 ];
> int amount;
> char text[ TEXT_LEN + 1 ];
> EXEC SQL END DECLARE SECTION;
>
> printf( "Testing program for ESQL-C.\\n\\n");
> EXEC SQL WHENEVER SQLERROR STOP;
> EXEC SQL connect to 'test';
>
> printf( "1. step\\n");
> EXEC SQL declare my cursor for
> select id, text
> into :id, :text
> from primary;>
> printf( "2. step\\n");
> EXEC SQL open my;
> for (;;)
> {
> EXEC SQL fetch my;
> if (strncmp(SQLSTATE, "00", 2) != 0)
> break;
>
> printf("%s %s\\n",id, text);
> }
>
> if (strncmp(SQLSTATE, "02", 2) != 0)
> printf("SQLSTATE after fetch is %s\\n", SQLSTATE);
>
> EXEC SQL close my;
> EXEC SQL free my;
>
> EXEC SQL disconnect current;
>
> printf("\\nEnd of the test program.\\n\\n");
> }
>
> -------------------- cut -------------------------
>
> --
> Milos Prudek
"Art S. Kagel" wrote: > > Your code never connects to the database server! You need either a CONNECT > TO statement or at least a DATABASE statement. But I do have 'connect to': > > printf( "Testing program for ESQL-C.\\n\\n"); > > EXEC SQL WHENEVER SQLERROR STOP; > > EXEC SQL connect to 'test'; This line, I believe, connects to database 'test' on the default server, as specified by INFORMIXSERVER environment variable. And that variable is specified correctly. Also the sqlhosts file points to correct IP address for the Informix server. -- Milos
Milos Prudek wrote:
> I can't run properly the demo1.ec (an ESQL/C example program)
>
> Our environment is composed of an application server and a database
> server. Both run HP-UX.
>
> I want to run ESQL/C programs on my Linux that will query the database
Both machines are running HP-UX, but one of them is running
Linux? I'm a little confused about your setup.
> server. Compilation is fine, but when I start the program, the
> "WHENEVER
> SQLERROR STOP" throws exception 404 (statement names a cursor that has
> been released with the FREE statement"), which I believe is not true.
Given the source I see, I don't see how the code can be referring
to a freed cursor.
> I was wondering that maybe the database server configuration forbids
> communication with any other machine except the application server, or
> that maybe it listens on a different port than that mentioned in
> /etc/services (port 1525, service name execsql). How can I check this?
Are you seeing the one-step message?
If you are, then database connectivity isn't a problem.
If you aren't, then database connectivity is the problem.
Which version of ESQL/C (CSDK) are you using on Linux? On HP-UX?
Which version of the database are you running on HP-UX?
If connectivity is the problem, what's the setting of INFORMIXSERVER
on the Linux box, what does the entry in $INFORMIXDIR/etc/sqlhosts
look like (it does use sesoctcp doesn't it?), and what does the entry
in /etc/services (or NIS/NIS+) look like? Is it the same as the
entry on the HP-UX database server? Have you configured the HP-UX
box for remote access (yes, because you use it in a C/S configuration).
Does the server name on Linux match the server name for the net connection
on the HP-UX box.
> Below is the source I'm using. It does not get past "1.step".
You see the "1.step" but you don't see "2.step"? Or you don't see "1.step"?
> -------------------------cut----------------
>
> #include <stdio.h>
>
> EXEC SQL define ID_LEN 1;
> /* EXEC SQL define AMOUNT_LEN 40;*/
> EXEC SQL define TEXT_LEN 20;
>
> main()
> {
> EXEC SQL BEGIN DECLARE SECTION;
> char id[ ID_LEN + 1 ];
> int amount;
> char text[ TEXT_LEN + 1 ];
> EXEC SQL END DECLARE SECTION;
>
> printf( "Testing program for ESQL-C.\\n\\n");
> EXEC SQL WHENEVER SQLERROR STOP;
> EXEC SQL connect to 'test';
You *do* connect to the database. And using WHENEVER ERROR STOP
is good for test programs.
> printf( "1. step\\n");
> EXEC SQL declare my cursor for
> select id, text
> into :id, :text
> from primary;
There's no intrinsic reason why this shouldn't work. I would
never use a cursor called 'my', and I probably wouldn't have a
column called text in a table (because TEXT is a type) and I
would be cautious about using a table called primary (though it
is creating a column called primary that's really hard, unless
you set DELIMIDENT in the environment).
> printf( "2. step\\n");
> EXEC SQL open my;
> for (;;)
> {
> EXEC SQL fetch my;
> if (strncmp(SQLSTATE, "00", 2) != 0)
> break;
>
> printf("%s %s\\n",id, text);
> }
>
> if (strncmp(SQLSTATE, "02", 2) != 0)
> printf("SQLSTATE after fetch is %s\\n", SQLSTATE);
>
> EXEC SQL close my;
> EXEC SQL free my;
>
> EXEC SQL disconnect current;
>
> printf("\\nEnd of the test program.\\n\\n");
> }
--
Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net)
Guardian of DBD::Informix v1.00.PC1 -- see http://www.perl.com/CPAN
#include <disclaimer.h>
Your CONNECT statement is probably failing (Connect failures do not respond to WHENEVER SQLERROR). Add code after your CONNECT stmt to check what error you are getting. Rudy Milos Prudek wrote: > Hi All, > > I can't run properly the demo1.ec (an ESQL/C example program) > > Our environment is composed of an application server and a database > server. Both run HP-UX. > > I want to run ESQL/C programs on my Linux that will query the database > server. Compilation is fine, but when I start the program, the > "WHENEVER > SQLERROR STOP" throws exception 404 (statement names a cursor that has > been released with the FREE statement"), which I believe is not true. > > ... > Milos Prudek
Oops, sorry I missed it. <He slinks sheeppishly away.....> Art S. Kagel Milos Prudek wrote: > > "Art S. Kagel" wrote: > > > > Your code never connects to the database server! You need either a CONNECT > > TO statement or at least a DATABASE statement. > > But I do have 'connect to': > > > > printf( "Testing program for ESQL-C.\\n\\n"); > > > EXEC SQL WHENEVER SQLERROR STOP; > > > EXEC SQL connect to 'test'; > > This line, I believe, connects to database 'test' on the default server, > as specified by INFORMIXSERVER environment variable. And that variable > is specified correctly. Also the sqlhosts file points to correct IP > address for the Informix server. > > -- > Milos
Rudy Fernandes wrote: > Your CONNECT statement is probably failing (Connect failures do not > respond to WHENEVER SQLERROR). Add code after your CONNECT stmt to check > what error you are getting. Which version of ESQL/C are you claiming has this bug in it? I just tested the code shown in the attachment (with both sqlerror and plain error) and got the same result -- a dramatic stop. So, with CSDK 2.40.UC1 on Solaris 7, ESQL/C definitely does handle errors from CONNECT with WHENEVER. -- Yours, Jonathan Leffler (Jonathan.Leffler@Informix.com) #include <disclaimer.h> Guardian of DBD::Informix v1.00.PC1 -- http://www.perl.com/CPAN "I don't suffer from insanity; I enjoy every minute of it!"