简体   繁体   English

仅在主页命中时触发连接池-ASP.NET MVC5实体框架

[英]Connection Pooling only triggered on home page hit - ASP.NET MVC5 Entity Framework

I really feel silly asking this question but I can't seem to figure this out - even though it sounds trivial. 我问这个问题真的很傻,但是我似乎无法弄清楚-尽管听起来很琐碎。

The problem arises when my site goes idle and the connection pool is closed - if I try to access a page other than the homepage, I am receiving the YSOD stating 当我的网站闲置并且连接池关闭时,会出现问题-如果我尝试访问除主页以外的其他页面,我将收到YSOD声明

' A network-related or instance-specific error occurred while establishing a connection to SQL Server ' ' 建立与SQL Server的连接时发生与网络相关或特定于实例的错误 '

I tried to debug the controller action being called but it doesn't even get hit... and I have no idea where else I could place a break point to see what's trying to be called. 我试图调试被调用的控制器动作,但是它甚至没有被击中……而且我也不知道我还能在哪里放置一个断点来查看试图调用的东西。

I can see the connection dropping off with a sp_who and coming back up when the home page is hit. 我可以看到连接被sp_who断开,并且在单击主页时又恢复了连接。

I'm using ASP.NET MVC5 along with Entity Framework 6. I haven't specified any setting for connection pooling since it's on by default with EF. 我正在将ASP.NET MVC5与Entity Framework 6一起使用。我没有为连接池指定任何设置,因为默认情况下它在EF中处于启用状态。 I'm also wrapping all my DB contexts in using blocks. 我还将所有数据库上下文包装在使用块中。

Has anyone any idea what would cause this or even where to begin looking in regards to debugging this? 有谁知道导致调试的原因,甚至是从哪里开始调试的?

I think that forms authentication may be responsible for this - but then again, surely if that timed out I'd be redirected to the default Account/Login route that MVC5 sets you up with when beginning a new project. 我认为表单身份验证可能是造成这种情况的原因-但是再说一遍,如果超时,我肯定会重定向到MVC5在开始新项目时为您设置的默认帐户/登录路由。

UPDATE I was able to fix this by adding the the SimpleRoleProvider to the webconfig in: 更新我能够通过将SimpleRoleProvider添加到webconfig中来解决此问题:

    <roleManager enabled="true" defaultProvider="SimpleRoleProvider">
      <providers>
        <clear />
        <add name="SimpleRoleProvider" connectionStringName="DefaultConnection" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
     </providers>
   </roleManager>

Then I had to move: 然后我不得不移动:

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);

into my Global.cs so that it was the first thing called. 进入我的Global.cs,所以这是第一件事。

I was able to fix this by adding the the SimpleRoleProvider to the webconfig in: 我可以通过将SimpleRoleProvider添加到webconfig中来解决此问题:

<roleManager enabled="true" defaultProvider="SimpleRoleProvider">
  <providers>
    <clear />
    <add name="SimpleRoleProvider" connectionStringName="DefaultConnection" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
 </providers>
</roleManager>

Then I had to move: 然后我不得不移动:

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);

out of InitializeSimpleMembershipAttribute.cs into my Global.cs so that it was the first thing called. 从InitializeSimpleMembershipAttribute.cs移到我的Global.cs中,所以这是第一件事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET MVC5 和实体框架设计题 - ASP.NET MVC5 and Entity Framework design questions ASP.NET MVC5实体框架应用程序中的单个上下文 - Single Context in ASP.NET MVC5 Entity Framework application 使用实体框架和ASP.NET MVC5更新记录 - Update records using Entity Framework and ASP.NET MVC5 ASP.NET MVC5-(实体框架)LINQ查询联接&如果更改,则仅返回1个结果,而不返回其他结果 - ASP.NET MVC5 - (Entity Framework) LINQ Query Join & Where returning only 1 result but not other result if changed 如何在每个页面的第一点击上提高ASP.NET MVC5应用程序的性能? - How do I improve ASP.NET MVC5 application performance on each page's first hit? 没有实体框架数据库连接的ASP.NET MVC - ASP.NET MVC without Entity Framework database connection 我如何使用实体框架ASP.NET MVC5保存相关数据? - How do i save related data using entity framework asp.net mvc5? ASP.NET MVC5-如何强制实体框架忽略模型中的属性? - ASP.NET MVC5 - How to enforce Entity Framework to ignore properties in model? ASP.NET MVC5实体框架6 get bool = true和bool = false LINQ - ASP.NET MVC5 Entity Framework 6 get bool = true and bool = false LINQ 帐户的ASP.NET MVC5实体框架组字段(国家/地区) - ASP.NET MVC5 Entity Framework Group Fields (Country, State) for Account
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM