Search This Blog

Friday, July 26, 2013

SQL.Fetch: object isn't open on a select

Usually, you come across this error when there are erroneous rows while loading data through Component Interface (CI).

You might be using any of the sql class functions to loop through the data and then inserting each row.  When an error occurs the CI closes the SQL object which is open. Thus subsequent rows will not get processed.

This is a problem as the subsequent rows which are valid are not getting inserted.
Now that we identified the cause for the issue, lets try to fix this issue.

Below is one such approach which helps in resolving the issue.

Resolution:
1. Create a standalone rowset and fill it with all the rows which needs to be inserted.

2. Now loop through the rowset and load the data through CI.

3. For error row, CI fails while saving. At this point , call the Cancel function as the current transaction is invalid.

4. After Successful cancellation of erroneous row , CI will move on to next row in the loop.

This way , we can avoid/skip error rows and proceed with insertion of other valid rows.
Hope this post is useful..

No comments: