Re: Urgent! C++ ESQL, db connection doesn't exist when it is used by a thread which didn't create it. -
06-01-2004
, 10:18 AM
Hello,
General rules for using ESQL with threads.
===========================================
(1) Have a global mutex and use the mutex when acquiring connections;
(2) Although you should be okay with a golbal SQLCA structure, it is
always safer to have variables local to a thread. Make the SQLCA
structure local to the thread;
(3) Minimize the use of dynamic sql (if you use dynamic sql, then understand that
the name space is global to the entire process) so do something like making
the prepared statement identifiers unique. For example:
sprintf (hostvar, "name%05d", pthread_self()) ;
(4) Cursors and connections are scoped by thread so if you have to use a
connection on a thread other than the one that acquired it, use the
#define CONNECTIONS_ARE_SHARED_ACROSS_THREADS 1, in your .cp file(s).
The cs_objects structure is an internal Sybase structure used to store context and
connection information. When an 'EXEC SQL CONNECT ...' statement is issued by
ESQL, keep in mind that it translates to ctlib calls, wherein a context
structure is allocated and populated with the users environment information,
such as locale info and a connection structure as well with the login info and a
command structure(s) for executing sql commands. |