SQL异常使用.NET 4和EF [英] Sql Exception With .net 4 & EF

查看:86
本文介绍了SQL异常使用.NET 4和EF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用的是.NET 4 MVC2与EF和放大器; SQL Server 2005中。

we are using .net 4 MVC2 with EF & Sql Server 2005.

对于一些要求,而且它很少发生,只有当我们正在做这与映射到存储过程类进行全文搜索执行搜索,我们得到 异常:

For some requests, and it happens rarely, and only when we are doing search which is implemented with classes mapped to stored procedures performing full text search, we get the exception:

[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) +2030802
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009584
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
   System.Data.SqlClient.SqlDataReader.get_MetaData() +86
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +311
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +987
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
   System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) +10
   System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +443

[EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.]
   System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +479
   System.Data.Objects.ObjectContext.CreateFunctionObjectResult(EntityCommand entityCommand, EntitySet entitySet, EdmType edmType, MergeOption mergeOption) +182
   System.Data.Objects.ObjectContext.ExecuteFunction(String functionName, MergeOption mergeOption, ObjectParameter[] parameters) +218
   System.Data.Objects.ObjectContext.ExecuteFunction(String functionName, ObjectParameter[] parameters) +53

如果发生(具有相同或不同的术语)之后的错误的搜索重试,它定期的工作原理。

If the search is retried after the error occurs (with same or different term), it works regularly.

pciated任何建议及AP $ P $

Any suggestions well appreciated

感谢

- MB

思想1:唯一的例外似乎发生在建立连接到SQL Server之后,并正在执行存储过程的同时,对吗?如果是这样的话,那么我就需要扩展查询执行超时,而不是连接超时?这是可能的,在哪里?

THOUGHT 1: The exception seems to happen after the connection to sql server is made, and while the stored procedure is being executed, am I correct? If this is the case, then I would need to extend the query execution timeout and not the connection timeout? Is this possible, where?

2思考:也许我是错的,这可能是在游泳池里陈旧的连接?在Java世界里,你可以传递一个应用程序获得它,以确保打开了连接和工作之前,在连接上执行的SQL?莫非是导致此。我一直没能找到这样的选项在<一个href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx">http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx

THOUGHT 2: Perhaps I am wrong and this could be a stale connection in the pool? In Java world you can pass the sql that is executed on the connection before the app obtains it to make sure the connection is opened and working? Could that be causing this. I have not been able to locate such an option within http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx

思想3:我迷路了:)​​

THOUGHT 3: I'm lost :)

推荐答案

您可以尝试设置<一href="http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.commandtimeout.aspx"><$c$c>ObjectContext.CommandTimeout属性:

You can try setting the ObjectContext.CommandTimeout property:

获取或设置超时值,以秒为单位,对所有对象上下文操作。 null值指示底层提供程序的默认值将被使用。

Gets or sets the timeout value, in seconds, for all object context operations. A null value indicates that the default value of the underlying provider will be used.

这篇关于SQL异常使用.NET 4和EF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆