HttpException (0x80004005): The IListSource does not contain any data sources – Anatomy

2

This is one of the common errors I saw when I was testing our new asp.net application recently. I asked my team, the answer was simple patch. But I wasn’t happy. I didn’t find any good explanation from anybody on internet either. I did little research. Here’s my explanation.

First, couple of points to note:

  • This occurs when you are binding a NULL dataset to Data control such a GridView, FormView etc. We could avoid this by simple checking whether dataset is null. I don’t think it is a robust solution.
  • NULL datasource is returned mostly when some thing is WRONG/ERROR with your query or stored procedure.

Then, what happened to the SQLException handling code? I had the same question. But look at the following piece of code.

//.... 
DataSet dsDataSet = null; 
dbConn = new SqlConnection(_connStr); 
try 
{ 
      dbAdapter = new SqlDataAdapter(SqlString, dbConn); 
      dsDataSet = new DataSet();
      dbAdapter.Fill(dsDataSet); 
} 
catch (SqlException sqlException) 
{ 
      System.Diagnostics.Trace.WriteLine(sqlException.ToString()); 
} 
catch (Exception genException) 
{ 
      System.Diagnostics.Trace.WriteLine(genException.ToString()); 
} 
return dsDataSet; 
//.... 

It looks great. It has all that you usually think of. But this is the same code which was bugging me. It simply returns NULL dataset even when I am missing my Stored Procedure in Database. What happened SQLException?

Here the culprit is the function “dbAdapter.Fill(dsDataSet);”. If you look at the FILL function documentation you will see few other signatures. The default signature simply tries to add or refresh the rows in dataset. If you look at the details carefully it says, it doesn’t fill the Dataset if there are any erros from the SELECT/SQL. Same thing happened in my case. I was missing stored procedures in my new database. It kept simply throwing the IListSource exception instead of SQLException.

You can carefully use this function with some extra checks to avoid this error. It is very important to handle this otherwise you may end up spending lot of time to find out that you are missing some database object.

-Khader Vali

2 COMMENTS

  1. 1. last_name problem:I agree, DbUnit suhold report this kind of mistakes and I’ll look into why it does not. DbUnit 2.0 tries to be default value friendly by omitting null from the insert statement. Having an empty string as default value for last_name would explain why you don’t get the not nullable error with version 2.0. I suhold have made this configurable and disabled it by default.2. middle_name problem:Looks like you are using a data type not natively supported by DbUnit for this column. Version 2.0 features configurable data type factory and provides implementations for a few vendors.You suhold have got a warning about the unrecognized data type. Perhaps the warning was lost in the middle of a very verbose output! Maybe it suhold be an error instead of a warning!

LEAVE A REPLY

Please enter your comment!
Please enter your name here