问题
I have an ASP.NET MVC application that is deployed on Azure app service. I'm debugging this application on my local and its using IIS express. No IIS installed on the Windows 10 system.
My code is written like this: The user login is getting validated like this
try
{
using(var context = new techEntities())
{
wtuser u = (from c in context.wtUsers
where c.email == email select c).FristOrDefault();
if(u == null)
{
return new userOT {error = "Invalid email or password"};
}
...
}
}
catch(exception ex)
{
...
}
Connection string:
<add name = "localsqlserver"
connectionString = "Data Source=xxx;Initial Catalog=xxx; Integrated
Security=true;Max Pool Size=50000;" ProviderName = "System.Data.SqlClient"/>
I normally login into database using Windows authentication.I hope the way I have above connection string should not be a problem?
Note: the database I have exported from Azure and imported in local SQL express 2019.
However, I get this error:
System.Data.EntityException: The underlying provider failed to open.
System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size is reached.
What could be the problem? How to fix this? Thanks
回答1:
Update
Step 1.
Make sure your can log in local sql server
by ssms
with Windows authentication
.
Step 2.
Make sure you connection strings is right.
You can change your connection string like below. For more details, you can see my answer in this post.
And it is recommended that you use the SQL statement to test whether you can use your database normally. Test demo can use this.
<add name="DefaultConnection" connectionString="Data Source =**;Initial Catalog = {your db in server not azure};User Id = {userid};Password ={password};" />
Step 3.
Generally speaking, the EF code snippets you provide are not very beautiful. Maybe just because of the sample code, please check this tutorial to create an Entity using Visual Studio. You can also download the demo according to the link in the article for review and try to modify your code.
Of course, you can also refer to the Code First tutorial to create it. Using Visual Studio to create may be more intuitive and convenient, easy to learn.
来源:https://stackoverflow.com/questions/63062815/timeout-period-elasped-prior-to-obtaining-a-connection-from-the-pool-entity-fr