-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConnectionString property has not been initialized - after first successful query #2576
Comments
I think this is the same as #2555. It seems to manifest in a couple of ways, all which boil down to the same underlying cause. Using the daily build fixes that for me anyways (while waiting for 7.0.1), you might want to try it. Though, I'm surprised you're not hitting #2557 as well. I wonder what the difference is. |
Good catch @pinkfloydx33, thanks! @milosa can you please try with the daily build patch version in #2555 and confirm whether that fixes the issue for you? |
One thing to note, I think you need to pull the construction of the data source/builder to outside the callback. Otherwise you are going to create a new builder and data source every time you request a context which I believe defeats the purpose. var dsBuilder = new NpgsqlDataSourceBuilder(builder.Configuration.GetConnectionString("PriceListDB"));
dsBuilder.MapEnum<PackagingAmountType>();
var dbDataSource = dsBuilder.Build();
builder.Services.AddDbContext<PriceListDbContext>(options =>
{
options.UseNpgsql(dbDataSource);
}); @roji Please correct me if I'm wrong here. Isn't the guidance one per-Application which the code in OP would be violating, or did I misunderstand a comment you made in gitter? |
That's correct... OnConfiguring is executed for every DbContext instance, so you should not be building a new data source in there; that effectively disables connection pooling altogether (since each data source corresponds to a pool). I should add a note to our docs around this. @pinkfloydx33 you may be interested in #2542. |
@pinkfloydx33 @roji I just tried, and can confirm the problem is solved in the daily build patch version. Thanks |
Duplicate of #2555 |
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 This is the swagger's error: This is the
This is the ConnectionString in` appSettings.json:
And finally this the dbContext injection in
I was expecting to make the basic Api operation(GET,POST,PUT,DELETE) into database, but it clearly seems that database is not well configured nor settled. |
same.. i am running several dotnetcore services in docker and access them from host.. got this "The ConnectionString property has not been initialized." error. have you solved it ? by the way, I am connecting to remote database |
I'm using efcore 7, dotnet 7, NpgsqlEntityFrameworkCore.Postgresql 7.0.0
I have a simple test application, generating an API response with data from postgresql.
When I make the first request to this API, i get the correct data from my database.
But after the first response (i.e. when i refresh the API page in my browser), i get this error (first 3 lines):
The first request gives me actual data from the database.
This project uses the API template from Visual Studio for Mac.
This is the
AddDbContext
part of my Program.cs:appsettings.json
Controllers/ProductController.cs
PriceListDBContext.cs
The text was updated successfully, but these errors were encountered: