thank you for the reply…
My problem is connection with crate db. just leave the other part.
Now i remove the RegisterFactory and using Npgsql;
Then i got an error
> Npgsql.NpgsqlException (0x80004005): Exception while reading from stream
> ---> System.TimeoutException: Timeout during reading attempt
> at Npgsql.NpgsqlReadBuffer.<Ensure>g__EnsureLong|40_0(NpgsqlReadBuffer buffer, Int32 count, Boolean async, Boolean readingNotifications)
> at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
> at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
> at Npgsql.ConnectorPool.OpenNewConnector(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
> at Npgsql.ConnectorPool.<>c__DisplayClass38_0.<<Rent>g__RentAsync|0>d.MoveNext()
> --- End of stack trace from previous location where exception was thrown ---
> at Npgsql.NpgsqlConnection.<>c__DisplayClass41_0.<<Open>g__OpenAsync|0>d.MoveNext()
> --- End of stack trace from previous location where exception was thrown ---
> at Npgsql.NpgsqlConnection.Open()
at Implementation/crateRepository.cs:line 15
My code is
using System;
using Npgsql;
namespace test
{
class Program
{
static void Main(string[] args)
{
string connString = "Host=localhost;Username=crate;SSL Mode=Prefer;Database=doc";
using (var conn = new NpgsqlConnection(connString))
{
conn.Open();
var tableName = "testtable";
var cmd = $"select timestamp as unixtime,reading from {tableName} where id=@s AND timestamp>=@st AND timestamp<=@et ORDER BY unixtime ASC";
using (NpgsqlCommand sqlCmd = new NpgsqlCommand(cmd, conn))
{
sqlCmd.Parameters.AddWithValue("s", "a");
sqlCmd.Parameters.AddWithValue("st", 1622716474405);
sqlCmd.Parameters.AddWithValue("et", 1622716474837);
using (var reader = sqlCmd.ExecuteReader())
{
while (reader.HasRows && reader.Read())
{
Console.WriteLine(reader["unixtime"]);
}
}
}
}
}
}
}
The error is:
error at conn.Open();