HttpException (0×80004005): The IListSource does not contain any data sources – Anatomy
Posted on 05. May, 2009 by khader in Other
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