Having the same error as
And the SO answer says to call NpgsqlConnection.ReloadTypes()
.
While I don’t think in production we would be dropping schemas, it is a possibility especially early on in this new project and if it happens we don’t want the website going down until we restart the website.
How do you see us implementing a global catchall for that specific error to call NpgsqlConnection.ReloadTypes()
and then try again? Note: It’s a generic Npgsql.PostgresException
exception, so would need to check the error message text.
our AppHost Configure(Container container)
method for registering pgsql looks like:
container.Register<IDbConnectionFactory>(c =>
{
var connectionFactory = new OrmLiteConnectionFactory();
// NOTE: Don't use ConfigUtils, use AppSettings instead.
connectionFactory.RegisterConnection("mydb", new OrmLiteConnectionFactory(AppSettings.GetString("ConnectionStrings:mydb"), PostgreSqlDialect.Provider, true));
connectionFactory.RegisterConnection("mydb2", new OrmLiteConnectionFactory(AppSettings.GetString("ConnectionStrings:mydb2"), PostgreSqlDialect.Provider, true));
connectionFactory.RegisterConnection("mydb3", new OrmLiteConnectionFactory(AppSettings.GetString("ConnectionStrings:mydb3"), PostgreSqlDialect.Provider, true));
return connectionFactory;
}).ReusedWithin(ReuseScope.Request);
Also, is it still better to ReuseScope.Request
?
Here is the stack trace:
{Npgsql.PostgresException (0x80004005): XX000: cache lookup failed for type 54669
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 1219
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior) in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1130
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at ServiceStack.OrmLite.OrmLiteWriteCommandExtensions.Insert[T](IDbCommand dbCmd, T obj, Action`1 commandFilter, Boolean selectIdentity)
at ServiceStack.OrmLite.OrmLiteWriteApi.<>c__DisplayClass5_0`1.<Insert>b__0(IDbCommand dbCmd)
at ServiceStack.OrmLite.OrmLiteExecFilter.Exec[T](IDbConnection dbConn, Func`2 filter)
at MyApp.MyService.Any(MyPageDto request) in C:\...\MyService.cs:line 38}