Dav*_*vid 5 c# sql datareader sqlclient aspdotnetstorefront
我在代码中有一个非常奇怪的问题,我不希望它会失败。这是一个基于 AspDotNetStoreFront 的网站,有一些流量但不是那么大。尝试从读取器读取数据库字段时,站点间歇性崩溃。这发生在网站的不同地方。此类代码的示例在下面与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;
}
Run Code Online (Sandbox Code Playgroud)
这是 SqlClient 的标准用法,我看不出它有什么问题。错误的堆栈跟踪是这样的:
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 propertySettings) at System.ConfigurationItem.Base (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)
当站点崩溃时,它需要重新启动 IIS 以使其重新启动。它在带有 .NET 3.5 和 SQL 2008 的 Windows Server 2008 上运行,并且都是最新的。机器是 64 位的,SQL Server 启用了 32 位模式以及使用“经典管道模式”的应用程序池。连接字符串是
<add name="PrimaryConnectionString" connectionString="data source=XXXX;database=XXXX;Integrated Security=True;Application Name=XXXX;MultipleActiveResultSets=true" />
Run Code Online (Sandbox Code Playgroud)
任何帮助非常非常感谢!!