English 中文(简体)
ASP.NET-MVC(IIS6)高流量错误:指定的强制转换无效。
原标题:
  • 时间:2008-11-25 20:22:02
  •  标签:

我刚在我的谦虚的专用服务器(Win2003)上推出了我的小型web应用程序,使用ASP.NET MVC、LINQ2SQL、SQL Express 2005和IIS6(使用通配符映射设置)。

The website runs smoothly 90% of the times. However, on relatively high traffic, LINQ2SQL throws the error: Specified cast is not valid

此错误仅在高流量时出现。我完全不知道为什么会发生这种情况,缓存并未完全消除这个问题。

Anyone seen this problem before? are there any secret SQL Server tweaking I should ve done? Or at least, any ideas on how to diagnose this issue? because i m out!

奈米 (Naimi)

堆栈跟踪(来自事件日志):

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:WebModelsDudlersDataContext.cs:line 562
   at Dudlers.Web.Controllers.BaseController.View(String viewName, String masterName, Object viewData) in C:WebControllersBaseController.cs:line 39
   at System.Web.Mvc.Controller.View(String viewName)
   at Dudlers.Web.Controllers.CatController.Index() in C:WebControllersCatController.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 includeAddress, 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 pageIndex, Int32 pageSize, Int32& recordCount)
   at CompositionAopProxy_4bd29c6074f54d10a2c09bd4ab27ca66.GetRolesForOrganisation(GetRolesForOrganisationCriteria criteria, Int32 pageIndex, Int32 pageSize, Int32& recordCount)
   at RF.Ias.Services.Role.ServiceImplementation.RoleService.GetRolesForOrganisation(GetRolesForOrganisationRequest request)

我们以前会得到这样的异常,如果我们首先得到这样的异常“System.InvalidOperationException:已经有一个与此命令关联的打开的DataReader必须首先关闭。”或“当从服务器接收结果时发生传输级错误。 (提供程序:TCP提供程序,错误:0-现有连接已被远程主机强制关闭。)”。

第一个异常是发生在不同的DataContext实例上,然后是在其后的所有实例中。

经过一些研究并在这个线程中询问后,我发现问题出在我没有处理DataContexts。在我开始处理后,问题就消失了。

问题回答

听起来可能是一种竞争条件,或者可能是一种仅与高流量相关的罕见 bug,因为这时大多数请求发生。





相关问题
热门标签