我刚刚在我简陋的专用服务器(Win2003)上启动了我的
tiny webapp …运行ASP.NET MVC,LINQ2sql,sql Express 2005和IIS6(使用
wildcard mapping设置)
该网站90%的时间运行顺利.但是,在相对较高的流量上,LINQ2sql会抛出错误:
指定演员表无效
此错误仅在高流量时抛出.我没有想法,为什么会发生这种情况.缓存并没有完全消除这个问题.
以前有人见过这个问题吗?是否有任何秘密的sql Server调整我应该做的?
或者至少,关于如何诊断这个问题的任何想法?因为我出去了!
纳伊米
Stacktrace(来自事件日志):
at System.Data.sqlClient.sqlBuffer.get_sqlGuid() at System.Data.sqlClient.sqlDataReader.GetGuid(Int32 i) at Read_Friend(ObjectMaterializer`1 ) at System.Data.Linq.sqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext() at Dudlers.Web.Models.DudlersDataContext.GetFriendRequests(Guid userId) in C:\Web\Models\DudlersDataContext.cs:line 562 at Dudlers.Web.Controllers.BaseController.View(String viewName,String masterName,Object viewData) in C:\Web\Controllers\BaseController.cs:line 39 at System.Web.Mvc.Controller.View(String viewName) at Dudlers.Web.Controllers.CatController.Index() in C:\Web\Controllers\CatController.cs:line 25 at lambda_method(ExecutionScope,ControllerBase,Object[] ) at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller,Object[] parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(MethodInfo methodInfo,IDictionary`2 parameters) at System.Web.Mvc.ControllerActionInvoker.c__DisplayClassb.b__8() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter,ActionExecutingContext preContext,Func`1 continuation) at System.Web.Mvc.ControllerActionInvoker.c__DisplayClassb.c__DisplayClassd.b__a() at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(MethodInfo methodInfo,IDictionary`2 parameters,IList`1 filters) at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext,String actionName) at System.Web.Mvc.Controller.ExecuteCore() at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) at System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)
解决方法
我们遇到类似LINQ的问题,我们得到“无法将类型’System.Int32’的对象强制转换为’System.String’”和“指定的强制转换无效”.
堆栈跟踪的示例
System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'. at System.Data.sqlClient.sqlBuffer.get_String() at System.Data.sqlClient.sqlDataReader.GetString(Int32 i) at Read_Person(ObjectMaterializer`1 ) at System.Data.Linq.sqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at RF.Ias.Services.Person.BusinessLogic.PersonTransactionScripts.GetPersons(IEnumerable`1 personIds,Boolean includeAddress,Boolean includeContact) at CompositionAopProxy_5b0727341ad64f29b816c1b73d11dd44.GetPersons(IEnumerable`1 personIds,Boolean includeContact) at RF.Ias.Services.Person.ServiceImplementation.PersonService.GetPersons(GetPersonRequest request) System.InvalidCastException: Specified cast is not valid. at System.Data.sqlClient.sqlBuffer.get_Int32() at System.Data.sqlClient.sqlDataReader.GetInt32(Int32 i) at Read_GetRolesForOrganisationResult(ObjectMaterializer`1 ) at System.Data.Linq.sqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at RF.Ias.Services.Role.DataAccess.RoleDataAccess.GetRolesForOrganisation(GetRolesForOrganisationCriteria criteria,Int32 pageIndex,Int32 pageSize,Int32& recordCount) at RF.Ias.Services.Role.BusinessLogic.RoleTransactionScripts.GetRolesForOrganisation(GetRolesForOrganisationCriteria criteria,Int32& recordCount) at CompositionAopProxy_4bd29c6074f54d10a2c09bd4ab27ca66.GetRolesForOrganisation(GetRolesForOrganisationCriteria criteria,Int32& recordCount) at RF.Ias.Services.Role.ServiceImplementation.RoleService.GetRolesForOrganisation(GetRolesForOrganisationRequest request)
如果我们第一次得到这样的异常,我们过去会得到这些异常“System.InvalidOperationException:已经有一个与此命令关联的开放DataReader,必须先关闭它.”或“从服务器接收结果时发生传输级错误.(提供程序:TCP提供程序,错误:0 – 远程主机强行关闭现有连接.)”.
第一个例外发生在DataCOntext的不同实例上,然后是所有那些随后关注的实例.
经过一些研究并在thread中询问后,我发现原因是我没有处理DataContexts.在我开始这样做之后,它消失了.