Test if Database exists

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
CNPSV
Posts: 27
Joined: Thu 01 Nov 2007 09:48

Test if Database exists

Post by CNPSV » Wed 11 Apr 2012 12:59

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

Pinturiccio
Devart Team
Posts: 2192
Joined: Wed 02 Nov 2011 09:44

Post by Pinturiccio » Thu 12 Apr 2012 11:49

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.

CNPSV
Posts: 27
Joined: Thu 01 Nov 2007 09:48

Post by CNPSV » Thu 12 Apr 2012 11:55

I understand, but the problem is that there is nothing in the error message that indicates the database does not exist.

CNPSV
Posts: 27
Joined: Thu 01 Nov 2007 09:48

Post by CNPSV » Thu 12 Apr 2012 12:06

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.}

CNPSV
Posts: 27
Joined: Thu 01 Nov 2007 09:48

Post by CNPSV » Thu 12 Apr 2012 12:17

I forgot to mention. I am using postgresql-9.1.3-1-windows-x64

Pinturiccio
Devart Team
Posts: 2192
Joined: Wed 02 Nov 2011 09:44

Post by Pinturiccio » Thu 12 Apr 2012 12:28

We will investigate the possibility to change the exception message and notify you as soon as possible.

CNPSV
Posts: 27
Joined: Thu 01 Nov 2007 09:48

Workaround 1

Post by CNPSV » Thu 19 Apr 2012 09:54

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.

Pinturiccio
Devart Team
Posts: 2192
Joined: Wed 02 Nov 2011 09:44

Post by Pinturiccio » Fri 20 Apr 2012 09:05

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.

CNPSV
Posts: 27
Joined: Thu 01 Nov 2007 09:48

Post by CNPSV » Fri 20 Apr 2012 09:24

Thanks

Pinturiccio
Devart Team
Posts: 2192
Joined: Wed 02 Nov 2011 09:44

Post by Pinturiccio » Fri 27 Apr 2012 05:20

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

CNPSV
Posts: 27
Joined: Thu 01 Nov 2007 09:48

Post by CNPSV » Fri 27 Apr 2012 08:59

It works. Thanks.
Have a nice day.

Post Reply