Npgsql.PostgresException (0x80004005): XX000: cache lookup failed for type 207852 when schema dropped

3

I', runining my test suite and try to use enums:

CREATE TYPE dockind AS ENUM ('I', 'O', 'Q');
CREATE TABLE document (
    doc_id       SERIAL,
    doc_kind     dockind NOT NULL DEFAULT 'O',
)

let openConn() =
    let conStr = localConnectionString()
    let conn = new NpgsqlConnection(conStr)
    conn.Open()


    conn :> IDbConnection
//Called after the schema is created
let initDb (conn:IDbConnection) =
    let db = conn :?> NpgsqlConnection
    db.TypeMapper.MapEnum<DocKind>("dockind") |> ignore

However, I'm getting a odd error:

Npgsql.PostgresException (0x80004005): XX000: cache lookup failed for type 207852
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 1032
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming) in C:\projects\npgsql\src\Npgsql\NpgsqlDataReader.cs:line 444
   at Npgsql.NpgsqlDataReader.NextResult() in C:\projects\npgsql\src\Npgsql\NpgsqlDataReader.cs:line 332
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken) in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1221
   at Npgsql.NpgsqlCommand.ExecuteScalar(Boolean async, CancellationToken cancellationToken) in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1086
   at Npgsql.NpgsqlCommand.ExecuteScalar() in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1063
   at CoreLib.Db.queryScalar[a,b](a con, String sql, IEnumerable`1 parameters) in /Users/mamcx/Proyectos/BestSellerPOS/CoreLib/DbStore.fs:line 184

Npgsql version 4.0.0


This happened when I drop the schema and rebuild it. If I don't rebuild this, it work. So how workaround this?

let createDb() =
    use con = openConn()
    let sql = openDbFile()
    exeSql con sql |> ignore

let testDb() =
    DbServer.createDb()
    let db = DbServer.openConn()
    DbServer.initDb(db)

I'm not using the reusing the connection for build the db and execute the tests.

postgresql
f#
npgsql
postgresql-9.6
asked on Stack Overflow Jun 28, 2018 by mamcx

1 Answer

6

Npgsql caches all the PostgreSQL types in a given database when it first connects to it (the types are cached on the connection string). If you make any changes to types such as defining a new one or dropping one, you must tell Npgsql to flush the type cache by calling NpgsqlConnection.ReloadTypes().

answered on Stack Overflow Jun 28, 2018 by Shay Rojansky

User contributions licensed under CC BY-SA 3.0