ASP.NET Core MVC webapp error after Azure deployment

1

I wrote an app in ASP.NET Core MVC with CRUD to deploy to Azure, using code first. I followed this tutorial: https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-dotnet-sqldatabase

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.

c#
asp.net
asp.net-mvc
azure
asp.net-core
asked on Stack Overflow Sep 11, 2020 by Nick Fleetwood • edited Sep 12, 2020 by marc_s

2 Answers

0

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 Source=tcp:servername.database.windows.net,1433;Initial Catalog=db;
    Persist Security Info=False;
    User ID=user;Password=mypassword;
    MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;
    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.

answered on Stack Overflow Sep 14, 2020 by Jason Pan
0

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

https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-azure-webapp-using-vs?view=aspnetcore-3.1

answered on Stack Overflow Sep 18, 2020 by Nick Fleetwood • edited Oct 8, 2020 by Nick Fleetwood

User contributions licensed under CC BY-SA 3.0