Click here to Skip to main content
15,921,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a microsservice which does search functionality.

In the Data access layer we use Entity framework to speak with DB.

We have millions of records in the DB, for a particular search keyword it takes more time (approx - 110 seconds) since the query takes time to render the data the entity context throws an timed out exception.

The Inner Exception is :
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.",
"ExceptionType": "System.Data.SqlClient.SqlException",
"StackTrace": " at System.Data.SqlClient.SqlCommand.<>c.<executedbdatareaderasync>b__167_0(Task`1 result)\r\n at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()\r\n at System.Threading.Tasks.Task.Execute()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.<executestorecommandsasync>d__c.MoveNext()",
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "The wait operation timed out",
"ExceptionType": "System.ComponentModel.Win32Exception",
"StackTrace": null
}

So my question is how do i make the code to wait until i get a response from DB.
Is there any web configuration i can add such that i can make the code to wait?

Any suggestions/solutions is highly appreciated.

What I have tried:

I have tried setting the Connection Timeout paramter in connection string to 3000 seconds.
Connection Timeout=120;
Posted
Updated 24-Mar-17 4:23am

1 solution

The connection timeout controls how long your application will wait for a database connection to be established. It has no effect on how long the application will wait for a database query to execute.

You need to change the context.Database.CommandTimeout property instead:
Database.CommandTimeout Property (System.Data.Entity)[^]
 
Share this answer
 
Comments
Member 1097736 25-Mar-17 5:55am    
Thanks Richard.I want to know if there is any way to specify it in configuration file?
Richard Deeming 27-Mar-17 13:31pm    
Not that I've seen. You can store the value in the config file, but you still have to write code to retrieve it and apply it to the context.
Member 1097736 27-Mar-17 14:24pm    
Great.Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900