Page 1 of 1

PostgreSQL server connection error

Posted: Sun 17 Dec 2017 21:11
by ertank
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.

Re: PostgreSQL server connection error

Posted: Mon 18 Dec 2017 09:13
by azyk
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.