从池中获取连接之前经过的超时时间 - 实体框架 [英] Timeout period elasped prior to obtaining a connection from the pool - Entity Framework

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

问题描述

我有一个部署在 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 步.

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

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语句来测试您的数据库是否可以正常使用.测试demo可以用这个.

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 创建实体.您也可以根据文章中的链接下载demo进行审核并尝试修改你的代码.

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.

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

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