C
C#2y ago
khamas

❔ postgres EF core, how to have a custom connection string config file

Hey, I have a net6 class library with a DbContext, I want to have the connection string in a separate custom config file, code below. For some reason, when I do dotnet ef database update, an error pops up:
System.ArgumentException: Couldn't set min pool size (Parameter 'min pool size')
---> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. *...*

Couldn't set min pool size (Parameter 'min pool size')
System.ArgumentException: Couldn't set min pool size (Parameter 'min pool size')
---> System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. *...*

Couldn't set min pool size (Parameter 'min pool size')
My connection string looks like this: User ID=postgres;Password=<PASSWORD>;Host=localhost;Port=5432;Database=NetSendHost;Pooling=true;Min Pool Size=0;Max Pool Size=250;Connection Lifetime=0;
public class Db : DbContext
{
private static readonly string ConnectionString;
static Db()
{
var obj = JsonDocument.Parse(File.ReadAllText("Config/config.json"));
ConnectionString = obj.RootElement.GetProperty("PgSqlConnectionString").GetString();
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql(ConnectionString);
}
public DbSet<PrivateServerUser> ServerUsers { get; set; }

}
public class Db : DbContext
{
private static readonly string ConnectionString;
static Db()
{
var obj = JsonDocument.Parse(File.ReadAllText("Config/config.json"));
ConnectionString = obj.RootElement.GetProperty("PgSqlConnectionString").GetString();
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql(ConnectionString);
}
public DbSet<PrivateServerUser> ServerUsers { get; set; }

}
9 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
khamas
khamas2y ago
no it's a class library, and I also want the file containing the connection string to be separate lemme try same error when I put the raw string in the options @Deleted User
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
khamas
khamas2y ago
could you tell me what is wrong with this one if you know postgres? User ID=postgres;Password=<PASSWORD>;Host=localhost;Port=5432;Database=NetSendHost;Pooling=true;Min Pool Size=0;Max Pool Size=250;Connection Lifetime=0;
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
khamas
khamas2y ago
Ok
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
khamas
khamas2y ago
yeah constr was crooked thanks
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts