I use Npgsql to deal with PostgreSQL using C#. In order to connect to the database I wrote:
NpgsqlConnection conn = new NpgsqlConnection(connstring);
conn.Open();
Open() is a void method. It doesn’t return any value indicating whether it connect to the database or not. I need to show the status connected or not connected in my client app. How to do that?
You can check value of
Stateproperty:Also event
StateChangeis available in version greater than 2.0 of this provider.