We help IT Professionals succeed at work.

SSIS error at System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex)

Hi there,
Im using SSIS 2005 which using a script tasks creates a connection to our server and db and calls a variable to execute a SP. but I keep getting the following error at System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex)
0 rows returned

but I know if I run this query on its own straight from the db it will return rows.
I even added a data flow tasks to call the sp and export all rows to a test table, which it did and then moved to the script tasks but fails again.

now when I run the SP for some previous dates it runs fine.
I just don't know what it could be.
any help please?
thank you.
Watch Question

Vikas GargAssociate Principal Engineer
Top Expert 2014

What is your requirement ?
Why do you need to use a Script Task ?

May be
you are trying to read or loop through the rows from datatable. This error states that the datasource(DataTable) is not having any rows. To avoid this exception use this before you read or loop through datatable:
Hide   Copy Code

if(dt.Rows.Count  > 0 ){
     //Do your stuff here.


The script task does do a loop and checks what so is being called and runs the sp however I know that there is data there so I can't understand this error.
I saw had actually tried this suggestion earlier, perhaps I had placed if statement at the wrong area, It throw an error again.


also, using script task, (ive inherited this package) as the formatting seems to be setup inside of the script, and the output is put into xml format using a library.
when I added the if(dt.Rows.Count  > 0 ){

around my main script section which calls the SP
and then I closed your suggestion with
} end if

there is an underline error on the if statement then - am I missing something?


So the thing is if I run this script task for say the first 3 weeks of the last month, the package runs successfully, but when It runs for the whole month it causes this error.
I don't understand how it can see there is 0 rows returned when I know the frist 3 weeks when ranhave worked previously, could it be anything else other than this error its given me, could there be an index issue?
So because I knew there was information in the data set I was calling, I decided to go day by day to see was there one particular day that caused the error.
And so it looks like there was one row in the file for one day that had an issue with it.
and once I removed this row the script ran correctly.


There had always been information in the dataset I was trying to access, so by checking to do a loop to ignore if there was no rows then skip wouldn't work as suggested. I had to find the row that caused the problem and remove it.