I use Entity Framework in a Blazor Server App to access data in an SQL Server database. The app runs fine in the IDE against the SQL Server database, but when I deploy to a test web server running IIS 10, it works until it pulls data from the database at which point it reports 'Service Unavailable' in the browser and I find errors in the Event Log on the server that say:
An ISAPI reported an unhealthy condition to its worker process. Therefore, the worker process with process id of '10940' serving application pool 'DefaultAppPool' has requested a recycle.
I have inspected the Event Log for the WAS type events, and nothing stands out as relevant. No errors that describe a cause are visible.
This is what I see in the browser after the process terminates:
I cannot find a cause that leads to a solution. I can break at the point where it will trigger this, and if I skip all subsequent code the web server will stay up.
These two lines can execute, and if I return from the second line it will result in termination:
Account? account = _accountManagerService.GetAccount(Account);
AspnetUser? user = _accountManagerService.GetUser(Account);
In those methods, the DB is accessed using lines like this:
account = context.Accounts.SingleOrDefault(c => c.AccountName.Equals(accountID));
If I skip the calls to the DBContext, the app will survive. If I make enough calls - not many, on the order of 2 to 5 or so - eventually the app will terminate after it returns from the code.
These calls do work and do return valid data, in fact, the entire process has run and returned the proper data, but once it is complete, the process terminates for no visible reason.
Why does this happen when I pull data from the SQL Server, and how do I resolve it? I have searched Google for more than a day now with nothing that resolves this. I have scoured the Event Logs to no avail. I have gathered Logs but nothing jumps out.
If I access data through one of the EF entities, that will lead to this condition. If I do not access the data, the site remains active.
It works on the development web server, but not when deployed to an actual web server.
What am I missing here, and what do I need to do to determine the root cause and thus hopefully a solution?
I have reviewed Logs, watched the code execute, searched google, fiddled with the Application Pool settings, reduced the amount of data pulled by the data context and pretty much everything I can think of.
I also tested against a totally separate SQL server instance with no change in behavior of the Webserver. I use SQL Server Authentication and have toggled 'Integrated Security' on and off with no change.