当前位置: 代码迷 >> Sybase >> HPUNIX & SYBASE ASE12.5 ESQL多线程连接数据库有关问题
  详细解决方案

HPUNIX & SYBASE ASE12.5 ESQL多线程连接数据库有关问题

热度:1529   发布时间:2013-02-26 00:00:00.0
HPUNIX & SYBASE ASE12.5 ESQL多线程连接数据库问题
启动线程后连接数据库,程序运行到EXEC SQL CONNECT时卡住,无coredump,无提示错误信息,请较各位大侠有没遇到过类似情况,如何解决?

C/C++ code
intconnect(const char* username, const char* password, const char* database){    EXEC SQL BEGIN DECLARE SECTION;    char    strUsername[DC_NAMSIZ];    char    strPassword[DC_NAMSIZ];    char    strDatabase[DC_NAMSIZ];    char    strConnection[DC_NAMSIZ];    EXEC SQL END DECLARE SECTION;    memset(strUsername, 0x00, sizeof(strUsername));    memset(strUsername, 0x00, sizeof(strPassword));    memset(strDatabase, 0x00, sizeof(strDatabase));    memset(strConnection, 0x00, sizeof(strConnection));    sprintf(strUsername, "%s", username);    sprintf(strPassword, "%s", password);    sprintf(strDatabase, "%s", database);    EXEC SQL WHENEVER SQLERROR CALL errHandler();    EXEC SQL WHENEVER SQLWARNING CALL msgHandler();    EXEC SQL WHENEVER NOT FOUND CONTINUE;    pthread_mutex_lock(&mtx);    EXEC SQL CONNECT :strUsername IDENTIFIED BY :strPassword;    EXEC SQL USE :strDatabase;    pthread_mutex_unlock(&mtx);    printf("connected.\n");       if ( sqlca.sqlcode != 0 )        return FAILURE;       EXEC SQL EXECUTE IMMEDIATE "set chained off";       return SUCCEED;}


C/C++ code
void*qthread(void* args){    EXEC SQL BEGIN DECLARE SECTION;    char    strGroup[DC_NAMSIZ];    EXEC SQL END DECLARE SECTION;    char    strUsername[DC_NAMSIZ];    char    strPassword[DC_NAMSIZ];    char    strDatabase[DC_NAMSIZ];    int     semid = ((thread_args*)args)->semid;    int     msqid = ((thread_args*)args)->msqid;    memset(strUsername, 0x00, sizeof(strUsername));    memset(strPassword, 0x00, sizeof(strPassword));    memset(strDatabase, 0x00, sizeof(strDatabase));    sprintf(strUsername, ((thread_args*)args)->username);    sprintf(strPassword, ((thread_args*)args)->password);    sprintf(strDatabase, ((thread_args*)args)->database);    if ( FAILURE == connect(strUsername, strPassword, strDatabase) )    {        printLog(__FILE__, __LINE__, "连接数据库失败,请检查用户名/密码!");        return NULL;    }        ...


------解决方案--------------------------------------------------------
还没有用过C/C++调用sybase.如果光是sybase问题我还可以帮你考虑一下.