Question

I'm trying to insert data into the following table using the Npgsql ADO.NET provider:

CREATE SCHEMA core;

CREATE TABLE core.config(
    name TEXT NOT NULL,
    value TEXT NOT NULL,
    CONSTRAINT pk_config PRIMARY KEY (name)
);

The first insert works fine but if I try to insert an item with the same name again, Npgsql just hangs. I would expect an exception to be thrown stating that the primary key constraint has been violated, but Npgsql just freezes instead. Sure enough, if I check the server logs I see this:

duplicate key value violates unique constraint "pk_config"

but this message doesn't seem to be getting back to Npgsql. Am I doing something wrong? My code is here:

using (NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;Database=temp;User Id=postgres;Password=test1"))
{
    conn.Open();
    string cmdText = "INSERT INTO core.config(name, value) values ('item', 'value')";
    using (NpgsqlCommand cmd = new NpgsqlCommand(cmdText, conn))
    {
        cmd.ExecuteNonQuery(); // This works fine
        cmd.ExecuteNonQuery(); // Insert again: this hangs, but would expect an exception
    }
}

This is a simplified version of a larger application (hence the use of a schema). I then tried creating the table in public (no schema specified). Interestingly this DOES generate an exception on the second call to ExecuteNonQuery():

Backend sent unrecognized response type

I'm a little lost as to whether this is a bug in Npgsql or whether it is something to do with Schema privileges (even though for this test I'm using the "postgres" superuser).

I'm using Npgsql 2.0.12.0

Was it helpful?

Solution

We have the same problem. According to this thread:

http://pgfoundry.org/forum/forum.php?set=custom&forum_id=518&style=nested&max_rows=50&submit=Change+View

We just noticed that Npgsql has a problem when handling error messages from postgresql 9.3.x.

Glen Parker already fixed in our latest code: https://github.com/npgsql/Npgsql/pull/99. We are working to create a new 2.0.12 stable release with this fix.

If you want to give it a try you can get the latest git code and check if it works ok for you. It is in beta state though.

Please, let me know if you have any problems with it.

So if you are using PostgreSQL 9.3, this may be your issue. You'll have to download the fix and experiment to see if this is actually your issue in this case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top