MVC 3/EF/SQL Server奇怪的连接超时问题 [英] MVC 3/EF/SQL Server strange connection timeout issue

查看:301
本文介绍了MVC 3/EF/SQL Server奇怪的连接超时问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读之前,请注意,我已经在Google上进行了搜索,并阅读了关于SO和其他地方的大量文章,到目前为止,还没有建议起作用.

Before reading please note that I've googled this and read a ton of articles on SO and elsewhere, no suggestions have worked as of yet.

我随机收到登录MVC 3应用程序时发生的超时错误.这种情况发生的时间远远超过一半-所有其他时间应用程序都可以正常登录.当它不起作用时,它将尝试大约10秒钟,然后出现错误.

I'm randomly getting a timeout error that occurs when logging into my MVC 3 application. It happens well over half of the time - all other times the application logs on just fine. When it doesn't work, it tries for about 10 seconds then errors.

错误:

异常:执行命令定义时发生错误.有关详细信息,请参见内部异常. 内部异常:{超时已到期.在操作完成之前超时或服务器未响应.\ r \ n超时已到期.在操作完成之前未超时或服务器未响应."}

Exception: "An error occurred while executing the command definition. See the inner exception for details." Inner Exception: {"Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.\r\nTimeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."}

这发生在我的与实体框架直接交互的存储库类中.

This happens inside my repository class that directly interacts with entity framework.

这似乎是在登录并仅从数据库中进行快速检查时发生的,例如:

It seems to happen when logging in and simply pulling a quick check from the database, such as:

 return entities.Users.SingleOrDefault(user => user.UserName == userName);

 return (entities.Users.SingleOrDefault(u => u.UserId == user.UserId || u.UserName == user.UserName) != null);

我尝试过的事情:

  • SQL Server验证
  • 集成安全性(我什至为每个可能的帐户提供了完全的数据库访问权限)
  • 在IIS之外运行
  • 在连接字符串中将连接超时"设置为极高的值(连接超时" = 50000). (我没有在此处设置默认命令超时)
  • 在我的实体连接上,将CommandTimeout设置为0、5000、100000,无论如何:Entitys.CommandTieout = 100000;
  • 在使用存储库实例的每个using语句中设置CommandTimeout.
  • 将SingleOrDefault翻转为FirstOrDefault等.
  • 启用/禁用延迟加载(为什么不这样做)

如果有帮助:

  • 我正在使用自定义角色和成员资格提供程序.
  • 我只是在using语句(AccountRepository bleh = new AccountRepository())中从控制器进行调用,并且AccountRepository实现了IDisposable等.
  • 实体模型在一个单独的项目中.
  • 我正在IIS中运行该站点.通过4.0集成的应用程序池进行设置.
  • 所有帐户都具有完全的数据库访问权限.
  • 发生错误时,只要在Web配置中设置(我认为是50000)或在存储库中设置commandtimeout,就可以使用它.
  • 登录时并没有做太多事情,只是验证用户,获取用户角色然后加载少量数据,但是在登录时获取用户数据时总是会发生错误.
  • 当我在调试之外尝试时,它会重复四到五次错误(关闭自定义错误).

这是事件日志中的完整异常:

Here is the full exception from the event log:

Exception information: 
Exception type: SqlException 
Exception message: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

推荐答案

您可以通过设置 SQL Server Profiler 从数据库服务器检查问题.

You could examine the problem from the database server by setting up a SQL Server Profiler.

您可以通过四处查找来找到有关SQL Profiler的许多信息.这是一个网站,其中包含可以帮助您入门的视频.

You can find lots of info about SQL Profiler by just googling around. Here's a site with a video that might help you get started.

这篇关于MVC 3/EF/SQL Server奇怪的连接超时问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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