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="Data Source=HERPADERP;Initial Catalog=MLIB;Integrated Security=True;MultipleActiveResultSets=True;Connect Timeout=200"" 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?
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.
Entity Framework Core Queries/Commands The default time-out for an EF Core command is 30 seconds.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With