当使用需要超过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
我找不到使用实体框架4.3及其'DbContext设置linq查询的命令超时的方法.如何在实体框架中增加Commandtimeout?
编辑 我实际上正在寻找命令超时增加.我混淆了两个,它是sql命令超时而不是连接.
谢谢
.net c# entity-framework command-timeout entity-framework-4.3
我们的添加迁移通常会失败但不一致.迁移总是进入脚手架步骤,然后大约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中运行.
我有这个LINQ查询
dbContext.Customers.Where(c => c.AssetTag == assetTag).Count();
Run Code Online (Sandbox Code Playgroud)
要么
(from c in dbContext.Customers
where c.AssetTag == assetTag
select c).Count();
Run Code Online (Sandbox Code Playgroud)
生成的SQL是
SELECT
[GroupBy1].[A1] AS [C1]
FROM ( SELECT
COUNT(1) AS [A1]
FROM [dbo].[Customer] AS [Extent1]
WHERE (([Extent1].[AssetTag] = @p__linq__0) AND ( NOT ([Extent1].[AssetTag] IS NULL OR @p__linq__0 IS NULL))) OR (([Extent1].[AssetTag] IS NULL) AND (@p__linq__0 IS NULL))
) AS [GroupBy1]
Run Code Online (Sandbox Code Playgroud)
那么为什么LINQ会为一个简单的where语句生成如此复杂的SQL呢?
我对MVC代码第一个应用程序开发相对较新,我试图在VPS中托管MVC代码第一个应用程序.当发布应用程序后尝试浏览网站时,我正在等待操作超时错误.我尝试做了一些研究,发现在SQL配置管理器上启用TCP/IP帮助了一些,但我没有运气.下面添加的是堆栈跟踪,有谁知道问题是什么?
[Win32Exception (0x80004005): The wait operation timed out]
[SqlException (0x80131904): Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=4223; handshake=2965; ]
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +356
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) …Run Code Online (Sandbox Code Playgroud)