当使用需要超过30秒才能完成的函数导入时,我将使用实体框架(EF)获得超时.我尝试了以下操作,但无法解决此问题:
我添加Default Command Timeout=300000到项目中App.Config文件中的连接字符串,该文件具有此处建议的EDMX文件.
这是我的连接字符串的样子:
<add
name="MyEntityConnectionString"
connectionString="metadata=res://*/MyEntities.csdl|res://*/MyEntities.ssdl|
res://*/MyEntities.msl;
provider=System.Data.SqlClient;provider connection string="
Data Source=trekdevbox;Initial Catalog=StarTrekDatabase;
Persist Security Info=True;User ID=JamesTKirk;Password=IsFriendsWithSpock;
MultipleActiveResultSets=True;Default Command Timeout=300000;""
providerName="System.Data.EntityClient" />
Run Code Online (Sandbox Code Playgroud)
我尝试直接在我的存储库中设置CommandTimeout,如下所示:
private TrekEntities context = new TrekEntities();
public IEnumerable<TrekMatches> GetKirksFriends()
{
this.context.CommandTimeout = 180;
return this.context.GetKirksFriends();
}
Run Code Online (Sandbox Code Playgroud)
我还能做些什么来让EF超时?这仅适用于非常大的数据集.小数据集一切正常.
这是我得到的错误之一:
System.Data.EntityCommandExecutionException:执行命令定义时发生错误.有关详细信息,请参阅内部异常 ---> System.Data.SqlClient.SqlException:超时已过期.操作完成之前经过的超时时间或服务器没有响应.
好的 - 我得到了这个工作,发生了什么事很愚蠢.我有连接字符串Default Command Timeout=300000和CommandTimeout设置为180.当我Default Command Timeout从连接字符串中删除它,它工作.所以答案是在上下文对象的存储库中手动设置CommandTimeout,如下所示:
this.context.CommandTimeout = 180;
Run Code Online (Sandbox Code Playgroud)
显然在连接字符串中设置超时设置对它没有影响.
c# asp.net entity-framework connection-string entity-framework-4
我正在使用最新的(1.0.0)版本的EF Core.我有一个迁移到一个相当大的数据库上运行.
我跑:
dotnet ef数据库更新-c ApplicationDbContext
得到:
超时已过期.操作完成之前经过的超时时间或服务器没有响应.
在连接字符串中,我明确地设置了超时,如下所示:
连接超时= 150000
不幸的是,它没有帮助.我该怎么做?
我们的添加迁移通常会失败但不一致.迁移总是进入脚手架步骤,然后大约5次中有4次我们会收到如下内容:
System.Runtime.Remoting.RemotingException: Object '/2355037d_df43_460b_8737_725c0c1c80be/hvdculybngjc_rcnskixmk7+_2.rem' has been disconnected or does not exist at the server.at EnvDTE.Project.get_Properties()
at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetPropertyValue[T] (Project project, String propertyName)
at System.Data.Entity.Migrations.Extensions.ProjectExtensions.AddFile(Project project, String path, String contents)
at System.Data.Entity.Migrations.Utilities.MigrationWriter.Write(ScaffoldedMigration scaffoldedMigration, Boolean rescaffolding, Boolean force, String name)
at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass3.<.ctor>b__1()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Object '/2355037d_df43_460b_8737_725c0c1c80be/hvdculybngjc_rcnskixmk7+_2.rem' has been disconnected or does not exist at the server.
Run Code Online (Sandbox Code Playgroud)
有时迁移类无论如何都会生成,但更常见的情况是它不会生成.对这个错误的搜索已经表明某些东西正在被垃圾收集,这不应该是,但这并没有真正帮助我们解决这个问题.
我们的数据迁移项目在.NET 4.5中,EF 5在Windows 8,Visual Studio 2012和SQL Server 2012中运行.
我在SQL Server 2008上使用Entity Framework 6.1.1,我有一个长期运行的代码第一次迁移(大约20分钟).它结束然后给出以下错误.
System.Runtime.Remoting.RemotingException: Object '/f10901d8_94fe_4db4_bb9d_51cd19292b01/bq6vk4vkuz5tkri2x8nwhsln_106.rem' has been disconnected or does not exist at the server.
at System.Data.Entity.Migrations.Design.ToolingFacade.ToolLogger.Verbose(String sql)
at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement, DbInterceptionContext interceptionContext)
at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbTransaction transaction, DbInterceptionContext interceptionContext)
at System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection)
at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClass30.<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, DbTransaction existingTransaction)
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 …Run Code Online (Sandbox Code Playgroud) 我目前在EF迁移中运行SQL()命令时遇到SQL超时。
情况:我要用一个表替换一堆(> 50)表,并且需要将要放入新表中的那些表中的数据转换。我通过以下方式组织了迁移:
1.创建新表。
3.删除所有旧表。
当前,迁移会产生以下错误:
System.Data.SqlClient.SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
The statement has been terminated. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
该错误发生在我为他们提供安装程序的环境中,并且他们在没有我参与的情况下运行了该安装程序,因此我无法手动运行单个迁移,而在中间暂停以运行SQL脚本。
有什么方法可以更改连接超时或解决此问题?
环境:
EF 6.0代码优先
SQL Server 2012