Retrieve the connection string of an SQL Azure database that is linked to a Windows Azure Web Site with C#.NET

Viewed 3384

The configuration page of a Windows Azure Web Site has a "connection strings" section. The section lists connection strings for linked resources. How do we programmatically retrieve the connection string for a linked SQL Azure Database?

2 Answers

Getting the connection string as an environmental variable this way would seem to be the wrong way. You would define it under the connection string and then just call GetConnectionString from the IConfiguration interface, without making it more complex and prefixing with database strings.

Try the below this makes it much simpler

IConfiguration config = new ConfigurationBuilder()
    .AddEnvironmentVariables()
    .Build();

var connection = _config.GetConnectionString("DatabaseConnection");
Related