简体   繁体   English

EF、SQL Server - 连接超时已过期。 登录后阶段已过的超时时间

[英]EF, SQL Server - Connection Timeout Expired. The timeout period elapsed during the post-login phase

I've created an ASP.NET MVC project that uses Entity Framework and Identity.我创建了一个使用实体框架和标识的 ASP.NET MVC 项目。

The problem is that when I debug my project, I get an error.问题是当我调试我的项目时,出现错误。

(note: If I delete my DB from SQL Server Object Explorer and run it again this error don't show up, but I don't want to manually delete it every time) (注意:如果我从 SQL Server 对象资源管理器中删除我的数据库并再次运行它,则不会出现此错误,但我不想每次都手动删除它)

Error:错误:

Connection Timeout Expired.连接超时已过期。 The timeout period elapsed during the post-login phase.在登录后阶段超时时间已过。 The connection could have timed out while waiting for server to complete the login process and respond;连接可能在等待服务器完成登录过程并响应时超时; Or it could have timed out while attempting to create multiple active connections.或者它可能在尝试创建多个活动连接时超时。 The duration spent while attempting to connect to this server was - [Pre-Login] initialization=15;尝试连接到此服务器所花费的持续时间为 - [Pre-Login] 初始化 = 15; handshake=3;握手=3; [Login] initialization=0; 【登录】初始化=0; authentication=2;认证=2; [Post-Login] complete=14991 [登录后]完成=14991

Connection string:连接字符串:

<add name="MovieReviewsDb" 
     providerName="System.Data.SqlClient" 
     connectionString="Data Source(LocalDb)\v11.0;AttachDbFileName=|DataDirectory|\MovieReviewsDb.mdf;Initial Catalog=MovieReviewsDb;Integrated Security=SSPI;MultipleActiveResultSets=True" />   

I've set custom initializer that inherits from DropCreateDatabaseAlways .我已经设置了从DropCreateDatabaseAlways继承的自定义初始值设定DropCreateDatabaseAlways I have overridden the Seed method where I populate the database with 3 records and creates default roles and users (Identity).我已经覆盖了用 3 条记录填充数据库并创建默认角色和用户(身份)的Seed方法。

(note: my DbContext inherits from IdentityDbContext ) (注意:我的DbContext继承自IdentityDbContext

I'm stuck at this for several hours and searched through a lot of similar posts ( like this one ) but I can't find an answer.我坚持了几个小时并搜索了很多类似的帖子( 比如这个),但我找不到答案。

Is it possible to set a bigger timeout (maybe It takes too long and the timeout is reached) and how?是否可以设置更大的超时时间(可能需要太长时间并且达到超时时间)以及如何设置?

I think I've finally figured it out. 我想我终于明白了。

I've added ;Connection Timeout=120; 我添加了;Connection Timeout=120; to my connection string and it works. 到我的连接字符串,它的工作原理。 I guess it just needed more time. 我想这只需要更多时间。

There are two different solutions increase the timeout or retry policy for network problems有两种不同的解决方案增加网络问题的超时或重试策略

  1. Connection timeout连接超时

Change the connection string as below.更改连接字符串如下。

"ConnectionString": "...;Connection Timeout=120;"
  1. Retry policy重试策略

Refactoring code in manner so that it would allow you to call the query recursively till you get a desired result.以某种方式重构代码,以便它允许您递归地调用查询,直到获得所需的结果。

for example Polly retry policy例如Polly重试策略

Re-try to open a SQL Server connection if failed 如果失败,请重新尝试打开 SQL Server 连接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 连接超时已过期。 登录后阶段已过的超时时间 - Connection Timeout Expired. The timeout period elapsed during the post-login phase SQL Server异常:超时已过期。 操作完成之前经过的超时时间或服务器未响应 - SQL Server Exception:Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding 超时已过。 在操作完成之前超时时间已过或服务器未响应 Azure SQL 数据库 - Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding with Azure SQL database EF 代码优先 - 超时已过。 完成前超时时间已过 - EF Code First - Timeout expired. The timeout period elapsed prior to completion 连接泄漏是否会导致Timeout过期。 从池中获取连接之前是否已经过了超时时间? - Will connection leak might Cause Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool? 超时时间已到。 获得连接之前经过的超时时间第一个连接 - Timeout expired. The timeout period elapsed prior to obtaining a connection First connection 超时已过。 在操作完成之前超时时间已过 - Timeout expired. The timeout period elapsed prior to completion of the operation 让超时过期。 从池中获取连接之前经过的超时时间。 。例外 - Getting Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. .exception 获取超时已过期。 从池中获取连接之前经过的超时时间 - Getting Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool 超时已过。 在从池中获取连接之前超时时间已过。 - Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM