本文介绍了ASP.NET-MVC (IIS6) 高流量错误:指定的转换无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在我不起眼的专用服务器 (Win2003) 上启动了我的 tiny webapp...运行 ASP.NET MVC、LINQ2SQL、SQL Express 2005 和 IIS6(使用 通配符映射)

该网站在 90% 的情况下都能顺利运行.但是,在相对流量上,LINQ2SQL 会抛出错误:指定的演员表无效

此错误仅在高流量时抛出.我不知道这是如何或究竟为什么会发生这种情况.缓存并没有完全消除这个问题.

有人见过这个问题吗?是否有任何我应该做的秘密 SQL Server 调整?或者至少,对如何诊断这个问题有什么想法吗?因为我出去了!

奈美

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

在 System.Data.SqlClient.SqlBuffer.get_SqlGuid()在 System.Data.SqlClient.SqlDataReader.GetGuid(Int32 i)在 Read_Friend(ObjectMaterializer`1 )在 System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext()在 Dudlers.Web.Models.DudlersDataContext.GetFriendRequests(Guid userId) 在 C:WebModelsDudlersDataContext.cs:line 562在 Dudlers.Web.Controllers.BaseController.View(String viewName, String masterName, Object viewData) 在 C:WebControllersBaseController.cs:line 39在 System.Web.Mvc.Controller.View(String viewName)在 Dudlers.Web.Controllers.CatController.Index() 在 C:WebControllersCatController.cs:line 25在 lambda_method(ExecutionScope , ControllerBase , Object[] )在 System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase 控制器,Object[] 参数)在 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(MethodInfo methodInfo, IDictionary`2 参数)在 System.Web.Mvc.ControllerActionInvoker.c__DisplayClassb.b__8()在 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)在 System.Web.Mvc.ControllerActionInvoker.c__DisplayClassb.c__DisplayClassd.b__a()在 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(MethodInfo methodInfo, IDictionary`2 个参数,IList`1 个过滤器)在 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)在 System.Web.Mvc.Controller.ExecuteCore()在 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)在 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)在 System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext)在 System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext)在 System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext)在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&completedSynchronously)
解决方案

我们在 LINQ 中遇到了类似的问题,我们得到无法将类型为 'System.Int32' 的对象转换为类型为 'System.String'"和指定演员表无效."

堆栈跟踪示例

System.InvalidCastException:无法将System.Int32"类型的对象转换为System.String"类型.在 System.Data.SqlClient.SqlBuffer.get_String()在 System.Data.SqlClient.SqlDataReader.GetString(Int32 i)在 Read_Person(ObjectMaterializer`1 )在 System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext()在 System.Collections.Generic.List`1..ctor(IEnumerable`1 集合)在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 源)在 RF.Ias.Services.Person.BusinessLogic.PersonTransactionScripts.GetPersons(IEnumerable`1 personIds, Boolean includeAddress, Boolean includeContact)在 CompositionAopProxy_5b0727341ad64f29b816c1b73d11dd44.GetPersons(IEnumerable`1 personIds, Boolean includeAddress, Boolean includeContact)在 RF.Ias.Services.Person.ServiceImplementation.PersonService.GetPersons(GetPersonRequest 请求)System.InvalidCastException:指定的强制转换无效.在 System.Data.SqlClient.SqlBuffer.get_Int32()在 System.Data.SqlClient.SqlDataReader.GetInt32(Int32 i)在 Read_GetRolesForOrganisationResult(ObjectMaterializer`1)在 System.Data.Linq.SqlClient.ObjectReaderCompiler.ObjectReader`2.MoveNext()在 System.Collections.Generic.List`1..ctor(IEnumerable`1 集合)在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 源)在 RF.Ias.Services.Role.DataAccess.RoleDataAccess.GetRolesForOrganisation(GetRolesForOrganisationCriteria 标准, Int32 pageIndex, Int32 pageSize, Int32& recordCount)在 RF.Ias.Services.Role.BusinessLogic.RoleTransactionScripts.GetRolesForOrganisation(GetRolesForOrganisationCriteria 标准, Int32 pageIndex, Int32 pageSize, Int32& recordCount)在 CompositionAopProxy_4bd29c6074f54d10a2c09bd4ab27ca66.GetRolesForOrganisation(GetRolesForOrganisationCriteria 标准, Int32 pageIndex, Int32 pageSize, Int32& recordCount)在 RF.Ias.Services.Role.ServiceImplementation.RoleService.GetRolesForOrganisation(GetRolesForOrganisationRequest 请求)

如果我们第一次遇到这样的异常System.InvalidOperationException: 已经有一个与此命令关联的打开的 DataReader 必须先关闭",我们就会得到这些异常.或从服务器接收结果时发生传输级错误.(提供者:TCP 提供者,错误:0 - 远程主机强行关闭了现有连接.)".

第一个异常发生在 DataCONtext 的不同实例上,然后发生在所有随后的实例上.

经过一些研究和询问 thread ,我发现原因是我没有处理DataContexts.在我开始这样做之后,它就消失了.

I just launched my tiny webapp on my humble dedicated server (Win2003)... running ASP.NET MVC, LINQ2SQL, SQL Express 2005, and IIS6 (setup with wildcard mapping)

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

This error is ONLY thrown at high traffic. I have NO IDEA how or exactly why this happens. Caching did not remove this problem entirely.

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

Stacktrace (from Event Log):

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)
解决方案

We had a similar problem with LINQ that we get "Unable to cast object of type 'System.Int32' to type 'System.String'" and "Specified cast is not valid."

Examples of stacktraces

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)

We used to get these exceptions if we first got a exception like this "System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first." or " A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)".

The first exception occur for a different instance of the DataCOntext then for all those that then are following.

After some research and asking in this thread , I found that the reason was that I did not dispose the DataContexts. After I started to do that, it dissappered.

这篇关于ASP.NET-MVC (IIS6) 高流量错误:指定的转换无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 23:16