0

Installed PostgreSQL Version 12.1 in Windows 10 (downloaded from this page)

But got two servers, as below:

(Why PostgreSQL 10 got installed?)

enter image description here

In a .NET C# project the below code auto connects to the database postgres under PostgreSQL 10:

string Server = "localhost";
string Port = "5432";
string Username = "postgres";
string Password = "123456";
string Database = "postgres";
string connString =
String.Format(
    "Server={0};Port={1};Username={2};Password={3};Database={4};SSLMode=Prefer",
    Server,
    Port,
    Username,
    Password,
    Database);
using (var sqlConnection = new NpgsqlConnection(connString))
{
    sqlConnection.Open(); // here opens database postgres under PostgreSQL 10
}

How to change the code to open database postgres from PostgreSQL 12 instead of PostgreSQL 10?

2
  • 3
    The database must already have been installed. During installation of v12 you must have specified (or accepted) a port. Use that port instead of 5432. Commented Feb 2, 2020 at 23:39
  • Awesome, after changing to v12's port it works, thanks Laurenz Commented Feb 2, 2020 at 23:51

1 Answer 1

1

Multiple instances on the sames box would run on different ports simultaneously. There is no possibility of running 2 pg instances on the same port at the same time so its the port you need to connect with to pg12.

As far as pg10 is concerned it must have been there before! Which explains why your app connects to it by default as the default port for pg is 5432.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.