NHibernate-"GenericADOException: could not execute query"
NHibernate - "GenericADOException: could not execute query"
我们使用 NHibernate v3.1.0.4000 的生产环境突然在使用全文搜索时开始出现此错误:
[SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +404
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +412
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1363
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +59
System.Data.SqlClient.SqlDataReader.get_MetaData() +118
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6388257
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +6389826
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +538
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +28
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +256
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +19
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() +23
NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) +845
NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) +580
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +275
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +205
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +195
[GenericADOException: could not execute query
[ SELECT count(distinct this_.IdDocument) as y0_ FROM Document.Document this_ inner join Document.DocumentCopy documentc1_ on this_.IdDocument=documentc1_.IdDocument WHERE ((@p0 = @p1 and contains(this_.Title, @p2)) and this_.IsDeleted = @p3) and (((@p4 = @p5 and documentc1_.CreationDate >= @p6) and documentc1_.CreationDate <= @p7) and (documentc1_.IdOwnedByGroup = @p8 or documentc1_.IdCreatedByGroup = @p9)) ]
Positional parameters: #0>0 #1>0 #2>"ýÿýÿýÿýÿýÿýÿýÿýÿ*" #3>False #4>0 #5>0 #6>12/5/2015 12:00:00 ýÿýÿ #7>12/5/2016 11:59:00 ýÿýÿ #8>1 #9>1
[SQL: SELECT count(distinct this_.IdDocument) as y0_ FROM Document.Document this_ inner join Document.DocumentCopy documentc1_ on this_.IdDocument=documentc1_.IdDocument WHERE ((@p0 = @p1 and contains(this_.Title, @p2)) and this_.IsDeleted = @p3) and (((@p4 = @p5 and documentc1_.CreationDate >= @p6) and documentc1_.CreationDate <= @p7) and (documentc1_.IdOwnedByGroup = @p8 or documentc1_.IdCreatedByGroup = @p9))]]
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +637
NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) +23
NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor session) +60
NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) +1025
NHibernate.Impl.CriteriaImpl.List(IList results) +63
NHibernate.Impl.CriteriaImpl.UniqueResult() +57
Domain.Repositories.DocumentRepository.Domain.Abstract.IDocumentRepository.GetAll(Criteria1 criteria, Int32& count, Dictionary
2 openFieldCriteria) +272
ServicesImplementation.DocumentService.GetDocuments(Criteria1 criteria, Int32& count, String metadataSearchTerm) +510
Docman.Models.List.ListModel.GetDocuments(Int32& count) +102
ASP._Page_Views_List_Index_cshtml.Execute() in d:\wwwroot\inetpub\docman\Views\List\Index.cshtml:27
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +104
System.Web.WebPages.StartPage.ExecutePageHierarchy() +143
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +157
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +384
System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +33
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func
1 continuation) +826372
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +827248
System.Web.Mvc.Controller.ExecuteCore() +159
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
System.Web.Mvc.<>c__DisplayClassb.b__5() +62
System.Web.Mvc.Async.<>c__DisplayClass1.b__0() +20
System.Web.Mvc.<>c__DisplayClasse.b__d() +54
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375
我已经在 SSMS 上尝试了上面列出的查询,它似乎 运行 既好又快。
这里提到了一个类似的错误:Nhibernate FieldNameLookup throws IndexOutOfRangeException,虽然我的错误信息中没有包含任何IndexOutOfRangeException
。
谁能告诉我这是什么原因造成的?
更新:
更多信息:
我们正在使用预测。
根据错误日志,该错误源自某些查询,该查询只有 returns 个计数,并且包含很多字段的行不多。
正如我之前所说,当我从 SSMS 运行 查询时,相同的查询(在错误日志中列出)运行 很快并且没有任何问题。然而,从执行此 SQL 查询的应用程序发出的所有查询似乎都因上述错误而失败。
您可能不清楚代码,因为我们使用 NH 的自定义包装器。
我认为我对异常的顺序是错误的,首先发生超时,然后 ADO.net 报告另一个错误。
所以,我想毕竟是超时了...
更新 2:
经过一些额外的研究,这似乎与这个问题有关,查询确实超时,只是不是来自 SSMS:
Query times out when executed from web, but super-fast when executed from SSMS
原来是一个无法从 SSMS 重现的超时,因为它使用了不同的 ARITHABORT
值(在我的应用程序会话和 SSMS 会话之间)。
一旦我将数据库的默认值设置为 ON
/1
,一切都已修复:
USE [master];
GO
ALTER DATABASE [{database_name}] SET ARITHABORT ON WITH NO_WAIT;
GO
我们使用 NHibernate v3.1.0.4000 的生产环境突然在使用全文搜索时开始出现此错误:
[SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +404 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +412 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1363 System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +59 System.Data.SqlClient.SqlDataReader.get_MetaData() +118 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6388257 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +6389826 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +538 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +28 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +256 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +19 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() +23 NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) +845 NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) +580 NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +275 NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +205 NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +195
[GenericADOException: could not execute query [ SELECT count(distinct this_.IdDocument) as y0_ FROM Document.Document this_ inner join Document.DocumentCopy documentc1_ on this_.IdDocument=documentc1_.IdDocument WHERE ((@p0 = @p1 and contains(this_.Title, @p2)) and this_.IsDeleted = @p3) and (((@p4 = @p5 and documentc1_.CreationDate >= @p6) and documentc1_.CreationDate <= @p7) and (documentc1_.IdOwnedByGroup = @p8 or documentc1_.IdCreatedByGroup = @p9)) ] Positional parameters: #0>0 #1>0 #2>"ýÿýÿýÿýÿýÿýÿýÿýÿ*" #3>False #4>0 #5>0 #6>12/5/2015 12:00:00 ýÿýÿ #7>12/5/2016 11:59:00 ýÿýÿ #8>1 #9>1 [SQL: SELECT count(distinct this_.IdDocument) as y0_ FROM Document.Document this_ inner join Document.DocumentCopy documentc1_ on this_.IdDocument=documentc1_.IdDocument WHERE ((@p0 = @p1 and contains(this_.Title, @p2)) and this_.IsDeleted = @p3) and (((@p4 = @p5 and documentc1_.CreationDate >= @p6) and documentc1_.CreationDate <= @p7) and (documentc1_.IdOwnedByGroup = @p8 or documentc1_.IdCreatedByGroup = @p9))]] NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +637 NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) +23 NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor session) +60 NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) +1025 NHibernate.Impl.CriteriaImpl.List(IList results) +63 NHibernate.Impl.CriteriaImpl.UniqueResult() +57 Domain.Repositories.DocumentRepository.Domain.Abstract.IDocumentRepository.GetAll(Criteria
1 criteria, Int32& count, Dictionary
2 openFieldCriteria) +272 ServicesImplementation.DocumentService.GetDocuments(Criteria1 criteria, Int32& count, String metadataSearchTerm) +510 Docman.Models.List.ListModel.GetDocuments(Int32& count) +102 ASP._Page_Views_List_Index_cshtml.Execute() in d:\wwwroot\inetpub\docman\Views\List\Index.cshtml:27 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280 System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +104 System.Web.WebPages.StartPage.ExecutePageHierarchy() +143 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +157 System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +384 System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +33 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func
1 continuation) +826372 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +827248 System.Web.Mvc.Controller.ExecuteCore() +159 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335 System.Web.Mvc.<>c__DisplayClassb.b__5() +62 System.Web.Mvc.Async.<>c__DisplayClass1.b__0() +20 System.Web.Mvc.<>c__DisplayClasse.b__d() +54 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375
我已经在 SSMS 上尝试了上面列出的查询,它似乎 运行 既好又快。
这里提到了一个类似的错误:Nhibernate FieldNameLookup throws IndexOutOfRangeException,虽然我的错误信息中没有包含任何IndexOutOfRangeException
。
谁能告诉我这是什么原因造成的?
更新:
更多信息:
我们正在使用预测。
根据错误日志,该错误源自某些查询,该查询只有 returns 个计数,并且包含很多字段的行不多。
正如我之前所说,当我从 SSMS 运行 查询时,相同的查询(在错误日志中列出)运行 很快并且没有任何问题。然而,从执行此 SQL 查询的应用程序发出的所有查询似乎都因上述错误而失败。
您可能不清楚代码,因为我们使用 NH 的自定义包装器。
我认为我对异常的顺序是错误的,首先发生超时,然后 ADO.net 报告另一个错误。 所以,我想毕竟是超时了...
更新 2:
经过一些额外的研究,这似乎与这个问题有关,查询确实超时,只是不是来自 SSMS:
Query times out when executed from web, but super-fast when executed from SSMS
原来是一个无法从 SSMS 重现的超时,因为它使用了不同的 ARITHABORT
值(在我的应用程序会话和 SSMS 会话之间)。
一旦我将数据库的默认值设置为 ON
/1
,一切都已修复:
USE [master];
GO
ALTER DATABASE [{database_name}] SET ARITHABORT ON WITH NO_WAIT;
GO