[英]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.