When executed, it issues No connection, while the network between the computer and the virtual machine (on which ./readwritepaths is running) is installed (ip of the main computer on which the base is installed The pgAdmin 3 program started with the server running (localhost: 5432) while the readwritepaths program is running.

conn = PQconnectdb("hostaddr= port=5432 connect_timeout=5 dbname=NexentaSearch user=DKOI password=21111991"); if (PQstatus(conn) == CONNECTION_BAD) { puts("No connection"); exit(0); } 

Tell me how to make the program workable?

  • one
    @ ivan31, you start bothering me. Please write your question with human formatting. Otherwise, the eyes have to break. - gecube
  • I do not know how to do that? - ivan89
  • 2
    Well, so learn the HashCode rules in the end. Built-in editor can do everything. - gecube
  • Do you have rights to remotely connect to the database over the network? - vv2cc
  • @ vv2, and how to check for these rights? - ivan89

2 answers 2

@ ivan31 PostgreSQL's default configuration does not allow incoming connections from external computers. This means that no external applications can access your database. And the fact that the program "Connection to database failed: timeout expired" returned only confirms the fact that it is necessary to make the appropriate settings to allow remote access to the database.

See the section "Configuring Remote Access to PostgreSQL". How to configure PostgreSQL and integrate it with PHP and Apache?

    @ ivan31 , unfortunately never worked with Postgress from C ++.

    The first example shows that the connection arguments in the PQconnectdb parameter are enclosed in apostrophes.

     psql = PQconnectdb("hostaddr = '' port = '' dbname = 'fwaggle' user = 'fwaggle' password = 'password' connect_timeout = '10'"); 

    Maybe this is the case?

    PS Dear responsible / appreciative! Well, the person does not know the topic, wants to figure out why minus?

    • @avp, thanks for the sensible comment, but unfortunately this did not solve the problem. - ivan89
    • Try PQerrorMessage fprintf (stderr, "Connection to database failed:% s", PQerrorMessage (conn)); - avp
    • Issued Connection to database failed: timeout expired - ivan89
    • one
      @avp According to the description, apostrophes are required if the value contains spaces or is empty - alexlz
    • one
      So he has 5 seconds (connect_timeout = 5). You can try to run the same program directly on the computer (real), where postgresql ... If it works there, then see why the packages (most likely) do not pass between the virtual and real computers. - alexlz