C
C#5mo ago
GABRIEL22

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.
No description
This is the  database setup in docker-compose file
This is the connection string in AppSettings.cs
This is the the dbcontext injection in program.cs
And fanally, the DbContext with model builder.
6 Replies
kermit
kermit5mo ago
Try this: builder.Configuration.GetConnectionString("DefaultConnection")
GABRIEL22
GABRIEL225mo ago
I already tried, and it didn't workout as expected.
kermit
kermit5mo ago
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
GABRIEL22
GABRIEL225mo ago
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.
Mursel
Mursel5mo ago
@GABRIEL22 Maybe that your ConnectionString is inside the logging brackets in the json file? Try to put it outside the logging
kermit
kermit5mo ago
Yes I think that's the issue.
Want results from more Discord servers?
Add your server
More Posts
Any WinForms gods here? Having issues with the Editor AttributeI am encountering an issue with a software project restructuring. Initially, my solution combined seUnable to set property 'onsubmit' on object of typeHi everyone! I created a simple login page but it throws me an exception: ``` InvalidOperationExcepScaffold Not Working because `dotnet-aspnet-codegenerator.exe` uses old C# versionI need help with scaffolding identity my C# project, I get this error whenever I scaffold `` D:\PrRead stream twice without missing dataI want to grab the first byte from a file and then read the entire file (max. 128 bytes) starting frSystem.UriFormatException: 'Invalid URI: The hostname could not be parsed.'``` using RabbitMQ.Client; using System; namespace RabbitMQ.Implementations { public abstract cBlazor Wasm with blazor server or APII'm new to blazor and want to work with it. But i have a question about blazor. i see alot of tutoriSwitching between two Blazor ServerSide apps.I have two Blazor apps. I want to switch between them smoothly. Using NavigationManager results in aWorking with platforms on MAUIGreetings! Are there any options on how to make XAML adaptive for desktop and mobile applications? AHow to design a C# SDKHello, I would like to ask you, what is the best approach to create an SDK written in C#? I mean: Help for Creating a Maui Application with Asp.net API and SQL Server Database IntegrationI've been exploring the process of developing a Maui application integrated with its own API (Asp.ne