Pergunta

I've been building a Lazarus Pascal program using Postgresql on the back-end. It used to work fine with the following lines for opening the DB.

  dbConn:= TPQConnection.Create(nil);
  dbConn.HostName := 'localhost';
  dbConn.DatabaseName:= 'dbHRS';
  dbconn.UserName:='mizk';
  dbConn.Password:='123';
  dbConn.Open;
    if dbConn.Connected Then
       OpenHRSDB := true
    else
        OpenHRSDB := False;

But the moment I change from localhost to the server's IP (on the LAN), the program simply stops. No errors or warnings. I have no clue as to what is happening.

Here are some related details that may help narrow down the problem.

  1. the program I'm running is from a workstation on the same LAN as the server.
  2. Both machines run Ubuntu 12.04 Desktop
  3. I can access the postgres DB on the server using PGAdmin III, so I guess it's not a firewall issue.
  4. I have allowed postgresql from ufw and ufw is disabled.
  5. Strangely, when the firewall is disabled, I can SSH the server from terminal using the workstation. But when it's enabled, I can't

My biggest concern right now is why the Pascal program is not working when the IP number is given and what is that message in the postgres log.

Any inputs are really appreciated. Thanks!

Edit: Here's more info:

The file postgresql.conf contains these lines:

listen_addresses = '*'
port = 5430

So sorry... Here's the correct log AFTER connection logging was turned on. The log file contains this after I shutdown, restarted and run my program:

2014-03-06 18:28:23 IST LOG: database system was shut down at 2014-03-06 18:28:22 IST 2014-03-06 18:28:23 IST LOG: connection received: host=[local] 2014-03-06 18:28:23 IST LOG: incomplete startup packet 2014-03-06 18:28:23 IST LOG: database system is ready to accept connections 2014-03-06 18:28:23 IST LOG: autovacuum launcher started 2014-03-06 18:28:24 IST LOG: connection received: host=[local] 2014-03-06 18:28:24 IST LOG: connection authorized: user=postgres database=postgres 2014-03-06 18:28:24 IST LOG: connection received: host=[local] 2014-03-06 18:28:24 IST LOG: connection authorized: user=postgres database=postgres 2014-03-06 18:28:25 IST LOG: connection received: host=[local] 2014-03-06 18:28:25 IST LOG: connection authorized: user=postgres database=postgres 2014-03-06 18:28:29 IST LOG: connection received: host=[local] 2014-03-06 18:28:29 IST LOG: incomplete startup packet

Foi útil?

Solução

I realised that something was missing when I found this link that talked about the PORT: http://lists.lazarus.freepascal.org/pipermail/lazarus/2009-August/044403.html

So I included the following line in my code to connect: dbConn.Params.Text := 'port=5430';

I'm not sure if this is most correct way of doing this connection string because I was thinking there may be other parameters in the connection string that are also used and the above method may over-write those params. For this reason I put this as the first line.

So this method has worked for me.

There's also another method that I tried but it did not work for me. That was to use the append method (dbConn.Params.Append)

I also found out that the parameters are case-sensitive and I had to write 'port' ('Port' did not work).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top