ASP.NET Core MVC webapp error after Azure deployment

I wrote an app in ASP.NET Core MVC with CRUD to deploy to Azure, using code first. I followed this tutorial:

The tutorial is slightly out of date, but I am confident that I followed it properly. I also attempted to literally follow the tutorial with the sample app, and I got the same problem. I can provide an image, but the error page isn’t very descriptive. It says:

Error: an error occurred while processing your request.
Request ID: |bac57a49-4ca7848aebbdb3cb.

Development Mode
Swapping to Development environment will display more detailed information about the error that occurred.

The Development environment shouldn’t be enabled for deployed applications. It can result in displaying sensitive information from exceptions to end users. For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development and restarting the app.

To be blunt, I have no idea on how to proceed. I feel like there is a problem with the connection string, because the site works except when you hit a page that accesses the database. In the appsettings.json file, the only connection string available is the following:

"ConnectionStrings": {
    "PostContext": "Server=(localdb)\mssqllocaldb;Database=PostContext-1;Trusted_Connection=True;MultipleActiveResultSets=true"

I wasn’t necessarily expecting VS2019 to add a connection string on it’s own, but this wasn’t a step in the tutorial, so I didn’t touch it myself.

I have also noticed that there are a few questions that seem related, but there also doesn’t seem to be a clear answer. There was a solution from 2018, this, that referenced a hosting model issue, but that was over 2 years ago.

Any help or direction would be appreciated.

EDIT: I used the application logging system in azure. this is the response:

2020-09-11 22:57:18.620 +00:00 [Error]
Microsoft.EntityFrameworkCore.Database.Command: Failed executing DbCommand (5ms)
[Parameters=[], CommandType=’Text’, CommandTimeout=’30’]
SELECT [p].[Two], [p].[OneAgent], [p].[OneDate], [p].[OnePartyId], [p].[OneStage], [p].[OneTitle]FROM [PostOnes] AS [p]

and another error:

2020-09-11 22:57:18.644 +00:00 [Error] Microsoft.EntityFrameworkCore.Query:
An exception occurred while iterating over the results of a query for context type ‘RyneAura.Data.PostContext’.Microsoft.Data.SqlClient.SqlException
(0x80131904): Invalid object name ‘PostOnes’.at
Microsoft.Data.SqlClient.SqlCommand.<>c. […]

I’m not sure what they mean.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I think the cause of this problem is the wrong connection string.

You can refer to my answer in this post. This is the answer I posted in May, but the official document may be migrated. You can download the sample code in the document you are looking at, and try it out according to my suggestions. It will definitely help you solve the problem.

Troubleshooting database connection errors:

  1. If you are using azure sql server, please check the firewall settings in the portal (usually used for local debugging and restrictions on special network segments).
  2. Check whether the database name is consistent, whether the database table structure, stored procedures, functions, etc. are consistent with the test environment.
  3. The connection string format of azure sql server is as follows:
    Data,1433;Initial Catalog=db;
    Persist Security Info=False;
    User ID=user;Password=mypassword;
    Connection Timeout=30;
  4. The configuration in the portal is higher than the configuration in the web.config, you can check my answer for details.

Method 2

The error is caused as a result of a wrong connection string. If you are deploying to Azure App Service, then you will need to have a connection string that looks like this;

User ID=[LoginForDb]@[serverName];Password=myPassword;Trusted_Connection=False;

Please follow The Official Documentation
This will guide you through the troubleshooting process

Method 3

I have a solution to my problem. I have to manually check the box to fire off the migrations on publish.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x