实体框架超时 [英] Entity Framework Timeouts

查看:118
本文介绍了实体框架超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用的函数进口接管30秒完成时使用实体框架(EF)超时。我尝试以下,并没有能够解决这个问题:

I am getting timeouts using the Entity Framework (EF) when using a function import that takes over 30 seconds to complete. I tried the following and have not been able to resolve this issue:

我添加默认命令超时​​= 300000 来在 App.Config中的所建议的具有EDMX文件的项目文件中的连接字符串<一href=\"http://stackoverflow.com/questions/1718739/entity-framework-with-mysql-timeout-expired-while-generating-model\">here.

I added Default Command Timeout=300000 to the connection string in the App.Config file in the project that has the EDMX file as suggested here.

这是我的连接字符串如下:

This is what my connection string looks like:

<add 
    name="MyEntityConnectionString" 
    connectionString="metadata=res://*/MyEntities.csdl|res://*/MyEntities.ssdl|res://*/MyEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=trekdevbox;Initial Catalog=StarTrekDatabase;Persist Security Info=True;User ID=JamesTKirk;Password=IsFriendsWithSpock;MultipleActiveResultSets=True;Default Command Timeout=300000;&quot;" 
    providerName="System.Data.EntityClient" />

我试着在我的仓库直接设置的CommandTimeout像这样:

I tried setting the CommandTimeout in my repository directly like so:

private TrekEntities context = new TrekEntities();

public IEnumerable<TrekMatches> GetKirksFriends()
{
    this.context.CommandTimeout = 180;
    return this.context.GetKirksFriends();
}

还有什么我能做得到定时EF了呢?这只发生非常大的数据集。一切正常的小数据集。

What else can I do to get the EF from timing out? This only happens for very large datasets. Everything works fine with small datasets.

下面是我得到的错误之一:

Here is one of the errors I'm getting:

System.Data.EntityCommandExecutionException:执行命令定义时出错。详情请参阅内部异常。 ---> System.Data.SqlClient.SqlException:超时过期。操作完成或服务器之前经过的超时时间没有响应。

System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

确定 - 我得到了这个工作,这是愚蠢的事了。我既有的连接字符串默认命令超时​​= 300000 键,将CommandTimeout设置为180。当我删除了默认命令超时​​从连接字符串,它的工作。因此,答案是手动设置的CommandTimeout在你的仓库上下文对象上,像这样:


OK - I got this working and it's silly what happened. I had both the connection string with Default Command Timeout=300000 and the CommandTimeout set to 180. When I removed the Default Command Timeout from the connection string, it worked. So the answer is to manually set the CommandTimeout in your repository on your context object like so:

this.context.CommandTimeout = 180;

显然设置连接字符串中的超时设置上有没有影响。

Apparently setting the timeout settings in the connection string has no effect on it.

推荐答案

有与EF连接字符串中指定默认命令超时​​一个已知的bug。

There is a known bug with specifying default command timeout within the EF connection string.

http://bugs.mysql.com/bug.php?id=56806

拆下连接字符串值,并将其设置数据上下文对象本身。如果从连接字符串删除冲突,这不错。

Remove the value from the connection string and set it on the data context object itself. This will work if you remove the conflicting value from the connection string.

this.context.Database.CommandTimeout = 180;

实体框架5:

((IObjectContextAdapter)this.context).ObjectContext.CommandTimeout = 180;

实体框架4如下:

this.context.CommandTimeout = 180;

这篇关于实体框架超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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