How to connect crate database using .NET Npgsql client in docker environment

223 Views Asked by At

Im using .NET Npgsql client for crate database cratedb .Crate database is running as a docker, dcoker command is

sudo docker run -p "4200:4200"   crate

But when i connect database through Npgsql client there is no error shows but connection is not established

NpgsqlDatabaseInfo.RegisterFactory(new CrateDbDatabaseInfoFactory());
var connString = "Host=localhost;Port=4200;Username=crate;SSL Mode=Prefer;Database=doc";
await using var conn = new NpgsqlConnection(connString);
await conn.OpenAsync();

im running docker database in local machine.i can able to access the admin UI through http://localhost:4200/.Also crate database installed (using executable ) is connected the Npgsql client. Python client have no issue with connect the docker. I don't under the actual problem.

import requests
from crate import client
connection = client.connect("localhost:4200")
1

There are 1 best solutions below

1
On

By default CrateDB listen to PostgreSQL protocol compatible clients on port 5432, the port 4200 is listening to HTTP clients. See https://crate.io/docs/crate/reference/en/4.3/config/node.html#ports for further documentation.

So changing your docker command to

sudo docker run -p 5432:5432 crate

should solve this issue.