0

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")
june alex
  • 244
  • 4
  • 17
  • Have you tried providing the the ip port and database name to `CrateDbDatabaseInfoFactory`? https://www.npgsql.org/doc/api/Npgsql.NpgsqlDatabaseInfo.html Also is both python and .net running outside or inside another container? – A_kat Nov 25 '20 at 11:19
  • im running crate docker in my local machine – june alex Nov 26 '20 at 05:29

1 Answers1

3

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.

Sebastian Utz
  • 719
  • 3
  • 9
  • Additionally you need to change the port in your connection string to `var connString = "Host=localhost;Port=5432;Username=crate;SSL Mode=Prefer;Database=doc";` – Christian Dec 22 '20 at 07:41