Re: Example of remote DB access via ESQL/C
Posted in 1997
>From: Tim Simms <tsimms@intr.net> >Date: Sun, 9 Mar 1997 22:37:56 -0500 >X-Informix-List-Id: <news.34989> > >I was wondering if anyone could share an example of connecting an ESQL/C >program to a remote DB server. int main(int argc, char **argv) { EXEC SQL WHENEVER ERROR STOP; EXEC SQL DATABASE "remotedb@server"; return(0); } Or int main(int argc, char **argv) { EXEC SQL WHENEVER ERROR STOP; EXEC SQL CONNECT TO "remotedb@server"; return(0); } >What requirements are there? You need an ESQL/C Development licence on the machine where you compile the program. You need an ESQL/C Runtime licence (or an Informix-Connect licence) on the machine where you are going to run the program if it doesn't already have one. You need the database system up and running on the remote system. You need to be able to connect to it using, for example, DB-Access. If you can't connect using the standard Informix utilities, it is unlikely that your ESQL/C program will fare any better. >Do the libs have to be on the same computer as the program? If you compile with static linking, then your program is self-contained as far as libraries are concerned. You still need the runtime system, both to be legal and to get the program to work correctly (message files, etc). If you compile with shared linking, then you need the libraries on the machine where the program is run. >Do you need to compile the ESQL source on the same machine as the server, >or on the one it will be running on, or does it even matter? If they are the same hardware type, it doesn't matter. If they're different, it does, of course. If you're using a version of ESQL/C which has shared libraries but which lists the shared libraries by pathname on the linker command line, then either the code should be compiled on the machine where it will be run or the runtime machine has to have $INFORMIXDIR in the same directory (by name) as on the machine where the program is compiled. This seems to afflict 7.1x; 7.2x has this fixed. >Do the Env vars need to be set? Yes. You may be able to get away with fewer environment variables when compiling than when running, but you'll need the correct environment sooner or later. >A simple example would be really helpful! See above. The CONNECT version only works with 6.00 or later versions of ESQL/C. Neither sample program has been compiled -- there could be a silly mistake in them, but I think they're OK. You'd need to fix the correct database and server name, of course, or make that into a variable, or whatever. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>