Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET 4.0 Entity framework timeout expired [closed]

I'm developing an ASP.NET website using MVC3, .NET framework 4.0 and Entity Framework. When I run the application and perform a simple select to a SQL Server 2005 database I get the following error:

"A System.Data.SqlClient.SqlException was thrown: "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."

This is the thing. I tried logging in and performing the same query from management studio and it worked. I developed a small console application using .NET framework 4.0 and entity framework performing the exact same query and it returned the information I needed. I even switched from using Entity framework to ADO.NET classes (SqlConnection and SqlCommand) and when executing the select from the SqlCommand instance I get the exact same error.

When I created the model using entity framework I was able to connect from the wizard to the database and it worked fine. I got all the classes created without any problems.

Please don't tell me the solution is to increase any timeout because the query is really small (20 records tops) and as I said before it worked fine when running it from a console application using the same technology and even the same code I place below.

This is the code giving me the problem:

MLIBEntities dbMLIB = new MLIBEntities();

var searchResults = (from s in dbMLIB.Sets
                     where s.setmap1.StartsWith(accountNumber)
                     select s);

return searchResults.ToList();

The exception is thrown when running searchResults.ToList();

This is my connection string being used by the entity classes. I'm sure it uses the connection string since I modified it with syntax errors and they were detected.

<connectionStrings>
    <add name="MLIBEntities" connectionString="metadata=res://*/Models.MlibDBModel.csdl|res://*/Models.MlibDBModel.ssdl|res://*/Models.MlibDBModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=HERPADERP;Initial Catalog=MLIB;Integrated Security=True;MultipleActiveResultSets=True;Connect Timeout=200&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

I'm guessing this must be a configuration problem somewhere in the MVC web application or I'm just missing something in the Web.config file. Have any of you had this problem? I know it's really weird.

Thank you for your help. I'm really out of ideas.

One last thing. I ran the SQL profiler and it seems like the query never makes it to the database server. Any ideas of why could this be happening?

like image 873
Alvos Avatar asked Feb 07 '11 22:02

Alvos


People also ask

How do I fix the connection timeout expired in SQL Server?

If you encounter a connection-timeout error, follow the steps: Increase the connection-timeout parameter. If you use an application to connect to SQL Server, increase the relevant connection-timeout parameter values and check whether the connection eventually succeeds.

What is default timeout in Entity Framework?

Entity Framework Core Queries/Commands The default time-out for an EF Core command is 30 seconds.


1 Answers

I had the same problem and another one also appeared later, not related to MSSQL. To solve first problem (running queries took too long), I changed command.CommandTimeout to use larger number (default is 30). Another problem that showed up was when I used scheduled task to run this application - after 20 minutes it would thrown error

"Thread was being aborted"

After reviewing log errors, it came out that application pool also has it's timeout, and default value is 20 minutes.

like image 188
ilija veselica Avatar answered Oct 12 '22 04:10

ilija veselica