No password has been provided but the backend requires one (in MD5)

See original GitHub issue

Environment:

  • Npgsql 3.1.2.0
  • EntityFramework6.Npgsql 3.1.0

Code:

public void ExecuteQuery(string sqlQuery, Action<NpgsqlCommand> action)
{
            if (db.Database.Connection.State == ConnectionState.Open)
            {
                NpgsqlCommand command = new NpgsqlCommand(sqlQuery, (NpgsqlConnection)db.Database.Connection);

                action(command);
            }
            else
            {
                using (NpgsqlConnection conn = new NpgsqlConnection(db.Database.Connection.ConnectionString))
                {
                    conn.Open();

                    NpgsqlCommand command = new NpgsqlCommand(sqlQuery, conn);

                    action(command);

                    conn.Close();
                }
            }

 }

var sqlCommand = "SELECT [...]";

ExecuteQuery(sqlCommand, (command) =>
{
                var reader = command.ExecuteReader();

                while (reader.Read())
                {
                    id = reader[0] as long
                }
 });

Stacktrace:

 at Npgsql.NpgsqlConnector.ProcessAuthenticationMessage(String username, AuthenticationRequestMessage msg)

 at Npgsql.NpgsqlConnector.HandleAuthentication(String username, NpgsqlTimeout timeout)

 at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout)

 at Npgsql.ConnectorPool.Allocate(NpgsqlConnection conn, NpgsqlTimeout timeout)

 at Npgsql.NpgsqlConnection.OpenInternal()

 at Horus.Repositories.ContentBaseRepository.ExecuteQuery(String sqlQuery, Action`1 action)

Any ideas?

Thanks, Cristi

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
rojicommented, May 25, 2016

This is because of the Persist Security Info feature, which has been implemented in 3.1. Once a conneciton is open, getting its connection string will return it without a password. This is a security feature that allows you to pass around (open) NpgsqlConnection instances without having to worry about someone extracting the password from it.

The easiest way to work around this is simply to set Persist Security Info to true, which will make things work like in 3.0. Otherwise you need some external way to get the password, i.e. not from the connection.

1reaction
rojicommented, Nov 1, 2022

@OS-kostaskapasakis see the introductory text on the doc page linked above, to understand how connection strings work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Npgsql.NpgsqlException: 'No password has been provided
but I am getting an error in the constructor of controller class as Npgsql.NpgsqlException: 'No password has been provided but the backend ......
Read more >
Solved: postgresql : no password has been provided but the...
postgresql : no password has been provided but the backend requires one. ‎10-04-2021 08:12 AM. Hi,. when I get this error, I try...
Read more >
PostgreSql connectionstring
... No password has been provided but the backend requires one (in MD5) ... getting its connection string will return it without a...
Read more >
power bi Error: no password has been provided but
Hi When we refreshing the postgresql database in power bi. it is showing below error. can you please assist.
Read more >
Creating code first postgres database is failing: No password ...
Coding example for the question Creating code first postgres database is failing: No password has been provided but the backend requires one (in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found