Reputation: 13616
I use entity framework 6 to access database. On development machine I have SQL SERVER 2014 Express edition. And when I make some complex queries using EF6 it works fine,I get the desired result.
On production machine I have SQL Server 2012 when move the code from development machine to production and the queries fired I get this error:
{"Message":"System.Data.SqlClient.SqlException (0x80131904): 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\r\n at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction)\r\n at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)\r\n at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)\r\n at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()\r\n at System.Data.SqlClient.SqlDataReader.get_MetaData()\r\n at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)\r\n at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds, Boolean describeParameterEncryptionRequest)\r\n at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource
1 completion, Int32 timeout, Task& task, Boolean asyncWrite)\r\n at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)\r\n at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)\r\n at System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func
3 operation, TInterceptionContext interceptionContext, Action3 executing, Action
3 executed)\r\n at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)\r\n at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)\r\nClientConnectionId:4a0350b7-e91e-42a4-ae04-ae94e294c26a\r\nError Number:-2,State:0,Class:11"}
Any idea why I get the error above on production machine while it works fine on development?
Upvotes: 0
Views: 1270
Reputation: 65860
You can increase the timeout as shown below.Try that and let us know.
Important Note : This is just a temporary solution. You have to analyse your EF query and must improve the performance of it. In other words you need to optimise that query. Hence your development database is having less data, you are not experiencing this. But with a heavy data load (like production) you are experiencing the time out issue.The best solution is the optimisation of your EF query.
Note : here time is seconds
public DbContext() : base("Default")
{
this.Database.CommandTimeout = 60;
}
Reference: MSDN: Database.CommandTimeout Property.
Upvotes: 1
Reputation: 151588
A man who seemingly has a broken finger walks into a doctor's office. "Doctor", he says, "It hurts when I press here". The doctor looks and goes "Well, if you press less hard, it hurts less, right?" and sends the man home.
When running into database timeouts, the solution is NOT to knee-jerk and simply increase the timeout, that's terrible advice you're getting here.
Analyze and profile your queries, and optimize your database and queries based on the findings from that analysis.
Upvotes: 4
Reputation: 14669
Better to set Timeout=0, 0 will defined as no limit.
this.Database.CommandTimeout = 0;
Upvotes: 0