rkm
rkm

Reputation: 13

"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?

Upvotes: 0

Views: 4260

Answers (2)

Arsen Khachaturyan
Arsen Khachaturyan

Reputation: 8330

In my case issue was connected with the stupid mistake: when copy/pasted connection string to Notepad++ I somehow missed that newline operator appeared because of the Notepad++ was wrapping the text or smth else.

In any case, I've copy/pasted to Notepad then replaced User ID and Password, then copy/pasted again to the server, Saved the settings then Restarted the server. Finally, issue fixed.

Upvotes: 0

Tom Sun
Tom Sun

Reputation: 24549

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.

Upvotes: 1

Related Questions