Search code examples
c#azureweb-configenvironment-variablesazure-application-settings

"Keyword not Supported" Error message while fetching connection string from azure application setting using environment variable


I am trying to get the connection string from Azure Application settings using environment variables, But it seems that the format of the connection string that I am putting in Azure App setting is not proper.Here is my original connection string that works fine in localhost.

    <add connectionString="Server=tcp:****.database.windows.net,1433;Initial Catalog=***;
Persist Security Info=False;User ID=******;Password=*********;MultipleActiveResultSets=False;
    Encrypt=True;TrustServerCertificate=False;Connection Timeout=1200000;
    Max Pool Size=500;Pooling=true;" name="Con_String"></add>

I am putting "Server=tcp:****.database.windows.net,1433;Initial Catalog=****;Persist Security Info=False;User ID=****;Password=****;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=1200000;Max Pool Size=500;Pooling=true;"as the con_string value in Azure Application Setting

Now for fetching the Connection string at runtime I am using Environment variable as string ConnectionString = Environment.GetEnvironmentVariable("SQLAZURECONNSTR_Con_String");

But during running the web app I am getting the exception message Keyword not supported: '"Server'.

I tried the approaches in Retrieve and use Windows Azure's connection strings? and other similar posts ,but didn't work. Am I missing something silly here?


Solution

  • Am I missing something silly here?

    If you still get the Keyword not supported: '"Server' or The ConnectionString property has not been initialized.

    I assume that you don't save the appsetting after you add the connection string the WebApp appseting.

    enter image description here

    The following code are both working on my side.

    ConnectionString = ConfigurationManager.ConnectionStrings["Con_String"].Connec‌​tionString.
    
    ConnectionString = Environment.GetEnvironmentVariable("SQLAZURECONNSTR_Con_Stri‌​ng")
    

    Test Result:

    enter image description here

    Note: as GauravMantri mentioned that there is no need quotes (") in the connection string in the Azure WebApp appsetting.