GetConnectionString() not working when migrated to 2.4.2
See original GitHub issueDescribe the bug
We have the below code in our application.
var mystring = Configuration.GetConnectionString("myKey");
Here Configuration is of type IConfiguration. But after migrating to Steeltoe 2.4.2 versions, it stopped working. Somehow GetConnectionString() is not able to get the values from PCF config server. Our Program.cs looks like below
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureAppConfiguration((hostContext, configApp) =>
{
configApp.AddCloudFoundry();
configApp.AddConfigServer();
})
.ConfigureLogging((builderContext, loggingBuilder) =>
{
// Add Serilog Dynamic Logger
loggingBuilder.ClearProviders();
loggingBuilder.AddSerilogDynamicConsole();
})
.AddCloudFoundryActuators(MediaTypeVersion.V2,
ActuatorContext.ActuatorAndCloudFoundry);
}
}
Steeltoe versions are given below
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="3.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.4" />
<PackageReference Include="Steeltoe.Management.CloudFoundryCore" Version="2.4.2" />
<PackageReference Include="Steeltoe.Extensions.Configuration.CloudFoundryCore" Version="2.4.2" />
<PackageReference Include="Steeltoe.Extensions.Configuration.ConfigServerCore" Version="2.4.2" />
</ItemGroup>
Expected behavior
Should be able to retrieve connection strings via IConfiguration.GetConnectionString().
Environment (please complete the following information):
- Platform: PCF
- .NET Version : .NET Core 2.2
- Steeltoe Version : 2.4.2
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
c# - Cannot resolve symbol GetConnectionstring
In .NET 6 you now use builder.Configuration.GetConnectionString like this builder.Services.AddDbContext<ApplicationDBContext>(options ...
Read more >Managing Connections | Couchbase Docs
This section describes how to connect the Java SDK to a Couchbase cluster.
Read more >The ConnectionString property has not been initialized. ...
This issue relates the above code. When use the GetConnectionString() method, it will look for a configuration value whose key is ...
Read more >Entity Framework Core MySQL | Documentation Center | ABP.IO
This will create a database migration with all database objects (tables) configured. Run the .DbMigrator project to create the database and seed the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey, sorry for the delay in getting back to you, I’ve been on vacation…
I was finally able to test this out, and this was fixed by #247
Yes. I am able to get other values from config server if I respect the case. E.g.
var myConstring = Configuration.Get("connectionstrings:myKey");
As per microsoft https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.1#keys, configuration keys are case insensitive. Looks like Steeltoe has broken this with v2.4.1+ onwards.