救命~! 关于linq出错问题

djzblue 2008-12-24 11:20:13
使用linq真的搞晕死,系统在本机调试没出现过这些问题:“序列不包含任何元素”“索引超出了数组界限”,或者提示:“已有打开的与此命令相关联的 DataReader,必须首先将它关闭。”
重新启动iis好了一会,又反复出现这些问题,或者用户总登录不进去,有没有哪位大哥遇到过这种问题啊


“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------

索引超出了数组界限。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.IndexOutOfRangeException: 索引超出了数组界限。

源错误:

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。

堆栈跟踪:


[IndexOutOfRangeException: 索引超出了数组界限。]
System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +2668402
System.Data.Linq.DataContext.GetTable(MetaTable metaTable) +214
System.Data.Linq.DataContext.GetTable() +163
SDPTThesis.DAL.Linq.ThesisDbDataContext.get_AdminUserInfo() in M:\毕业设计选题信息系统\ThesisManagement\ThesisManagement\DAL\ThesisDb.designer.cs:124
SDPTThesis.BLL.AdminUser.ValidateUser(String uname, String pwd) in M:\毕业设计选题信息系统\ThesisManagement\ThesisManagement\BLL\AdminUser.cs:24
SDPTThesis.Web.Root.LoginPage.ValidateUser(IUser user) in M:\毕业设计选题信息系统\ThesisManagement\ThesisManagement\ThesisManagement\Login.aspx.cs:85
SDPTThesis.Web.Root.LoginPage.submitbtn_Click(Object sender, ImageClickEventArgs e) in M:\毕业设计选题信息系统\ThesisManagement\ThesisManagement\ThesisManagement\Login.aspx.cs:73
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +86
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +115
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746




“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------

已有打开的与此命令相关联的 DataReader,必须首先将它关闭。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.InvalidOperationException: 已有打开的与此命令相关联的 DataReader,必须首先将它关闭。

源错误:

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。

堆栈跟踪:


[InvalidOperationException: 已有打开的与此命令相关联的 DataReader,必须首先将它关闭。]
System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand command) +795219
System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command) +21
System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async) +99
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +73
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
System.Data.Common.DbCommand.ExecuteReader() +9
System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult) +281
System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries) +129
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +878
System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute(Expression expression) +92
System.Linq.Queryable.Count(IQueryable`1 source) +244
SDPTThesis.BLL.BLLBase.ToSingle(IQueryable`1 vars) in M:\毕业设计选题信息系统\ThesisManagement\ThesisManagement\BLL\BLLBase.cs:42
SDPTThesis.BLL.Subject.GetFormalSubjectByID(Int32 id) in M:\毕业设计选题信息系统\ThesisManagement\ThesisManagement\BLL\Subject.cs:111

[TargetInvocationException: 调用的目标发生了异常。]
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +371
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +480
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1960
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
System.Web.UI.WebControls.DetailsView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.DetailsView.EnsureDataBound() +181
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +50
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Control.PreRenderRecursiveInternal() +170
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041
...全文
330 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dantin 2009-02-21
  • 打赏
  • 举报
回复
不懂,帮忙顶起来
ztenv 2009-02-05
  • 打赏
  • 举报
回复
使用linq真的搞晕死,系统在本机调试没出现过这些问题:“序列不包含任何元素”“索引超出了数组界限”,或者提示:“已有打开的与此命令相关联的 DataReader,必须首先将它关闭。”

?????异常没处理好引起的一系列问题,访问了没有元素的IEnumerable<T>类型等;
djzblue 2008-12-27
  • 打赏
  • 举报
回复
不是这个问题,用linq的话,就不会再自己写什么datareader了,我先前用的是单件模式,在一个公共类统一引用,结果在多人使用的时候就出乱子了,后来修改了,用工厂模式逐一生成实例,就没有再出现这些乱七八糟的问题了,不过在update和delete的时候比较麻烦,我采用了一种折中办法就是利用out参数, 哎,,那些天真的给linq弄得抓狂。
vwxyzh 2008-12-27
  • 打赏
  • 举报
回复
万恶的滥用singleton
qinhl99 2008-12-24
  • 打赏
  • 举报
回复
代码贴出来看看?
qinhl99 2008-12-24
  • 打赏
  • 举报
回复
up
ustbwuyi 2008-12-24
  • 打赏
  • 举报
回复
代码有问题,最好贴出来看看,至少像"已有打开的与此命令相关联的 DataReader,必须首先将它关闭。"之类的问题,你应该可以跟踪得到的,自己设置断点然后做一个数据操作,一步步执行下去,看看是什么地方没有关闭DataReader
xiaobaook 2008-12-24
  • 打赏
  • 举报
回复
这样是没用的,你可以跟踪啊
jiang_jiajia10 2008-12-24
  • 打赏
  • 举报
回复
帮顶

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧