can't connect, get exception without message

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
DaveBowman
Posts: 4
Joined: Tue 27 Apr 2021 09:30

can't connect, get exception without message

Post by DaveBowman » Tue 27 Apr 2021 09:43

Hi,

I want to connect to a pgbouncer stats database, but can't. I get an exception with a empty message, not very helpful. The Code:

Code: Select all

var connString = $"Host={Ip};Port={PortPgBouncer};User=pgbouncer;Password=myPw;Database=pgbouncer;Protocol=2;";
var tab = new DataTable();
using (var con = new PgSqlConnection(connString))
{
	con.Open();
	tab.Load(new PgSqlCommand(statement, con).ExecuteReader());
	con.Close();
}
I have installed the express edition. What do I wrong?

DaveBowman
Posts: 4
Joined: Tue 27 Apr 2021 09:30

Re: can't connect, get exception without message

Post by DaveBowman » Wed 28 Apr 2021 06:54

To give more information, the PgSqlException occurs on opening the connection. This Exception looks like

Code: Select all

		CallStack	null	string
		ColumnName	null	string
		ConstraintName	null	string
+		Data	{System.Collections.ListDictionaryInternal}	System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
		DataTypeName	null	string
		DetailMessage	null	string
+		Error	{ERROR: }	Devart.Data.PostgreSql.PgSqlError
		ErrorCode (System.Runtime.InteropServices.ExternalException)	-2147467259	int
		ErrorCode	null	string
		ErrorSql	null	string
		FileName	null	string
		HResult	-2147467259	int
		HelpLink	null	string
		Hint	null	string
+		InnerException	null	System.Exception
		InternalPosition	null	string
		InternalQuery	null	string
		LineNumber	0	int
		Message	""	string
		Position	0	int
		ProcedureName	null	string
		SchemaName	null	string
		Severity	Error	Devart.Data.PostgreSql.Severity
		SeverityMessage	"ERROR"	string
		Source	"Devart.Data.PostgreSql"	string
		TableName	null	string
+		TargetSite	{Void a(Devart.Data.PostgreSql.PgSqlConnection)}	System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
The StackTrace is

Code: Select all

   bei Devart.Data.PostgreSql.n.a(PgSqlConnection A_0)
   bei Devart.Data.PostgreSql.n..ctor(f A_0, PgSqlConnection A_1)
   bei Devart.Data.PostgreSql.w.a(DbConnectionOptions A_0, Object A_1, DbConnectionBase A_2)
   bei Devart.Common.DbConnectionFactory.a(DbConnectionPool A_0, DbConnectionOptions A_1, DbConnectionBase A_2)
   bei Devart.Common.DbConnectionPool.a(DbConnectionBase A_0)
   bei Devart.Common.DbConnectionPool.GetObject(DbConnectionBase owningConnection)
   bei Devart.Common.DbConnectionFactory.b(DbConnectionBase A_0)
   bei Devart.Common.DbConnectionClosed.Open(DbConnectionBase outerConnection)
   bei Devart.Common.DbConnectionBase.Open()
   bei Devart.Data.PostgreSql.PgSqlConnection.Open()
   bei ClusterStatus.PatroniClusterMember.<GetPgBouncerStatAsDatatable>d__54.MoveNext() in C:\Users\MyName\Documents\Visual Studio 2019\Projects\PostgreSqlTools\ClusterStatus\PatroniClusterMember.cs: Zeile121
Connections to the database are working, that's why I assume, there is no problem with the license. But I can't get connections to a pgbouncer instance. What can I do?

DmitryGm
Devart Team
Posts: 42
Joined: Fri 11 Dec 2020 10:27

Re: can't connect, get exception without message

Post by DmitryGm » Fri 30 Apr 2021 14:10

Try to specify 'Protocol=3;' in the connection string.

DaveBowman
Posts: 4
Joined: Tue 27 Apr 2021 09:30

Re: can't connect, get exception without message

Post by DaveBowman » Mon 31 May 2021 06:35

With this parameter I get this exception on opening the connection (before I can commit a statement):

Code: Select all

invalid command 'SELECT version()', use SHOW HELP;

DmitryGm
Devart Team
Posts: 42
Joined: Fri 11 Dec 2020 10:27

Re: can't connect, get exception without message

Post by DmitryGm » Mon 31 May 2021 11:00

Please tell us the version of PgBouncer you use.
Besides, let's ensure that the connection to your database is configured properly.
Can you connect via pgAdmin, for example?

I see "Database=pgbouncer;" in your connection string, but most likely you should connect to some database behind PgBouncer (for example postgresql). Otherwise, you may have to report to the support team of PgBouncer.

Note that the 'SELECT version()' command is sent by dotConnect for PostgreSQL during establishing a connection.

DaveBowman
Posts: 4
Joined: Tue 27 Apr 2021 09:30

Re: can't connect, get exception without message

Post by DaveBowman » Mon 31 May 2021 12:16

The version is 1.15.0.
I don't want to connect to the postgresql database behind pgbouncer, but to pgbouncer itself (please see https://www.pgbouncer.org/usage.html#admin-console).
The connect to pg works properly, but not to the virtual pgbouncer database.

NpgSql can't connect (https://stackoverflow.com/questions/672 ... 3#67274513) to the pgbouncer database, but I have read (https://github.com/npgsql/npgsql/issues ... -724505820) the devart provider can (with Parameter Protocol=2). But it does not work.

DmitryGm
Devart Team
Posts: 42
Joined: Fri 11 Dec 2020 10:27

Re: can't connect, get exception without message

Post by DmitryGm » Tue 01 Jun 2021 14:29

dotConnect for PostgreSQL is intended for connecting to PostgreSQL databases via standard PostgreSQL client-server protocol. It can be a simple (v2) protocol as well as an extended (v3) protocol.

Apparently PgBouncer doesn’t support all features of the PostgreSQL protocol, so you may ask PgBouncer team to implement it in order to use ordinary PostgreSQL tools for connecting to a PgBouncer virtual database.

Post Reply