Creating code first postgres database is failing: No password has been provided but the backend requires one (in MD5)


I'm building a .NET API and am stuck trying to create a postgres database using EFCore and Npgsql.

Targeted frameworks:
.Net Core 3.1
EFCore 3.1.4
Npgsql 3.1.3

I have created the initial migration but then running dotnet ef database update gives me this error:

Npgsql.NpgsqlException (0x80004005): No password has been provided but the backend requires one (in MD5)
   at Npgsql.NpgsqlConnector.AuthenticateMD5(String username, Byte[] salt, Boolean async)
   at Npgsql.NpgsqlConnector.Authenticate(String username, NpgsqlTimeout timeout, Boolean async)
   at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<<Open>g__OpenLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlConnection.Open()
   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)

I've found a number of other people with the same error but none of the suggested solutions have worked for me, the most common one saying that I need to add Persist Security Info=true; to my connection string as it's a security feature new to .NET Core 3.1.

My current connection string is:

"ConnectionStrings": {
    "(default)": "Server=localhost; Port=5432; Database=xxxxx; Persist Security Info=true; Pooling=true; CommandTimeout=60;"

I've also tried adding Password=xxxxx; to the connection string as well since that has been suggested.

Can anyone help?

asked on Stack Overflow Jun 1, 2020 by Kurt Lim

1 Answer

        private static string Host = "";
        private static string User = "mylogin@mydemoserver";
        private static string DBname = "mypgsqldb";
        private static string Password = "<server_admin_password>";
        private static string Port = "5432";

        static void Main(string[] args)
            // Build connection string using parameters from portal
            string connString =
answered on Stack Overflow Jun 1, 2020 by Siloen

User contributions licensed under CC BY-SA 3.0