简体   繁体   中英

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

' A network-related or instance-specific error occurred while establishing a connection to 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.

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

UPDATE I was able to fix this by adding the the SimpleRoleProvider to the webconfig in:

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

I was able to fix this by adding the the SimpleRoleProvider to the webconfig in:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM