2
votes

I successfully used npgsql (Npgsql.EntityFrameworkCore.PostgreSQL) to connect to PostgreSQL database. I have heard that same EF provider works well with CockroachDB. I am trying with it but need help to define connection string for CockroachDB. For PostgreSQL I have used following connection string:

optionsBuilder.UseNpgsql(@"Host=localhost;Database=<database>;Username=postgres;Password=<password>");

Does anybody know what should a connection string look like if I wish to connect it to CockroachDB?

1

1 Answers

1
votes

The connection string you mentioned is almost correct, you just need to add Port=26257 as CockroachDB runs on a dedicated port.

If the Cockroach nodes are running securely, you'll also need to specify the Security and Encryption parameters.

You can find sample code to use npgsql to talk to CockroachDB in the docs, including the important "retry logic" section.