ASP NET应用程序中的事件查看器中存储的警告已停止IIS
不重复,因为我检查了我的代码,如果ns填充不成功,请参阅:
if (!string.IsNullOrEmpty(str))
{
strArr = str.Split(splitchar);
}
请重新打开此问题,谢谢。
我在ASP NET 4.0和C-sharp工作。
我对此应用程序有疑问,因为在事件查看器(应用程序事件记录)中的服务器上经常存储此警告:
at GridViewPage.RetrieveProducts() in d:\Inetpub\wwwroot\GV\GridViewPage.aspx.cs:line 69
at GridViewPage.BindData() in d:\Inetpub\wwwroot\GV\GridViewPage.aspx.cs:line 225
at GridViewPage.Page_Load(Object sender, EventArgs e) in d:\Inetpub\wwwroot\GV\GridViewPage.aspx.cs:line 30
在第69行的GridViewPage.cs后面的代码中我有:
str = ns.ToString();
在第225行:
gvProducts.DataSource = RetrieveProducts();
第30行:
BindData();
问题在于:
private DataSet RetrieveProducts()
在我设置的行
str = ns.ToString();
在string ns
我存储在List
中的数据库中提取的值,因为一个用户可以获得更多评分。
有人知道如何解决这个问题?
你能帮助我吗?
提前感谢您,我的代码如下。
List<string> colorList = new List<string>();
protected void Users()
{
using (OdbcConnection cn =
new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString))
{
string sql_aut = @" SELECT * FROM doTableUSers WHERE number = ?; ";
using (OdbcCommand command =
new OdbcCommand(sql_aut, cn))
{
try
{
if (Request.Cookies["number"] != null)
{
command.Parameters.AddWithValue("param1", Server.UrlDecode(Request.Cookies["number"].Value));
command.Connection.Open();
using (OdbcDataReader reader = command.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
idColor = reader["idColor"].ToString();
colorList.Add(idColor.ToString());
}
ns = "";
foreach (string s in colorList)
{
if (ns.Length != 0)
{
ns += ", ";
}
ns += s;
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Msg", "alert('User not stored.');", true);
}
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Msg", "alert('User not stored.');", true);
}
}
catch (Exception ex)
{
throw new ApplicationException("operation failed!", ex);
}
finally
{
command.Connection.Close();
}
}
}
}
private DataSet RetrieveProducts()
{
str = null;
strArr = null;
count = 0;
str = ns.ToString();
char[] splitchar = { ',' };
if (!string.IsNullOrEmpty(str))
{
strArr = str.Split(splitchar);
}
for (count = 0; count <= strArr.Length - 1; count++)
{
sql = @" SELECT * FROM doTable WHERE idColor IN (?); ";
}
DataSet dsProducts = new DataSet();
using (OdbcConnection cn =
new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString))
{
cn.Open();
using (OdbcCommand cmd = new OdbcCommand(sql, cn))
{
for (count = 0; count <= strArr.Length - 1; count++)
{
cmd.Parameters.AddWithValue("param1", Server.UrlDecode(strArr[count].Trim()));
}
OdbcDataAdapter adapter = new OdbcDataAdapter(cmd);
adapter.Fill(dsProducts);
}
}
return dsProducts;
}
编辑#1
完成事件例外:
Event Type: Warning
Event Source: ASP.NET 4.0.30319.0
Event Category: Web Event
Event ID: 1309
Date: 24/07/2015
Time: 10.18.17
User: N/A
Computer: XXXXXXX
Description:
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 24/07/2015 10.18.17
Event time (UTC): 24/07/2015 8.18.17
Event ID: 71776aa8c7d747d5b00a5a84b2f7f701
Event sequence: 6
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/1/Root/GV/GridView-3-130821994960000000
Trust level: Full
Application Virtual Path: /GV/GridView
Application Path: D:\Inetpub\wwwroot\GV\GridView\
Machine name: XXXXXXX
Process information:
Process ID: 1932
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE
Exception information:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
at GridView.asp.RetrieveProducts() in d:\Inetpub\wwwroot\GV\GridView\GridView.aspx.cs:line 69
at GridView.asp.BindData() in d:\Inetpub\wwwroot\GV\GridView\GridView.aspx.cs:line 225
at GridView.asp.Page_Load(Object sender, EventArgs e) in d:\Inetpub\wwwroot\GV\GridView\GridView.aspx.cs:line 30
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Request information:
Request URL: http://xxx/GV/GridView/GridView.aspx
Request path: /GV/GridView/GridView.aspx
User host address: 11.11.1.000
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE
Thread information:
Thread ID: 8
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Stack trace: at GridView.asp.RetrieveProducts() in d:\Inetpub\wwwroot\GV\GridView\GridView.aspx.cs:line 69
at GridView.asp.BindData() in d:\Inetpub\wwwroot\GV\GridView\GridView.aspx.cs:line 225
at GridView.asp.Page_Load(Object sender, EventArgs e) in d:\Inetpub\wwwroot\GV\GridView\GridView.aspx.cs:line 30
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Custom event details:
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.