#ASP.NET Core app with Azure DB works locally but not deployed

1 messages · Page 1 of 1 (latest)

safe temple
#

I've developed a very simple API application in ASP.NET Core with just three routes:

`app.MapGet("/", (AppDbContext db) =>
{
return $"Hello World";
});

app.MapGet("/api/tasks", (AppDbContext db) =>
{
return db.Tasks;
});

app.MapPost("/api/tasks", (TaskViewModel model, AppDbContext db) =>
{
Task task = model.MapTo();
db.Add(task);
db.SaveChanges();
return $"New task {task} created\n" + task;
});`

While running the application locally on my computer, everything works correctly. However, when I deploy the application to Azure as an App Service, only the route with "Hello World" works, and the others that access my database return a 500 Internal Server Error.

Here's what I've already checked:

  • The connection string to my database is correct.
  • I've enabled application logs on Azure, but they didn't provide any relevant information.

This is my first experience with Dotnet and Azure, so I'm quite inexperienced with these tools.

I appreciate any assistance in advance!

lean latch
#

Well the locally part is fine but when you take things remotely it makes it a different scenario

#

Not enough context here to work with

safe temple
#

Yeah, I know that. I could not provide more context because that's basically it.
However I figured out the problem, I only needed to enable the option on my Azure SQL Server that allows my resources to access it.

lean latch
#

Sweet its usually some sort of access on the network layer