I'm getting "invalid descriptor index" when fetching results after `SQLExecute`. What should I check?

Responsive Ad Header

Question

Grade: Education Subject: Support
I'm getting "invalid descriptor index" when fetching results after `SQLExecute`. What should I check?
Asked by:
101 Viewed 101 Answers

Answer (101)

Best Answer
(1031)
If the error occurs after `SQLExecute` (or `SQLExecDirect`) during result fetching (e.g., when calling `SQLBindCol` or `SQLGetData`), it typically means: 1. **Incorrect Column Index:** You are trying to bind or retrieve data for a column index that does not exist in the result set. Column indexing is also typically 1-based. 2. **Mismatched Column Count:** The number of `SQLBindCol` calls exceeds the actual number of columns returned by the query. Use `SQLNumResultCols` to determine the exact number of columns available in the result set before binding. 3. **Invalid Statement State:** Less common, but if the statement handle is in an erroneous state from a previous operation that wasn't properly handled, subsequent operations like fetching can fail. 4. **`SQLFetch` or `SQLFetchScroll` Issues:** Ensure `SQLFetch` is returning `SQL_SUCCESS` or `SQL_SUCCESS_WITH_INFO` before attempting to access column data. An error from `SQLFetch` itself could precede the descriptor index error if the result set is malformed or empty.