从IDataReader读取字段时Intermittent System.IndexOutOfRangeException

我在代码中有一个非常奇怪的问题,我不希望它会失败。 它是一个网站,有一些流量但不是很大,基于AspDotNetStoreFront。 尝试从阅读器读取数据库字段时,站点间歇性崩溃。 这发生在网站上的各个地方。 这个代码的一个例子是在对象pValue = rs [“PropertyValueString”]的行下面;

private Dictionary 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 propertyValues = new Dictionary(); 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; } 

它是SqlClient的标准使用,我看不出它有什么问题。 堆栈跟踪错误是这样的:

位于AspDotNetStorefront.ASPDNSFProfileProvider的System.Data.SqlClient.SqlDataReader.get_Item(String name)的System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)处的System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)的System.IndexOutOfRangeException。 System.Configuration.SettingsBase.get_Item上System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)的System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider提供程序)的AspDotNetStorefront.ASPDNSFProfileProvider.GetPropertyValues(SettingsContext context,SettingsPropertyCollection settingsProperties)中的GetPropertValuePairs(String userName) (String propertyName)位于System.Web.Profile.ProfileBase.GetInternal(String propertyName)的System.Web.Profile.ProfileBase.get_Item(String propertyName),位于AspDotNetStorefront.SkinBase的System.Web.Profile.ProfileBase.GetPropertyValue(String propertyName) System.Web.UI上System.Web.UI.Page.PerformPreInit()的.OnPreInit(EventArgs e) .Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)

当站点崩溃时,需要重新启动IIS才能重新启动它。 它位于Windows Server 2008上,带有.NET 3.5和SQL 2008,全部都是最新的。 该机器为64位,SQL Server启用了32位模式,以及使用“经典流水线模式”的应用程序池。 连接字符串是

   

任何帮助非常非常赞赏!!

我猜你是在线程之间共享一个datareader的实例。 确保DB.GetRS在所有情况下都返回一个新的datareader实例,而不是返回共享实例。

所以经过多次搜索,我遇到了我的确切问题。 我在工作中向我的朋友展示了他们的post,他们承认这是我们的情况。 然后我意识到这里没有足够的信息来解决我的问题。 所以我拿了一些在这里说的内容并搜索了一些。

我发现了这个post: 索引超出范围exception 。 这不仅仅是NHibernate的好post。

我添加了Pooling=false; 到我的web.config连接字符串,然后启动一系列测试以加载服务器。 我们测试了当前最大访问者负载的200%以尝试使用此错误终止服务器。 以前,我们会在100%以下崩溃。 没有一个错误。 我将测试另一个选项Enlist = false。 我以前没有听说过这个。

还有一点,我们已经运行AspDotNetStoreFront多年了。 所以我回去找出为什么我们最新的网站发布了所有这些错误,旧网站没有错误。 原来我们添加了pooling=false; 以前取得了巨大成功。

Interesting Posts