Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 31 2019 21:30
    roji commented #2307
  • Jan 31 2019 20:35
    YohDeadfall commented #2307
  • Jan 31 2019 10:20
    capan starred npgsql/npgsql
  • Jan 31 2019 06:10
    SeanFarrow synchronize #2308
  • Jan 30 2019 20:37
    austindrenski commented #2308
  • Jan 30 2019 20:37
    pentagra commented #1445
  • Jan 30 2019 20:33
    SeanFarrow commented #2308
  • Jan 30 2019 20:31
    austindrenski commented #2308
  • Jan 30 2019 20:27
    SeanFarrow commented #2308
  • Jan 30 2019 20:09
    austindrenski labeled #2308
  • Jan 30 2019 20:05
    roji commented #1520
  • Jan 30 2019 19:50
    gyzod commented #1445
  • Jan 30 2019 19:06
    SeanFarrow commented #1520
  • Jan 30 2019 18:54
    roji commented #1520
  • Jan 30 2019 18:53
    roji commented #1520
  • Jan 30 2019 18:52
    roji commented #2050
  • Jan 30 2019 18:45
    Trolldemorted commented #2050
  • Jan 30 2019 18:21
    SeanFarrow commented #1520
  • Jan 30 2019 18:16
    SeanFarrow review_requested #2308
  • Jan 30 2019 18:16
    SeanFarrow review_requested #2308
pm64
@pm64
It looks like PostgresException member "Statement" has been removed in 6.0. Is there a new way to access this info?
Shay Rojansky
@roji
Yeah, you can now use the new NpgsqlBatch to execute a batch (see the release notes - I still need to document this properly). Exceptions raised when executing an NpgsqlBatch reference the DbBatchCommand from NpgsqlException.DbBatchCommand.
pm64
@pm64
Thank you @roji, appreciate your guidance as always.
FerrariF70
@FerrariF70
Hello, what is the mean Npgsql.PostgresException (0x80004005): 28000: connection requires a valid client certificate. I deploy my app on linux and I get this exception when try retrieve data from database. But when I connect with that certificate to database from terminal with psql "..." this authentication is pass over. Where is the problem? please help me, any tips.
FerrariF70
@FerrariF70

Hello, what is the mean Npgsql.PostgresException (0x80004005): 28000: connection requires a valid client certificate. I deploy my app on linux and I get this exception when try retrieve data from database. But when I connect with that certificate to database from terminal with psql "..." this authentication is pass over. Where is the problem? please help me, any tips.

As I see from this npgsql/npgsql#1721, the problem has existed for a long time, that everything seems very strange, either they don’t know how to solve it or they don’t want to. @roji I want to hear what's going on about this problem?

Shay Rojansky
@roji
@FerrariF70 this is PostgreSQL telling you that it's configured to require client certificate authentication; that means you need to provide a certificate to Npgsql so that it can send it to PG as part of the authentication (see https://www.npgsql.org/doc/security.html#client-certificates)
On the command-line with psql, you're probably using a different connection method, and PG is configured for different authentication. For example, with psql you may not be using TCP/IP but rather Unix domain socket. IIRC using psql -h localhost should force TCP/IP, which should put psql in a similar situation as Npgsql
All the config around this is found in pg_hba.conf BTW.
In any case, certificate auth is fully supported by Npgsql - you just need to make sure you provide the right certificate etc.
FerrariF70
@FerrariF70
@roji Nice.Then Have event ProvideClientCertificatesCallback which recieve client certificate, now my question what is the exactly certificate I need to transfer in event ProvideClientCertificatesCallback? bundle certificates (client+root) or only client certificate? because this information is not listed anywhere and this confused. Thank you for your replies.
Peter
@AnderssonPeter
Hi I have a table with a column of type timestamp without time zone but when i try to store DateTime.Now in it, I get Cannot write DateTime with Kind=Local to PostgreSQL type 'timestamp with time zone' why does it give me a error for timestamp with time zone when I'm using without?
Shay Rojansky
@roji
@FerrariF70 I'm pretty sure that's going to depend on exactly how your environment is configured (e.g. root CAs etc.). If your client has a certificate from a root CA that's recognized by PG, then just providing that certificate should be fine. Basically the question isn't really specific to Npgsql at that point, but rather general to PostgreSQL.
@AnderssonPeter you've likely forgot to tell EF Core that the column is timestamp without time zone (remember that timestamp with time zone is the default for .NET DateTime!). See https://github.com/npgsql/efcore.pg/issues/2128#issuecomment-983404118 for more info, if that doesn't help please open an issue with a repro and I'll try to help.
spiral
@spiralw
hey, I updated to .NET 6 and Npgsql has been throwing a ton of System.TimeoutExceptions (NpgsqlException (0x80004005): Exception while connecting). I updated to Npgsql 6.0 and the errors changed to Npgsql.NpgsqlException (0x80004005): Exception while reading from stream. This starts happening at around 400 queries per second. how can I fix this?
Shay Rojansky
@roji
@spiralw it's not clear from your message - were you receiving the same number of exceptions before, but just as TimeoutExceptions? What exactly changed between 5.0 and 6.0? Can you submit a code sample?
Marcel Juen
@mjuen_gitlab
Hello, I got a question concerning the timestamp migration from 5.0 to 6.0. When using ALTER TABLE "Blogs" ALTER COLUMN "CreatedOn" TYPE timestamp with time zone; for the conversion, does this also consider summer/winter time for old timestamps?
Shay Rojansky
@roji
@mjuen_gitlab you probably want to read the migration guidelines in the 6.0 release notes: https://www.npgsql.org/doc/release-notes/6.0.html#migrating-columns-from-timestamp-to-timestamptz
If you just dod ALTER COLUMN ... TYPE as you wrote above, your timestamps will undergo conversion based on your TimeZone parameter (as defined in postgresql.conf) - this is frequently not what you want. If your timestamp without time zone column in fact already contains UTC timestamps, set TimeZone to UTC as explained in the link above.
Marcel Juen
@mjuen_gitlab
@roji Thanks for the answer!
akshayjoyinfo
@akshayjoyinfo
@roji I have been trying to resolve one issue with AZURE POSTGRES WITH ASP.NET CORE.
CONNECTIONS -100 TOTAL
I AM TRYING TO RUN READ QUERY for 50 k6 users parallel but npgsql ef core is able to ingest recot in parallel with npgsql connection, but with dapper Is connection with Transient dependency is failing for 10% requests
npgsql.npgsqlexception (0x80004005): exception while reading from stream ---> system.timeoutexception: too many requests
Ideal case everything working.. but 50 parallel users with ID connection dapper npqsql is failing
I am using 3.1.4
akshayjoyinfo
@akshayjoyinfo
Npgsql.NpgsqlException (0x80004005): Exception while reading from stream
---> System.TimeoutException: Timeout during reading attempt
at Npgsql.NpgsqlReadBuffer.<Ensure>gEnsureLong|40_0(NpgsqlReadBuffer buffer, Int32 count, Boolean async, Boolean readingNotifications)
at Npgsql.NpgsqlConnector.<ReadMessage>g
ReadMessageLong
akshayjoyinfo
@akshayjoyinfo
My query is quite huge that is essential, but this error only happens when you have do load testing with k6 , 50 users. This issue happens only when dapper with ISBCONNNECTION
jearmstrong
@jearmstrong
Hello, major newbie here, and I have a question that might show how deep my ignorance goes. Anyway, I don’t want to be long winded here, so my basic question is: Can a postgres table be edited through a connection with Excel? I suspect the answer is YES, and if confirmed I will provide more details of the situation I have. Thanks - james
Shay Rojansky
@roji
@akshayjoyinfo are you saying that the same scenario works well with EF Core, but fails with Dapper? That's sounds very odd. Make sure you haven't forgotten to close/dispose your NpgsqlConnection etc. Otherwise, there's generally not much I can help with for timeout/load exceptions - that's almost always a matter of your specific query, index usage, networking conditions, etc.
@jearmstrong yeah - you can install Npgsql at the Windows level, and then it appears as a "data source" inside Excel and can be accessed directly. Get the MSI installer for Npgsql 4.0.11 (https://github.com/npgsql/npgsql/releases?q=4.0.11&expanded=true) and make sure you check "GAC installation".
akshayjoyinfo
@akshayjoyinfo
@roji since I am using Transient IDbConnection there will be auto closing and opening connection, I have tried DBconnection Factory , but getting too many clients error
Shay Rojansky
@roji
@akshayjoyinfo you'd really need to show some minimal code samples - it's impossible to know exactly what's going on from the above. I'd suggest opening a question on stackoverflow with the tag "npgsql".
akshayjoyinfo
@akshayjoyinfo
Yeah I am creating one,
But what is the reason for this exception
Npgsql.NpgsqlException (0x80004005): Exception while reading from stream
---> System.TimeoutException: Timeout during reading attempt
at Npgsql.NpgsqlReadBuffer.<Ensure>gEnsureLong|40_0(NpgsqlReadBuffer buffer, Int32 count, Boolean async, Boolean readingNotifications)
at Npgsql.NpgsqlConnector.<ReadMessage>gReadMessageLong
While executing query
Shay Rojansky
@roji
@akshayjoyinfo the exception simply says there was a timeout while reading results from PostgreSQL. There could be many reasons for that - network outage, a very long query, an overloaded server... The exception itself can't provide enough information to know what the root cause is
Björn Harrtell
@bjornharrtell
Why is the usage example using await using in await using var conn = new NpgsqlConnection(connString);? I don't understand what await does in that context because construction cannot be async?
Brar Piening
@Brar
@bjornharrtell the using declaration is not about construction of objects but about their disposal. It basically tells the compiler to automatically call Dispose() on the object when it goes out of scope.
await using is the async counterpart of the using declaration that tells the compiler to call DisposeAsync() instead of Dispose(). See https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-disposeasync#using-async-disposable for more background.
Björn Harrtell
@bjornharrtell
@Brar: Ah, I was confused because I failed to note that it does implement both IDisposable and IAsyncDisposable.
JT Bruch
@JT-Bruch

I am feeling really stupid right now, but I don't understand why this doesn't work.

I have a POCO that looks like:

public class DbEquipmentFeature : EntityBase
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int DbId { get; set; }

        public Guid Id { get; set; } = Guid.NewGuid();

        public DbEquipment Equipment { get; set; }
        public Guid EquipmentId { get; set; }

        [Column(TypeName = "jsonb")]
        public SerializableMultiLangString Value { get; set; }

    }

and SerializableMultiLangString is

public class SerializableMultiLangString
    {
        public Translation[] Translations { get; set; }
}

and Translation is


    public class Translation
    {

        public Translation() { }

        public LanguageCode LanguageId { get; set; } = 0;
        public string LanguageShortCode => LanguageId.ToString();
        public string Text { get; set; }
        public string Description { get; set; }
    }

But I keep getting System.InvalidOperationException: The entity type 'SerializableMultiLangString' requires a primary key to be defined. If you intended to use a keyless entity type call 'HasNoKey()'.

Which doesn't make sense because its not its own entity?

That is the error i get on trying to create the context
Shay Rojansky
@roji
@JT-Bruch just copying and pasting the above into a sample file works - there's likely something else you're not showing. Always good to point to a full, runnable code sample rather than snippets...
Sajan
@woodsongem

Hey All,
We have a customer and county table. We added below config and Customer.CountryId is optional. we are able to populate CountryDetail if CountryId is not null and get below error if Customer.CountryId is null. How to fix this issue? . TIA.

builder.HasOne(x => x. CountryDetail).WithOne().HasForeignKey< Country >(x => x. Id).HasPrincipalKey<Customer>(z => z. CountryId);
public class Customer {
  public int Id {get;set;}
  public int? CountryId {get;set;}
  public Country? CountryDetail {get;set;}
}
public class Country
{
 public int CountryId {get;set;}
 public string name  {get;set;}
}

Error:

System.InvalidCastException: Column 'CountryId is null.
   at Npgsql.ThrowHelper.ThrowInvalidCastException_NoValue(FieldDescription field)
   at Npgsql.NpgsqlDataReader.GetFieldValue[T](Int32 ordinal)
   at Npgsql.NpgsqlDataReader.GetInt32(Int32 ordinal)
  at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.BufferedDataRecord.ReadInt(DbDataReader reader, Int32 ordinal, ReaderColumn column)
   at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.BufferedDataRecord.ReadRow()
   at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.BufferedDataRecord.InitializeAsync(DbDataReader reader, IReadOnlyList`1 columns, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.InitializeAsync(IReadOnlyList`1 columns, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.BufferedDataReader.InitializeAsync(IReadOnlyList`1 columns, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
Shay Rojansky
@roji
Looks like you have a null value in the CountryIt column in the database? You're telling EF Core that this isn't possible (that property is a non-nullable int)...
(note that EF Core doesn't support nulls in primary keys)
Matthijs ter Woord
@mterwoord:matrix.org
[m]
Hi all! I recently upgraded a project to .net 6, entity framework core 6 and npgsql 6, and now I have to specify datetimekind everywhere (or resort to the legacy behavior)
Is theer an easy way to have my api assume all dates are in fact utc?
Shay Rojansky
@roji
@mterwoord:matrix.org the question is more why you have DateTimes with non-UTC Kinds in your application, when in fact you want them to mean UTC... For example, maybe you're using DateTime.Now when you should be using DateTime.UtcNow?
Regardless of Npgsql, it's important for the DateTime's Kind to correspond to what's actually being represented
Matthijs ter Woord
@mterwoord:matrix.org
[m]
stuff coming from api's
my api+server side is purely utc