A
A
Amin Madani2016-05-26 14:12:35
PostgreSQL
Amin Madani, 2016-05-26 14:12:35

How to connect to a database in PostgreSQL from a C# application?

In the application, I connect using the NPGSQL class
connectionStr = $"Server=localhost;Port=1488;User={LoginText.Text.Trim(' ')};Password={PasswordText.Text.Trim(' ')};Database=PrivateBD; ";
npgSqlConnection = new NpgsqlConnection(connectionStr);
try
{
npgSqlConnection.Open();
MessageBox.Show("Connected!", "Hurrah", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Then it gives an error that the base I specified in the line does not exist!
Severity: FATAL Code: 3D000
But the same line only with a database named postgres establishes a connection with a bang. What could be the problem? The error appears on any database created by me in pdAdmin!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
krypthon, 2016-05-26
@krypthon

Take out the connection string in the config file, also check the user in the specified database, it can help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question