[unixODBC-support] connection pooling & multiple environments

Suresh tsureshkumar at gmail.com
Thu Sep 2 11:16:45 BST 2004


hi,

   i've seen similar code from this mailing list. there is a situation
where in my application, i hve to create two environment handles. 
This does not work with connection pooling enabled.   Run the below
application with CPTimeout set to 5 and run the program with argv4 as
9. This gives segmentation fault.

   Can anybody help me out? or am I totally wrong in the concept?

    Are there any ways to flush out the pools before starting a new environment?

regards,
suresh.

regards,
suresh

#include <sql.h>
#include <sqlext.h>
#include <stdio.h>

int main(int argc, char **argv)
{
        char *DSN=argv[1];
        char *user=argv[2];
        char *pass=argv[3];
        int waitTime=atoi(argv[4]);

        int i;

        SQLHENV hEnv;
        SQLHDBC hDbc;
        SQLHSTMT hStmt;

        for(i=0; i<2; i++) {
                SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv);
                SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER)SQL_OV_ODBC3, 0);
                SQLSetEnvAttr(hEnv, SQL_ATTR_CONNECTION_POOLING,
(SQLPOINTER)SQL_CP_ONE_PER_HENV, 0);

                printf("Iteration %d\n", i+1);
                /* Pooled environment is now set up, make a connection  */
                SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hDbc);
                SQLConnect(hDbc, DSN, SQL_NTS,
                        user, SQL_NTS, pass, SQL_NTS);
                printf("Connected.\n");

                /* Connection made, now make a statement */
                SQLAllocHandle(SQL_HANDLE_STMT, hDbc, &hStmt);
                SQLExecDirect(hStmt, "show tables", SQL_NTS);
                printf("Query made.\n");

                /* Now disconnect */
                SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
                SQLDisconnect(hDbc);
                SQLFreeHandle(SQL_HANDLE_DBC, hDbc);
                SQLFreeHandle(SQL_HANDLE_DBC, hDbc);
                printf("Disconnected and freed.\n");

                /* And wait the specified number of seconds */
                sleep(waitTime);
                SQLFreeHandle(SQL_HANDLE_ENV, hEnv);
        }
        return 0;
}



More information about the unixODBC-support mailing list