I have a very strange code problem that I would not have expected to ever fail. This is a website with some traffic, but not that huge, based on AspDotNetStoreFront. The site is interrupted when trying to read the database field from the reader. This happens in different places on the website. An example of such code is shown below in the line with the 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;
}
This is the standard use of SqlClient, and I see nothing wrong with that. The error stack trace is as follows:
System.IndexOutOfRangeException System.Data.ProviderBase.FieldNameLookup.GetOrdinal(_ fieldName) System.Data.SqlClient.SqlDataReader.GetOrdinal( ) System.Data.SqlClient.SqlDataReader.get_Item ( ) AspDotNetStorefront.ASPDNSFProfileProvider.GetPropertValuePairs(String userName) AspDotNetStorefront.ASPDNSFProfileProvider.GetPropertyValues ( SettingsContext, SettingsPropertyCollection settingsProperties) System.Configuration.SettingsBase.GetPropertiesFromProvider( SettingsProvider) System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName) System.Configuration.SettingsBase.get_Item (String propertyName) System.Web.Profile.ProfileBase.GetInternal(String propertyName) System.Web.Profile.ProfileBase.get_Item (String propertyName) System.Web.Profile.ProfileBase.GetPropertyValue(String propertyName) AspDotNetStorefront.SkinBase.OnPreInit(EventArgs e) System.Web.UI.Page.PerformPreInit() System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
IIS, . Windows Server 2008 .NET 3.5 SQL 2008, . 64 , SQL Server 32- , , " ".
<add name="PrimaryConnectionString" connectionString="data source=XXXX;database=XXXX;Integrated Security=True;Application Name=XXXX;MultipleActiveResultSets=true" />
!