How to fix " The ConnectionString property has not been initialized." in .Net api
Hello world!
I'm developing a .Net api using Docker containers, but at the moment to ask a GET request in swagger, it throws back " The ConnectionString property has not been initialized." which has to do with a database failure.
If Anyone could bring me some help, I'd be really grateful.





6 Replies
Try this:
builder.Configuration.GetConnectionString("DefaultConnection")
I already tried, and it didn't workout as expected.
Some points that I noticed in the provided screenshots:
1. If the database is on your local machine then Host will be localhost in the connection string.
2. I can't see OnConfiguring method in your Context file
No, I'm using GitHub Codespaces which is a online ide. Should I set the string config in db context rather than Program.cs alone. I didnt use OnConfiguring method because I though setting the Postgres connection string in Program.cs was enough.
@GABRIEL22 Maybe that your ConnectionString is inside the logging brackets in the json file? Try to put it outside the logging
Yes I think that's the issue.