Troubleshooting Azure App Service Deployment Errors: “An Error Occurred While Starting the Application”

Tristan Holaday
5 min readMar 23, 2020

--

So you’ve got your app to a presentable state, or at least your API is working, and you decide to deploy it to Azure app services, cause why not. And low and behold the most rare of circumstances occurs, you have an error! Why did I even hope that this was going to go smoothly 🤦‍♂️ ?

This is what happened to me the other day — twice! So in the interest of sparing fellow developers of possible high blood pressure, I want to share what I learned about error logging in Azure App Services and also my embarrassing mistake.

Here’s what we’re going to learn:

  • 2 ways to enable error logging
  • 3 ways to find and view said error logs

***Note: my experience occurred while deploying an ASP.NET Core REST API from Visual Studio Community 2019.

Ok, I’m going to assume that you already have a basic understanding of how to deploy to Azure App Services. If not then you can check out this step by step tutorial I wrote right here:

Let’s start by checking things off the list:

  1. We have an azure account: check
  2. We created an app service and a hostingplan within a resource group: check
  3. We created a server and SQL database: check
  4. We connected our app service to our SQL database via the connection string: check
  5. We replaced the default placeholders for admin username / password in the connection string: check
  6. Our environment variables are correct: check

Result upon hitting the API URL?

What?!?! Ok, well what kind of error?…. Obviously something is wrong but there’s no way for us to know just by this message. So we’re going to have to enable some error logging.

***Note: there are a lot of great articles/stackoverflow answers that I gleaned this information from, along with just CAUTIOUSLY clicking on stuff (haha). However, it took a bit of piecing things together. So let’s save you some time and look at two ways you can output more helpful error logs.

Add Detailed Errors Variable

A super simple way to see something more helpful is by adding a ASPNETCORE_DETAILEDERRORS variable to the application settings and set the value to “true”.

I know the pic shows “false” but set it to “true”

Try hitting the URL again. Now this is what we get:

Ok, so there’s some kind of login failure. Let’s check the connection string. No, everything looks good. Hmmmm. We can go a step further by clicking on “Show raw exception details” farther down on the page.

Let me draw your attention towards the third line from the bottom where it says Error Number: 18456, State:1, Class:14. That combined with the top line System.Data.SqlClient.SqlException (0x80131904) gives us some actionable intelligence.

Pop that error into google and you’ll come across this beauty:

This microsoft article tells us what the state of the error specifically means. Unfortunately, a state of 1 tells you nothing further…😑 But the other states give more useful information. This is the point at which I spent several hours trying to figure out a way to see if there was any other bit of info I was missing. Eventually I gave up and decided to pick things up the next morning.

And this is where I embarrass myself! While messaging another developer about this, it occurred to me:

‘Hey, you know those curly braces that you placed your password in for the db connection string?’

“Yeah…what about ‘em?”

‘What if you don’t need those curly braces?’

…*blink*blink*….”What”

‘Yeah you should take those out newb’

…*deep sigh*…

And mystery solved folks. I don’t know why, but I just placed my password inside of the curly braces and didn’t even think about the fact that it’s reading the value as the password + those braces. Thank God the thought occurred to me before I wasted anymore time. Learning about the error logging, though, was certainly not a waste of time. So there’s the silver lining!

But wait…I told you I would show you another way to generate logs and two other ways to view them and so I will!

Edit the Web Config

You can find the “App Service Editor” under development tools in the left window pane of your app service.

>Click on it and hit go.

>Find your web.config file and where it says stdoutLogEnabled=”false”

>Change the value to “true”.

>Hit the run icon on the left side and another pane should open called “output”.

There we go, we can see the same error information as before.

You can also view the files, either from the detailed errors or changing the web.config approach, within visual studio community.

You’ll open your project. Find the cloud explorer and sign into your azure account, if you’re not already. From there you can move through the directories to find your log files.

I hope this helps propel you in the right direction if you’re running into similar troubles. I mentioned that I ran into another error. Thankfully the second one wasn’t a stupid oversight on my part. I’ve written an article on how to launch the app service in a debugging mode with breakpoints if you’re interested or in further need 😁.

Cheers!

--

--