Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 704
Soren Avatar asked May 22 '26 08:05

Soren


1 Answers

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.

like image 111
Soren Avatar answered May 23 '26 20:05

Soren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!