MATLAB: Am I getting the error “Beyond SQL_ACTIVE_STATEMENTS limit” when querying from SQL database with Database Toolbox

databaseDatabase Toolboxsqlsql_active_statements

I am using the database toolbox to query from a SQL database with the "exec" and "fetch" functions. I sometimes can get the data back successfully but occasionally get empty data after fetch.
I print out the message from the cursor object after using the "exec" command and obtained the following error:
[Teradata][ODBC Teradata Driver] Beyond SQL_ACTIVE_STATEMENTS limit
Why am I getting this error?

Best Answer

"Beyond SQL_ACTIVE_STATEMENTS limit" means that your application has tried to create more "hStmt"s by ODBC driver than the database is allowed.
It probably means that you are creating a new "hStmt" each time you submit a new query, but you are not releasing these "hStmt"s after the queries complete.
Please make sure to close the cursor object after the the query is completed with the "close" function as shown in the example below:
>> sqlquery = 'SELECT * FROM inventoryTable ORDER BY productNumber';
>> curs = exec(conn,sqlquery,'CursorType','scrollable');
>> curs = fetch(curs,'AbsolutePosition',10);
>> data = curs.Data;
>> close(curs);