NpgsqlException : "Unknown message code: 74" on dotnet ef database update

-1

When I tried to update(build tables from Models) the PostgreSQL database for the first time I caught this exception:

dotnet ef database update

Npgsql.NpgsqlException (0x80004005): Unknown message code: 74 at Npgsql.Util.PGUtil.ValidateBackendMessageCode(BackendMessageCode code) in C:\projects\npgsql\src\Npgsql\Util\PGUtil.cs:line 63 at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<g__ReadMessageLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 894 --- End of stack trace from previous location where exception was thrown --- at Npgsql.NpgsqlConnector.Authenticate(String username, NpgsqlTimeout timeout, Boolean async) in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.Auth.cs:line 22 at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken) in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 393 at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<g__OpenLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnection.cs:line 241 --- End of stack trace from previous location where exception was thrown --- at Npgsql.NpgsqlConnection.Open() in C:\projects\npgsql\src\Npgsql\NpgsqlConnection.cs:line 119 at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists() at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists() at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) Unknown message code: 74

unfortunately, I couldn't find any clue about this exception, and as you see the exception is totally unclear.

c#
postgresql
.net-core
entity-framework-migrations
dotnet-cli
asked on Stack Overflow Jun 21, 2020 by Soren

1 Answer

0

After hours of investigation and reading similar errors and study the source code of the PGUtil.cs, I suspected to the communication problem.

And Bingo. the root of the problem was the wrong port number committed by my colleague.

public class IdentityResourceContextFactory : IDesignTimeDbContextFactory<IdentityResourceContext>
    {
        public IdentityResourceContext CreateDbContext(string[] args)
        {
            var optionsBuilder = new DbContextOptionsBuilder<IdentityResourceContext>();
            optionsBuilder.UseNpgsql("Username=postgres;Password=p@$$word;Host=localhost;Port=3306;Database=Identity;");

            return new IdentityResourceContext(optionsBuilder.Options);
        }
    }

When I changed the port number to the correct one everything goes well:

Username=postgres;Password=p@$$word;Host=localhost;Port=5432;Database=Identity;

I know it might be totally unrelated to the Exception message and because of that I share it here.

answered on Stack Overflow Jun 21, 2020 by Soren

User contributions licensed under CC BY-SA 3.0