I'm using Npgsql with EF core to establish a connection to PostgreSQL for a demo console application. But I'm getting an exception 'Format of the initialization string does not conform to specification starting at index 0'. I think this because of some issue with the connectionstring. Any help is appreciated.
1 Answer
This should do fine:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql(@"Server=localhost;Port=5432;Database=dbname;User Id=Id;Password=password");
base.OnConfiguring(optionsBuilder);
}
2 Comments
hrust
Is there a link to the documentation?
Sam
I keep having problems connecting. I'm keep getting
Failed to connect to [::1]:5432. I tried to change to 127.0.0.1 and I am getting Failed to connect to 127.0.0.1:5432, but if I do psql -h 127.0.0.1 -p 5432 -U stellagunner -d MyTestDb it works fine.

