从池中获取连接之前,超时时间已经过去-Entity Framework [英] Timeout period elasped prior to obtaining a connection from the pool - Entity Framework

查看:47
本文介绍了从池中获取连接之前,超时时间已经过去-Entity Framework的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个部署在Azure应用程序服务上的ASP.NET MVC应用程序.我正在本地和使用IIS Express调试此应用程序.Windows 10系统上未安装IIS.

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)
{
   ...
}

连接字符串:

<add name = "localsqlserver" 
connectionString = "Data Source=xxx;Initial Catalog=xxx; Integrated 
Security=true;Max Pool Size=50000;" ProviderName = "System.Data.SqlClient"/>

我通常使用Windows身份验证登录数据库.我希望上面的连接字符串没有问题吗?

I normally login into database using Windows authentication.I hope the way I have above connection string should not be a problem?

注意:我已从Azure导出并在本地SQL Express 2019中导入的数据库.

Note: the database I have exported from Azure and imported in local SQL express 2019.

但是,出现此错误:

System.Data.EntityException:基础提供程序无法打开.

System.Data.EntityException: The underlying provider failed to open.

System.InvalidOperationException:超时已过期.从池中获取连接之前已经经过了超时时间.发生这种情况的原因可能是所有池化连接都在使用中,并且达到了最大池大小.

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步.

确保您可以使用 Windows身份验证通过 ssms 登录本地 sql服务器.

Make sure your can log in local sql server by ssms with Windows authentication.

第2步.

确保连接字符串正确.

您可以如下更改连接字符串.有关更多详细信息,您可以看到我在这篇文章中的答案.

You can change your connection string like below. For more details, you can see my answer in this post.

建议您使用SQL语句测试演示可以使用此.

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};" />

第3步.

通常来说,您提供的EF代码段不是很漂亮.也许只是由于示例代码,请检查本教程使用Visual Studio创建实体.您还可以根据文章中的链接下载演示,并尝试修改您的代码.

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.

当然,您也可以参考来创建它.使用Visual Studio进行创建可能更直观,方便,易学.

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.

这篇关于从池中获取连接之前,超时时间已经过去-Entity Framework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆