Applies To:
  • CitectSCADA 5.50, 6.00
  • CitectHMI 5.50, 6.00

Summary:
I'm using the CSV_DB_Execute() function from the CSV_Include project to query a database. It works for a while, then fails every subsequent time. The recordset handle returned by CSV_DB_Execute() is -1, but CSV_DB_GetExecuteError() returns a blank string (no error). Or, the same (incorrect) error is returned every time.
 

Solution:
If you are executing a query that does not return a recordset (like adding or deleting a record), it is not necessary to close the query. For example:

CSV_DB_Execute("DELETE FROM Alarms WHERE [Date] < " + rOLEDate:5.8, msConnection, "");

If you are executing a query that returns a recordset it is necessary to close the recordset when you're done with it. For example:

hRS = CSV_DB_Execute("SELECT Tag,Name,[Desc] FROM Alarms ORDER BY [Date]", msConnection, "");
CSV_DB_MoveFirst(hRS);

WHILE NOT CSV_DB_EOF(hRS) DO
    sAlmTag = CSV_DB_GetFieldText(hRS, "Tag");
    sAlmName = CSV_DB_GetFieldText(hRS, "Name");
    sAlmDesc = CSV_DB_GetFieldText(hRS, "Desc");
    .
    .
    .
    CSV_DB_MoveNext(hRS);
END

CSV_DB_Close(hRS);

If you don't close the recordset with CSV_DB_Close(), the recordset handle number will keep increasing until there are 30 open queries. After that, all queries will fail and return -1 regardless of whether they would return a recordset.
 

Keywords:
XP_Style Templates, memory leak, handle leak, ADO  

Attachments