EF代码优先 - 超时已过期。完成之前经过的超时时间 [英] EF Code First - Timeout expired. The timeout period elapsed prior to completion

查看:331
本文介绍了EF代码优先 - 超时已过期。完成之前经过的超时时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这个奇怪的措辞问题的道歉。我不知道实际的问题是什么,但希望有人可以给我一些见解。



尝试运行迁移时我收到以下错误:

 超时已过期。在完成操作或服务器之前经过的超时时间没有响应。 ---> System.ComponentModel.Win32Exception(0x80004005):等待操作超时

有趣的是,我的笔记本电脑没有发生,但在我的虚拟机(天蓝色 - 大型)这是发生在100%的失败率。



我正在使用 Ef 6.0.0 - RC1 即可。请注意,更新EF不是一个选项。如果更新到EF 6.0.0或6.0.1,我将收到以下错误,100%的失败率:



在代码第一次添加迁移期间的错误



我也对错误进行了计时。触发错误大约需要1.5分钟。当使用 -Verbose 标志运行时,它尝试使用索引创建200个表。复制sql查询并在SSMS中排除它需要5秒。



一些我累了但没有工作的东西:



1)设置 ObjectContext.CommandTimeout = 36000 // 10小时!如下所示:



https://stackoverflow.com/a/6234593/305469



2)在web.config中设置连接字符串中的超时值:




connectionString =Data Source = localhost;初始目录= myDB;集成安全= SSPI;连接超时= 36000



3)设置machine.config事务maxTimeout:




< system.transactions>
< machineSettings maxTimeout =00:00:00/>
< /system.transactions>



4)在sql server上设置远程查询超时

 使用MyDB; 
GO
EXEC sp_configure'remote query timeout',0;
GO
RECONFIGURE;
GO

那么发生了什么?如何进入 CommandTimeout 不被尊重?任何建议?



完整追踪如下:

  System.Data .SqlClient.SqlException(0x80131904):超时过期。在完成操作或服务器之前经过的超时时间没有响应。 ---> System.ComponentModel.Win32Exception(0x80004005):等待操作超时

在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,Boolean breakConnection,Action`1 wrapCloseInAction)
在系统System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,Boolean callerHasConnectionLock,Boolean asyncClose)中的
在System .Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj,Boolean& dataReady)
在System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName,Boolean async,Int32超时)
在System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1完成,String methodName,Boolean sendToPipe,Int32超时,Boolean asyncWrite)
在System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
在System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch [TInterceptionContext,TResult](Func`1操作,TInterceptionContext interceptionContext,Action`1执行,Action`1执行)
在System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand命令,DbCommandInterceptionContext interceptionContext)
在System.Data.Entity。 Internal.InterceptableDbCommand.ExecuteNonQuery()
在System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction事务,MigrationStatement migrationStatement)
在System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(DbTransaction事务,MigrationStatement migrationStatement)
在System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements,DbConnection连接)
在System.Data.Entity.Migratio ns.DbMigrator。c__DisplayClass32。< ExecuteStatements> b__2e()
在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy。  c__DisplayClass1。< Execute> b__0()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute [TResult](Func`1操作)
在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action操作)
在System.Data.Entity .Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements)
在System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable`1 migrationStatements)
在System.Data.Entity.Migrations.DbMigrator .ExecuteOperations(String migrationId,XDocument targetModel,IEnumerable`1操作,IEnumerable`1 systemOperations,Boolean downgrading,Boolean auto)
在System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration,DbMigration lastMigration)
在System.Data.Entity.Migrations.Infrastructure.MigratorL oggingDecorator.ApplyMigration(DbMigration migration,DbMigration lastMigration)
在System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations,String targetMigrationId,String lastMigrationId)
在System.Data.Entity.Migrations .Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations,String targetMigrationId,String lastMigrationId)
在System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
在System.Data.Entity.Migrations .DbMigrator。c__DisplayClassc。< Update> b__b()
在System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
在System.Data.Entity.Migrations.Infrastructure .MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
在System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
在System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration) $在System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
在System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
在System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
$在System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)上的b $ b $ System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration,Boolean force)

在System.Data.Entity.Migrations.UpdateDatabaseCommand。c__DisplayClass2。< .ctor> b__0()
在System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action命令)
ClientConnectionId :8cbbc70c-8182-417e-9aca-4603f797340d
超时到期。在完成操作或服务器之前经过的超时时间没有响应。


解决方案

在Configuration.cs类的构造函数文件夹)添加属性CommandTimeout = Int32.MaxValue;


Apology for this strangely worded question. I don't know what the actual problem is but hopefully someone can give me some insights.

I am getting the following error when trying to run migrations:

Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

It is interesting to note that on my laptop this is not happening but on my VM (azure - large) this is happening with 100% failure rate.

I am using Ef 6.0.0 -rc1. Please note, updating EF is not an option. If updating to EF 6.0.0 or 6.0.1 I will get the following error with 100% failure rate:

Errors during Code First add-migration

I have also timed the error. It takes about 1.5 min to trigger the error. When running with -Verbose flag it was trying to create 200 tables with indexes. Copying the sql query and excuting it in SSMS takes 5 secs.

A few things that I have tired but didn't work:

1) Setting ObjectContext.CommandTimeout = 36000 // 10 hours! as indicated here:

https://stackoverflow.com/a/6234593/305469

2) Setting timeout in connection string in "web.config":

connectionString="Data Source=localhost;Initial Catalog=myDB;Integrated Security=SSPI;Connection Timeout=36000"

3) Setting "machine.config" transaction maxTimeout:

<system.transactions> <machineSettings maxTimeout="00:00:00" /> </system.transactions>

4) Setting "remote query timeout" on sql server

USE MyDB;
GO
EXEC sp_configure 'remote query timeout', 0 ;
GO
RECONFIGURE ;
GO

So what is happening? How come CommandTimeout is not being respected? Any suggestions?

Full trace as follows:

System.Data.SqlClient.SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TInterceptionContext,TResult](Func`1 operation, TInterceptionContext interceptionContext, Action`1 executing, Action`1 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery()
   at System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection)
   at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClass32.<ExecuteStatements>b__2e()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable`1 migrationStatements)
   at System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto)
   at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
   at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClassc.<Update>b__b()
   at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
   at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
ClientConnectionId:8cbbc70c-8182-417e-9aca-4603f797340d
Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

解决方案

In the constructor of Configuration.cs class (in migration Folder) add the property CommandTimeout = Int32.MaxValue;

这篇关于EF代码优先 - 超时已过期。完成之前经过的超时时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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