performance problem
I have written an application that is querying databases ( access or postgreSQL ) with the use of ODBC. The database can be large.
I have performance issues ( both for access and postgreSQL ), that depends of the user. With some users, the queries (i only do SELECT queries ) are fine and take only a few seconds, and for other users, it can take much more, sometimes several minutes.
The problem doesn't seem to be the size of the database or the type of the database, it's just that on some PC it works fine and on others it's very slow.
here is basically what i do:
retcode=SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
retcode=SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3,0);
else
continue;
if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
retcode=SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
else
continue;
// Set Connection Attribute
if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
retcode=SQLSetConnectAttr(hdbc,SQL_ATTR_TRACE,(SQLPOINTER)SQL_OPT_TRACE_OFF,NULL);
retcode=SQLSetConnectAttr(hdbc,SQL_ATTR_ACCESS_MODE,(SQLPOINTER)SQL_MODE_READ_ONLY,NULL);
}
else
continue;
if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
retcode=SQLConnect(hdbc, (SQLCHAR*)PTDB[b].DBDSN, SQL_NTS, (SQLCHAR*)PTDB[b].DBLogin, SQL_NTS, (SQLCHAR*)PTDB[b].DBPassword, SQL_NTS);
else
continue;
if(retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
retcode=SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
else
continue;
retcode=SQLPrepare(hstmt, (SQLCHAR*)MyQuery, SQL_NTS);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR , SQL_CHAR, 64, 0, pName, 0, &id1);
else
continue;
The query MyQuery is long with 4 INNER JOIN in it.
I use a SQLPrepare and SQLBindParameter because i need to call the same query 10 times with only one parameter ( pName ) changing.
Then i call SQLExecute(hstmt); and SQLFetch(hstmt); 10 times, changing pName each time.
Again, this works perfectly on some configuration, and very slowly on others. I've read things about the Trace, that should be turned OFF, but i think the SQLSetConnectAttr(hdbc,SQL_ATTR_TRACE,(SQLPOINTER)SQL_OPT_TRACE_OFF,NULL); is enough, right?
Anyway, if you have any idea that could help, it will be very welcomed.
Regards

