DEV Community

Gem Cloud
Gem Cloud

Posted on

Net Core postgreSQL connection string on windows 10

Prepare knowledge:

  • The file “pg_hba.conf” control whether password or not:

Image description

  • Find server port number at pgAdmin4:
    Image description

  • Restart PostgreSQL server:
    typing “services.msc” on Run and Enter key.

Image description

config password Steps:

  • find the file pg_hba.conf;
  • Back it up;
  • place the following line
local all all trust
Enter fullscreen mode Exit fullscreen mode
  • restart your PostgreSQL server

  • you can now connect as any user. Connect as the superuser postgres

>psql -p 5433 -U postgres
Enter fullscreen mode Exit fullscreen mode
  • Reset password ('replace my_user_name with postgres since you are resetting postgres user)
ALTER USER my_user_name with password 'my_secure_password';
ALTER USER postgres with password 'pass@2022';
Enter fullscreen mode Exit fullscreen mode
  • Restore the old pg_hba.conf as it is very dangerous to keep around

  • Restart the server, in order to run with the safe pg_hba.conf.

Result:
The ConnectionString is "Host=localhost;Port=5433;Username=postgres;Password=pass@2022;Database=dvdrental;";

Dos Commands:

>cd C:\Program Files\PostgreSQL\14\bin>
>psql -p 5433 -U postgres
postgres=# ALTER USER postgres with password 'pass@2022';
Enter fullscreen mode Exit fullscreen mode

It worked!
The end!

Top comments (0)