New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A failing command completely replaces all prepared statements #2178

NekoKoneko opened this Issue Oct 2, 2018 · 2 comments


None yet
3 participants

NekoKoneko commented Oct 2, 2018

Calling a failing command multiple times completely replaces all other prepared statements.

Steps to reproduce

var csb = new NpgsqlConnectionStringBuilder
    Host = "...",
    Username = "...",
    Password = "...",
    Database = "...",
    AutoPrepareMinUsages = 2,
    MaxAutoPrepare = 2
using (var conn = new NpgsqlConnection(csb.ConnectionString))
using (var cmd = new NpgsqlCommand())
    cmd.Connection = conn;

    cmd.CommandText = "SELECT 1";
    Debug.Assert(cmd.IsPrepared); // As expected

    // Now executing a faulty command multiple times
    cmd.CommandText = "SELECT * FROM public.dummy_table_name";
    for (var i = 0; i < 3; ++i)
            // If running in Debug mode, an assertion is raised on the third step in the PreparedStatementManager.cs:212 and PreparedStatement.cs:85
        catch { }

    // Should be prepared
    cmd.CommandText = "SELECT 1";
    Debug.Assert(cmd.IsPrepared); // An assertion is raised

Further technical details

Npgsql version: 4.0.3
PostgreSQL version: 10.5
Operating system: Ubuntu 18.04.1 LTS


This comment has been minimized.


roji commented Oct 2, 2018

It will probably take me at least a couple weeks to get around to this, but I'll definitely investigate.


This comment has been minimized.


JustBSka commented Oct 9, 2018

Tried fixing this one, skipping redundant adding to _autoPrepared in PreparedStatementManager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment