Friday, March 16, 2012

"System.InvalidOperationException: Invalid attempt to MetaData when reader is closed"

I am getting this exception sporadically in a certain block of code (it usually works):

"System.InvalidOperationException: Invalid attempt to MetaData when reader is closed"

The code is below: cmd.CommandText ="[dbo].CountryGetList"; cmd.CommandType = CommandType.StoredProcedure; IDataReader rdr = cmd.ExecuteReader(); List countries =new List(); ...while (rdr.Read()) {//do stuff                  

CountryID = (

Guid)rdr["CountryID"];

//blows up on the next line

cty.Name = (string)rdr["Name"];

}

} rdr.Close();

Any ideas!?

I guess thecmd.Connection has been closed before you finish reading data from IDataReader rdr

No comments:

Post a Comment