I have a very weird problem in code that I would not expect to ever fail. It is a website with some traffic but not that huge based on AspDotNetStoreFront. Site intermittently crashes when trying to read a database field from a reader. This happen on various places on the website. An example of such code is below on the line with object pValue = rs["PropertyValueString"];
private Dictionary<string, object> GetPropertValuePairs(string userName)
{
string query = string.Format("select PropertyName, PropertyValueString from dbo.profile with(nolock) where CustomerGUID = {0} and StoreID = {1}", DB.SQuote(userName),AppLogic.StoreID());
Dictionary<string, object> propertyValues = new Dictionary<string, object>();
using (SqlConnection conn = new SqlConnection(DB.GetDBConn()))
{
conn.Open();
using (IDataReader rs = DB.GetRS(query, conn))
{
while (rs.Read())
{
string pName = DB.RSField(rs, "PropertyName");
object pValue = rs["PropertyValueString"];
if (propertyValues.ContainsKey(pName) == false)
{
propertyValues.Add(pName, pValue);
}
}
rs.Close();
rs.Dispose();
}
conn.Close();
conn.Dispose();
}
return propertyValues;
}
It is standard use of SqlClient and I can't see anything wrong with it. Stack trace of the error is this:
System.IndexOutOfRangeException at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName) at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name) at System.Data.SqlClient.SqlDataReader.get_Item(String name) at AspDotNetStorefront.ASPDNSFProfileProvider.GetPropertValuePairs(String userName) at AspDotNetStorefront.ASPDNSFProfileProvider.GetPropertyValues(SettingsContext context, SettingsPropertyCollection settingsProperties) at System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider) at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName) at System.Configuration.SettingsBase.get_Item(String propertyName) at System.Web.Profile.ProfileBase.GetInternal(String propertyName) at System.Web.Profile.ProfileBase.get_Item(String propertyName) at System.Web.Profile.ProfileBase.GetPropertyValue(String propertyName) at AspDotNetStorefront.SkinBase.OnPreInit(EventArgs e) at System.Web.UI.Page.PerformPreInit() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
When the site crashes it requires to restart IIS to bring it back on. It is on Windows Server 2008 with .NET 3.5 and SQL 2008, all up to date. The machine is 64 bit and SQL Server has 32-bit mode enabled as well as the application pool that uses "classic pipeline mode". THe connection string is
<add name="PrimaryConnectionString" connectionString="data source=XXXX;database=XXXX;Integrated Security=True;Application Name=XXXX;MultipleActiveResultSets=true" />
Any help very very appreciated!!