2

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.

Exceptionenter image description here

enter image description here

1 Answer 1

6

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);
    }
Sign up to request clarification or add additional context in comments.

2 Comments

Is there a link to the documentation?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.