I have a very strange issue, I'm using System.Data.SqlClient.
to get data from a SQL Server though a stored procedure.
When I test the Application at the Development and Stagging machines it works fine but when I deploy the application on the Production Server I randomly getting an SqlDataReader IndexOutOfRangeException with different column names!.
The error appears in 2 requests in each 1000 request (approximative).
The SQL Server is Clustered
Source Code:
public static List<CountryInfo> GetAllCountries(){
List<CountryInfo> Items = new List<CountryInfo>();
try{
using (rdr = SqlHelper.ExecuteReader(Globals.ConnectionString, "unv_spGetAllCountries"))
{
while (rdr.Read())
{
CountryInfo item = new CountryInfo();
item.CountryId = Convert.ToInt32(rdr["CountryId"]);
item.CountryName = rdr["CountryName"].ToString();
item.FirstLevel = rdr["FirstLevel"].ToString();
item.SecondLevel = rdr["SecondLevel"].ToString();
Items.Add(item);
}
}
}
catch (Exception ex)
{
throw ex;
}
Items.TrimExcess();
return Items;
}
Stored Procedure:
select * from unv_tblCountries order by CountryName;
Already Tested
- Check Stored Procedure column names.
- Check Reader Column names.
- Check connection String.
Anyone faced like this issue and solve it?
select * ...is not going to help you, ifunv_tblCountrieschanges (or is different in different instances) you'll get errors at a distance rather than within the query itself -- this makes debugging harder. Thusselect *in production code is generally regarded as poor form (ad-hoc queries are different).