Npgsql.PostgresException(0x80004005):XX000:删除架构时,类型207852的缓存查找失败

时间:2018-06-28 15:17:22

标签: postgresql f# npgsql postgresql-9.6

我,运行测试套件并尝试使用枚举:

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

但是,我遇到一个奇怪的错误:

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版本4.0.0


这是在我删除架构并重建它时发生的。如果我不重建它,它会工作。那么如何解决呢?

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

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

我没有使用重用连接来建立数据库并执行测试。

1 个答案:

答案 0 :(得分:6)

Npgsql首次连接到给定数据库时,会将所有PostgreSQL类型缓存(该类型缓存在连接字符串上)。如果您对类型进行了任何更改,例如定义一个新的或删除一个,则必须告诉Npgsql通过调用NpgsqlConnection.ReloadTypes()刷新类型缓存。