0

I am using .NET 6.0, in the project I have appsettings.json file with the following line:

"ConnectionStrings": {
        "SqlConnection": "Server=.\\SQLEXPRESS;Database=XXX;Trusted_Connection=True;MultipleActiveResultSets=true"
},

In Azure I have Connection Strings defined as follows:[enter image description here]1

When I check appsettings.json in xxx.scm.azurewebsites.net/wwwroot I can see that it still uses ConnectionStrings defined in my project's appsetting.json but not in the Azure one.

My Dbcontext:

services.AddDbContext<MyContext>(
            options => options.UseSqlServer(Configuration.GetConnectionString("SqlConnection")));

How I get to Azure overwrite my connection string and use it instead? Thanks.

Shukhrat Raimov
  • 2,137
  • 4
  • 21
  • 27

1 Answers1

1

The App Service will not change your appsettings.json file. It will inject any app settings (including Connection Strings) in addition to your appsettings.json file into your application (as ENV vars).

silent
  • 14,494
  • 4
  • 46
  • 86
  • thanks, and what has precedence? looks like appsettings.json is winning? – Shukhrat Raimov Dec 02 '22 at 15:25
  • 1
    @ShukhratRaimov https://devblogs.microsoft.com/premier-developer/order-of-precedence-when-configuring-asp-net-core/ – silent Dec 02 '22 at 16:07
  • thanks for the link! https://learn.microsoft.com/en-us/azure/app-service/tutorial-dotnetcore-sqldb-app says that I can use in my code Configuratoin.GetConnectionString(" – Shukhrat Raimov Dec 02 '22 at 16:11
  • I dont understand what you mean? The name of setting can be the same in different environments, just their values should be different. – silent Dec 02 '22 at 17:09