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.
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:
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).
Check whether the database name is consistent, whether the database table structure, stored procedures, functions, etc. are consistent with the test environment.
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;
The configuration in the portal is higher than the configuration in the web.config
, you can check my answer for details.
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;
Server=tcp:[serverName].database.windows.net;Database=myDataBase;
User ID=[LoginForDb]@[serverName];Password=myPassword;Trusted_Connection=False;
Encrypt=True;
Please follow The Official Documentation This will guide you through the troubleshooting process
I have a solution to my problem. I have to manually check the box to fire off the migrations on publish.
User contributions licensed under CC BY-SA 3.0