Re: Background Tasks
Posted in 1995
How are you running the program in the background, and when are you opening the connection to the database? Given that you are having problems, I suspect that you are opening the connection to the database, forking a child process and then having the parent process die to allow the child to continue in the background. This won't work with ESQL/C; the child needs its own connection to the database. When the parent process dies, the associated database connection is terminated and because the child does not have its own database connection, everything it tries to do with the database fails. It is best if you decide in advance that you are going to run in the background and delay opening the database until after the fork -- that simplifies everything. Failing that, you need to go into background mode at a transaction boundary, and you should have no important data in temporary tables, or in cursors declared WITH HOLD. You then do the fork; the child uses sqldetach() to clean up (its version of) the parents connection data, and then connects to the database, and starts processing. If you have no transactions on the database, then all cursors should be closed and tables unlocked, and so on. Basically, your child process needs a brand new session, and can inherit no state information from the parent except via regular program variables. All prepared statements and declared cursors must be re-prepared and re-declared by the child. Anything else is fraught with problems, indeterminacies and version dependencies. I don't even want to try thinking about the permutations that might be available; neither do you. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h> >From: dray@icsware.com >Date: Mon, 30 Oct 1995 16:59:46 GMT >X-Informix-List-Id: <news.18407> > > I have a program that uses embedded sql commands and need to >run it as a background task. This is in C/UNIX. Now I know how to >run a background task but I can't keep this running after I log off. >I have other non INFORMIX processes running in this mode and there >is no problem with them. If any one can help I thank them in advance.