PostgreSQL server connection error

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ertank
Posts: 172
Joined: Wed 13 Jan 2016 16:00

PostgreSQL server connection error

Post by ertank » Sun 17 Dec 2017 21:11

Hello,

I am using Delphi 10.2, UniDAC 7.1.3, PostgreSQL 10.1, target is Win32 executable.

I would like to connect to PostgreSQL server without making any database connection. After establishing connection, I will use TUniScript to create a database on the server.

Using an empty database name results to "database "test" not exists exception". Example code is as follows:

Code: Select all

  UniConnection1.Close();
  UniConnection1.ProviderName := 'PostgreSQL';
  UniConnection1.Server := 'localhost';
  UniConnection1.Port := 0;
  UniConnection1.Database := EmptyStr;
  UniConnection1.Username := 'test'; // there is indeed a user named test in database system
  UniConnection1.Password := 'test'; // test user's password is indeed test in database system
  UniConnection1.Connect();
I appreciate any help.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: PostgreSQL server connection error

Post by azyk » Mon 18 Dec 2017 09:13

When establishing a connection, PostgreSQL protocol requires the DB name not to be empty. Therefore, if the TUniConnection.Database property is empty, then UniDAC assigns it a value from TUniConnection.Username .

One of the variants to solve the issue is to establish a connection to system DB postgres. Or create a separate DB, for example named for_create_db, connect to it and then create new DBs using TUniScript.

Post Reply