Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

asp.net mvc - Timeout period elasped prior to obtaining a connection from the pool - Entity Framework

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Update

enter image description here

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...