Page 1 of 1

Test if Database exists

Posted: Wed 11 Apr 2012 12:59
by CNPSV
Hello. I am trying to test if a database exists using this code:

Code: Select all

  PgSqlConnection conn = new PgSqlConnection();
            conn.Host = "localhost";
            conn.UserId = "postgres";
            conn.Password = "postgres";
            conn.Database = "x";
            conn.Open();
The database "x" does not exist.

I am getting an error: "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host." instead of "database "x" does not exist". Any ideea how to fix it?

Ps. In PgAdmin, server status I am receiving: database "x" does not exist

Using. VS. 2010, C#, Windows 7 x64, the project is set to x86, 5.80.332.0

Posted: Thu 12 Apr 2012 11:49
by Pinturiccio
dotConnect for PostgreSQL shows the full exception text, it gets from the server. It is likely that pgAdmin cuts this message. We suppose that displaying the full error message is better than displaying a short error message.

Posted: Thu 12 Apr 2012 11:55
by CNPSV
I understand, but the problem is that there is nothing in the error message that indicates the database does not exist.

Posted: Thu 12 Apr 2012 12:06
by CNPSV
This is what I get: {Error: 08006: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.}

Posted: Thu 12 Apr 2012 12:17
by CNPSV
I forgot to mention. I am using postgresql-9.1.3-1-windows-x64

Posted: Thu 12 Apr 2012 12:28
by Pinturiccio
We will investigate the possibility to change the exception message and notify you as soon as possible.

Workaround 1

Posted: Thu 19 Apr 2012 09:54
by CNPSV
Hello. I've found this workaround. Add

Code: Select all

conn.ConnectionString += "Protocol = Ver20;";
to the connection string, but I am still hoping for an update.

Posted: Fri 20 Apr 2012 09:05
by Pinturiccio
We have changed the behaviour: the exception message when connecting to a non-existing database is 'database "..." does not exist' now. We will post here when the corresponding build of dotConnect for PostgreSQL is available for download.

Posted: Fri 20 Apr 2012 09:24
by CNPSV
Thanks

Posted: Fri 27 Apr 2012 05:20
by Pinturiccio
The new build of dotConnect for PostgreSQL 5.80.350 is available for download now!
It can be downloaded from http://www.devart.com/dotconnect/postgr ... nload.html (trial version) or from Registered Users' Area (for users with valid subscription only).
For more information, please refer to http://www.devart.com/forums/viewtopic.php?t=23998

Posted: Fri 27 Apr 2012 08:59
by CNPSV
It works. Thanks.
Have a nice day.