我的命令保持超时,所以我需要更改默认命令超时值.
我发现了myDb.Database.Connection.ConnectionTimeout,但它确实如此readonly.
如何在Entity Framework 5中设置命令超时?
我找不到使用实体框架4.3及其'DbContext设置linq查询的命令超时的方法.如何在实体框架中增加Commandtimeout?
编辑 我实际上正在寻找命令超时增加.我混淆了两个,它是sql命令超时而不是连接.
谢谢
.net c# entity-framework command-timeout entity-framework-4.3
为这个措辞奇怪的问题道歉.我不知道实际问题是什么,但希望有人可以给我一些见解.
尝试运行迁移时出现以下错误:
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
Run Code Online (Sandbox Code Playgroud)
值得注意的是,在我的笔记本电脑上,这种情况并没有发生,但在我的虚拟机(天蓝色 - 大)上,这种情况发生率为100%.
我使用的是Ef 6.0.0 -rc1.请注意,更新EF不是一个选项.如果更新到EF 6.0.0或6.0.1,我将收到以下错误,100%失败率:
我也计时了错误.触发错误大约需要1.5分钟.当使用-Verboseflag 运行时,它试图创建200个带索引的表.复制sql查询并在SSMS中将其排除需要5秒.
我厌倦但没有用的一些事情:
1)ObjectContext.CommandTimeout = 36000 // 10 hours!如下所示设置:
2)在"web.config"中设置连接字符串中的超时:
connectionString="Data Source=localhost;Initial Catalog=myDB;Integrated Security=SSPI;Connection Timeout=36000"
3)设置"machine.config"事务maxTimeout:
<system.transactions>
<machineSettings maxTimeout="00:00:00" />
</system.transactions>
4)在sql server上设置"远程查询超时"
USE MyDB;
GO
EXEC sp_configure 'remote query timeout', 0 ;
GO
RECONFIGURE ; …Run Code Online (Sandbox Code Playgroud) 我试图通过执行自定义Sql使用Entity Framework Migration创建FULL TEXT索引.
我的迁移类看起来像这样:
public partial class DocumentContentFullTextIndex : DbMigration
{
public override void Up()
{
AlterColumn("dbo.Attachments", "ContentType", c => c.String(maxLength: 260));
Sql("CREATE FULLTEXT CATALOG FullTextIndexes AS DEFAULT;", true);
Sql(@"CREATE FULLTEXT INDEX ON [Attachments](
Content
TYPE COLUMN ContentType
Language 'ENGLISH'
)
KEY INDEX [PK_dbo.Attachments]
ON FullTextIndexes;", true);
}
public override void Down()
{
AlterColumn("dbo.Attachments", "ContentType", c => c.String(maxLength: null));
Sql("DROP FULLTEXT INDEX ON [Attachments]");
Sql("DROP FULLTEXT CATALOG FullTextIndexes");
}
}
Run Code Online (Sandbox Code Playgroud)
当我从MSSQL管理工作室运行它时,一切都很完美,SQL完全符合我的预期.
但是当从迁移项目运行时,第二个Sql请求会触发异常
超时已过期.操作完成之前经过的超时时间或服务器没有响应.
带-Verbose标志的完整堆栈跟踪:
Update-Database -ConnectionStringName DatabaseContext -Verbose
Using …Run Code Online (Sandbox Code Playgroud) full-text-indexing sql-server-2012 ef-migrations entity-framework-6
我正在使用Entity Framework 5,我希望知道命令超时值.
为此,我将dbContext对象转换为ObjectContext,然后访问CommandTimeout属性.
int ? currentCommandTimeout = ((IObjectContextAdapter)dbContext).ObjectContext.CommandTimeout;
Run Code Online (Sandbox Code Playgroud)
此属性的当前值为null,这意味着当前命令超时是基础提供程序的默认值.
MSDN ObjectContext CommandTimeout属性参考
编辑:感谢您解释如何设置命令超时并在文档中查找默认命令超时值.但问题仍未解决.如果可能,如何在默认情况下通过EF读取命令超时值.
我想为查询执行设置命令超时,目前我正在做context.Database.CommandTimeout = 90;但我觉得这不起作用,我尝试检查数据库中的进程日志,但发现时间差总是小于90秒.
有人可以帮助我如何在Entity Framework 6中设置数据库超时?
asp.net-mvc entity-framework command-timeout entity-framework-6
我在MySQL中构建了一个数据库,我试图用Entity Framework映射它,但每当我尝试向EF上下文添加超过20个表时,我就会开始运行"GenerateSSDLException".
尝试从数据库更新时发生"Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine + GenerateSSDLException"类型的异常.异常消息是:'执行命令定义时发生错误.有关详细信息,请参阅内部异常.
命令执行期间遇到致命错误.
超时已过期.操作完成之前经过的超时时间或服务器没有响应.
受影响的表没有什么特别之处,并且它永远不会是相同的表,只是在添加了某个(非特定)数量的表后,如果没有"超时过期"错误,则无法再更新上下文.有时它只留下一张桌子,有时它只有三张; 结果非常不可预测.此外,在错误之前可以添加的表数的变化向我表明,问题可能在于生成的查询的大小以更新包括现有表定义的上下文,以及新表.正在加入它.本质上,SQL查询变得太大,并且由于某种原因而无法执行.
如果我使用EdmGen2生成模型,它可以正常工作,但生成的EDMX文件无法在Visual Studio中更新而不会产生上述异常.
很可能这个问题的根源在于Visual Studio中的工具,因为EdmGen2工作正常,但我希望其他人可以就如何处理这个非常独特的问题提供一些建议,因为看起来我不是唯一经历过它的人.
一位同事提出的一个建议是维护两个单独的EBMX文件和一些表格交叉,但在我看来,这似乎是一个非常难看的修复.我想这是我尝试使用"新技术"的原因.:(
我想将ConnectionTimeout设置为默认值以外的值,即15秒.我继承了一些使用EntityFramework的代码,app.config看起来像这样:
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS; Integrated Security=True; ConnectionTimeout=30; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; ConnectionTimeout=30; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
Run Code Online (Sandbox Code Playgroud)
我是那个为了让事情发挥作用而添加了sectino的人.我可以告诉它在设置断点时无效:
var adapter = (IObjectContextAdapter) this;
var objectContext = adapter.ObjectContext;
objectContext.CommandTimeout = CommandTimeoutSeconds;
int test = objectContext.Connection.ConnectionTimeout;
Run Code Online (Sandbox Code Playgroud)
测试始终是15.发生了什么?有人能告诉我如何设置ConnectionTimeout吗?我已经尝试过"ConnectionTimeout"和"Connection Timeout",即没有空间与空间.
有人能帮我吗?我把头发拉了出来.我确定这是一个简单的修复!戴夫
附加信息.回应评论,这是我的DbContext派生类...
public class SessionDataContext : DbContext
{
// Command timeout (seconds)
private const int CommandTimeoutSeconds = 30;
/// <summary> …Run Code Online (Sandbox Code Playgroud) 我们正在使用.net 4 MVC2与EF和Sql Server 2005.
对于某些请求,它很少发生,并且只有当我们进行搜索时,这是通过映射到执行全文搜索的存储过程的类实现的,我们得到异常:
[SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2030802
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009584
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
System.Data.SqlClient.SqlDataReader.get_MetaData() +86
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +311
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +987
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162 …Run Code Online (Sandbox Code Playgroud) 编译器是否将任何乘法优化为1?也就是说,考虑一下:
int a = 1;
int b = 5 * a;
Run Code Online (Sandbox Code Playgroud)
表达式5*a是否会被优化为5?如果不是,如果a被定义为:
const int a = 1;
Run Code Online (Sandbox Code Playgroud) 我正在使用实体框架来调用一个需要 2 分钟才能执行的存储过程。结果,我收到超时异常。
有什么方法可以使用我的存储过程而不会出现超时异常?
c# ×6
.net ×3
asp.net-mvc ×2
.net-4.5 ×1
connection ×1
edmgen ×1
mysql ×1
optimization ×1
sql ×1
sql-server ×1