performance problem

Hi all,
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
[2643 byte] By [fouf] at [2007-11-19 20:44:48]
# 1 Re: performance problem
I didn't get well: you are calling ten times the entire SP or just a part of it?- it is clear why it is slow...Try to replace the repeatable part with a function call inside the sp. If the SP is using cursors- it is slowly too.
Or, better, post the SP here to have a look
DanielaTm at 2007-11-9 13:43:27 >
# 2 Re: performance problem
I didn't get well: you are calling ten times the entire SP or just a part of it?- it is clear why it is slow...Try to replace the repeatable part with a function call inside the sp. If the SP is using cursors- it is slowly too.
Or, better, post the SP here to have a look

What is what you call SP?

OK, what i have is a big query that i have to do 10 times, with one parameter changing each time ( the name ). We can say my query is something like that:

"SELECT a,b,c,d,e FROM ((TableA INNER JOIN TableB ON TableA.ID=TableB.ID) INNER JOIN TableC ON TableC.Id=TableB.Id where Name=x AND (additionnal fixed conditions)"

That's why i used the SQLPrepare function. So after the code in the previous post i do :

for (i=0;i<10;i++)
{
pName=name[i];
SQLExecute(hstmt);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
retcode = SQLFetch(hstmt);
// treat results
}
SQLFreeStmt(hstmt, SQL_CLOSE);
}

Again this code seems to work fine most of the time, but i have reports from some users that it is extremely slow on their PC.
Something wrong with this code?
Thanks for the help.
fouf at 2007-11-9 13:44:28 >