Connection string with dash (hyphen) don't work on Linux App Service

Dmitry Nechaev 20 Reputation points
2024-11-28T04:26:24.91+00:00

I have a Linux web app deployed as code

User's image

I used to define connection string with the name of the database. The one in use is with dash: myjax-integration. That connection string consistently returned as empty from configuration manager.

So after figuring the root cause (several hours of pain) I found that the problem is about dash in the name. At the same time, I have another Windows-based web app, where dash works just fine.

And it works on the local computer (Windows). The problem only happens on the cloud.

I created 2 connection strings for testing:

User's image

And log them on startup.

    var builder = WebApplication.CreateBuilder(args);
    builder.Configuration.AddEnvironmentVariables();
    .....
    var app = builder.Build();
    var logger = app.Services.GetRequiredService<ILogger<object>>();
    logger.LogInformation($"connection string myjax-integration:[{builder.Configuration.GetConnectionString("myjax-integration")}]");
    logger.LogInformation($"connection string myjax_integration:[{builder.Configuration.GetConnectionString("myjax_integration")}]");

And the one with the dash is consistently empty. User's image

I've tried changing the connection name to something else, but as long as there is a dash in it, that name doesn't return the connection string.

As far as I could find, this is nowhere documented. Is it a feature or a bug? If the latter, where is a good place to lodge a bug report?

Azure App Configuration
Azure App Configuration
An Azure service that provides hosted, universal storage for Azure app configurations.
240 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,092 questions
{count} votes

2 answers

Sort by: Most helpful
  1. TP 100.9K Reputation points
    2024-11-28T05:06:51.7133333+00:00

    Hi Dmitry,

    hyphen isn't valid for environment variable name in linux. I did quick test and if you manually include hyphen in connection string name (as in your screenshot) the hyphen is removed when the environment variable is injected into the worker. For example, myjax-integration is automatically changed to SQLCONNSTR_myjaxintegration for connection type SQLServer.

    I recommend that you use underscore character instead since that is consistent with what is permitted in application settings.

    Please click Accept Answer and upvote if the above was helpful.

    Thanks.

    -TP


  2. VenkateshDodda-MSFT 23,141 Reputation points Microsoft Employee
    2024-12-03T04:05:37.88+00:00

    @Dmitry Nechaev Thanks for your patience on this. I have checked with App Service Engineering team on this and sharing the below.

    Team has confirmed that for Linux app service in the connection string names it is not recommended to use `-` same applicable for app settings as well.

    I am working content author team internally to update this documentation accordingly.

    Hope this helps let me know if you have any further questions on this.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.