当使用需要超过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台Windows 2003计算机的服务器场中部署了几个ASP.NET应用程序.每个应用程序在IIS中使用单独的应用程序池和虚拟目录.他们严重依赖其持久会话进程外的单个的SQL Server 2000(上<sessionstate mode="sqlserver" ... />).应用程序是针对.NET 3.0编译的,但.NET 3.5 SP1安装在服务器上.
每个Web服务器每秒接收大约10个请求.每隔一段时间我就会在日志中遇到一些异常:
System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.)
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()
at System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
at System.Data.SqlClient.TdsParserStateObject.ReadByte()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at …Run Code Online (Sandbox Code Playgroud) 为这个措辞奇怪的问题道歉.我不知道实际问题是什么,但希望有人可以给我一些见解.
尝试运行迁移时出现以下错误:
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)