我用的DataSet读取数据,大概每天不定时会出现1-3次下面的错误,我找不出原因,怀疑是DataSet造成内存出错,请大家帮我分析一下
错误提示(同一个页面出错时刷新可能会是另一个相似的错误,而且必须重新启动服务器或重新上传dll才能恢复)
--------------------------------------------------------
Server Error in '/' Application.
--------------------------------------------------------------------------------Column 'AdsID' does not belong to table Table.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: Column 'AdsID' does not belong to table Table.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[ArgumentException: Column 'AdsID' does not belong to table Table.]
System.Data.DataRow.GetDataColumn(String columnName) +1899247
System.Data.DataRow.get_Item(String columnName) +10
CAENETCN.Forums.ForumGet.GetAdsToShowByPosNo(String Ads_Pos_No) +376
Controls.CaeNetAds.Page_Load(Object sender, EventArgs e) +31
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42 下面是我操作数据库的代码式样:
-------------------------------------------------------------------
获取数据代码
/// <summary>
/// 执行存储过程并返回数据集
/// </summary>
/// <param name="procName">存储过程名称</param>
/// <param name="coll">SqlParameter集合</param>
/// <param name="ds">DataSet </param>
public static DataSet ExecutePorcedureBackDataset(string procName,SqlParameter[] coll)
{
DataSet ds=new DataSet();
try
{
SqlDataAdapter da=new SqlDataAdapter();
openConnection();
for(int i=0;i<coll.Length;i++)
{
comm.Parameters .Add(coll[i]);
}
comm.CommandType=CommandType.StoredProcedure ;
comm.CommandText =procName;
da.SelectCommand =comm;
da.Fill(ds); }
catch(Exception e)
{
throw new Exception(e.Message+coll[0].ParameterName+coll[0].Value);
}
finally
{
comm.Parameters.Clear();
closeConnection();
}
return ds;
}操作数据代码:
--------------------------------------------
protected void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{ string procName="forums_GetIndexData";//含有多个返回表的存储过程
SqlParameter[] coll= {};
DataSet ds=DataAccess.ExecutePorcedureBackDataset(procName,coll));//获取数据
this.RpForumRegion.DataSource=new DataView(ds.Tables[0]);
this.RpForumRegion.DataBind(); this.RpForumHot.DataSource=new DataView(ds.Tables[1]);
this.RpForumHot.DataBind(); this.RpForumNew.DataSource=new DataView(ds.Tables[2]);
this.RpForumNew.DataBind();
ds.Dispose();
} }
请大家帮我分析一下,我这种使用方式有没有什么缺陷,造成内存紊乱之类的?还有一个表现,每次出现这个错误后,凡不涉及数据库访问的aspx页面不会出错,访问数据库的页面就回出错
错误提示(同一个页面出错时刷新可能会是另一个相似的错误,而且必须重新启动服务器或重新上传dll才能恢复)
--------------------------------------------------------
Server Error in '/' Application.
--------------------------------------------------------------------------------Column 'AdsID' does not belong to table Table.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: Column 'AdsID' does not belong to table Table.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[ArgumentException: Column 'AdsID' does not belong to table Table.]
System.Data.DataRow.GetDataColumn(String columnName) +1899247
System.Data.DataRow.get_Item(String columnName) +10
CAENETCN.Forums.ForumGet.GetAdsToShowByPosNo(String Ads_Pos_No) +376
Controls.CaeNetAds.Page_Load(Object sender, EventArgs e) +31
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42 下面是我操作数据库的代码式样:
-------------------------------------------------------------------
获取数据代码
/// <summary>
/// 执行存储过程并返回数据集
/// </summary>
/// <param name="procName">存储过程名称</param>
/// <param name="coll">SqlParameter集合</param>
/// <param name="ds">DataSet </param>
public static DataSet ExecutePorcedureBackDataset(string procName,SqlParameter[] coll)
{
DataSet ds=new DataSet();
try
{
SqlDataAdapter da=new SqlDataAdapter();
openConnection();
for(int i=0;i<coll.Length;i++)
{
comm.Parameters .Add(coll[i]);
}
comm.CommandType=CommandType.StoredProcedure ;
comm.CommandText =procName;
da.SelectCommand =comm;
da.Fill(ds); }
catch(Exception e)
{
throw new Exception(e.Message+coll[0].ParameterName+coll[0].Value);
}
finally
{
comm.Parameters.Clear();
closeConnection();
}
return ds;
}操作数据代码:
--------------------------------------------
protected void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{ string procName="forums_GetIndexData";//含有多个返回表的存储过程
SqlParameter[] coll= {};
DataSet ds=DataAccess.ExecutePorcedureBackDataset(procName,coll));//获取数据
this.RpForumRegion.DataSource=new DataView(ds.Tables[0]);
this.RpForumRegion.DataBind(); this.RpForumHot.DataSource=new DataView(ds.Tables[1]);
this.RpForumHot.DataBind(); this.RpForumNew.DataSource=new DataView(ds.Tables[2]);
this.RpForumNew.DataBind();
ds.Dispose();
} }
请大家帮我分析一下,我这种使用方式有没有什么缺陷,造成内存紊乱之类的?还有一个表现,每次出现这个错误后,凡不涉及数据库访问的aspx页面不会出错,访问数据库的页面就回出错
解决方案 »
- 估计这是一个白痴问题, 第一个做Web, 感觉很别扭, 关于DataGrid的问题
- .net自定义控件 嵌入资源css内图片路径问题
- gridview的dataSource问题?
- html 表格的计算
- DataGrid 中通过column归类的那个属性是什么???
- 学了不少,.NET关于XML的知识,对语法和一系列的知识都了解不少了,现在苦于普通的.NET项目或者哪些方面用XML比较好。
- 100分求解:word另存为xml文件后,怎样访问<w:t>节点
- 怎样在VS.net中设置一个页面的长度??
- 关于代码分离的问题
- 春节快到了,不知知位Asp.net发烧友有何感想,我来这里不久,得到很多的热心的朋友的帮助,在些谢谢你们,预祝你们新春愉快!
- 急救!!!!!!!!!!!!
- 如何不用Upload控件,制作弹出一个打开文件的窗口?
public static DataSet ExecutePorcedureBackDataset(string procName,SqlParameter[] coll)
方法是线程安全吗?
从你的代码看来应该不是线程安全的,当同一时间内有两个用户操作问题就产生.