Top
Symfoware Server V12.1.0 Application Development Guide
FUJITSU Software

7.3 Connecting with the Database

Use the CONNECT statement shown below to create a connection to the database server.

Format

EXEC SQL CONNECT TO target [AS connection-name] [USER user-name]END-EXEC.
target

Write in one of the following formats:

  • dbname@host:port

  • tcp:postgresql://host:port/dbname[?options]

  • Linuxunix:postgresql://host[:port][/dbname][?options]
    (Definition method when using the UNIX domain socket)

  • SQL string literal containing one of the above formats

  • Reference to a character variable containing one of the above formats

  • DEFAULT

user-name

Write in one of the following formats:

  • username

  • username/password

  • username IDENTIFIED BY password

  • username USING password

Description of the arguments

Argument

Description

dbname

Specify the database name.

host

Specify the host name for the connection destination.

port

Specify the port number for the database server.

The default is "26500".

connection-name

Specify connection names to identify connections when multiple connections are to be processed within a single program.

username

Specify the user that will connect with the database.

If this is omitted, the name used will be that of the user on the operating system that is executing the application.

password

Specify a password when authentication is required.

options

Specify the following parameter when specifying a time for timeout. Connect parameters with & when specifying more than one. The following shows the values specified for each parameter.

  • connect_timeout

    Specify the timeout for connections.

    Specify a value between 0 and 2147483647 (in seconds). There is no limit set if you set 0 or an invalid value. If "1" is specified, the behavior will be the same as when "2" was specified. An error occurs when a connection cannot be established within the specified time.

  • keepalives

    This enables keepalive.

    Keepalive is disabled if 0 is specified. Keepalive is enabling when any other value is specified. The default is keepalive enabled. Keepalive causes an error to occur when it is determined that the connection with the database is disabled.

  • keepalives_idle

    Specify the time until the system starts sending keepalive messages when communication with the database is not being performed.

    • Linux

      Specify a value between 1 and 32767 (in seconds). The default value of the system is used if this is not specified.

    • Windows

      Specify a value between 1 and 2147483647 (in seconds). 7200 will be set as default if a value outside this range is specified or if nothing is specified.

  • keepalives_interval

    Specify the interval between resends when there is no response to keepalive messages.

    • Linux

      Specify a value between 1 and 32767 (in seconds). The default value of the system is used if this is not specified.

    • Windows

      Specify a value between 1 and 2147483647 (in seconds). 1 will be set as default if a value outside this range is specified or if nothing is specified.

  • keepalives_count

    Specify the number of resends for keepalive messages.

    • Linux

      Specify a value between 1 and 127. The default value of the system is used if this is not specified.

    • Windows

      The system default value is used irrespective of what is specified for this parameter.

Code examples for applications

EXEC SQL CONNECT TO tcp:postgresql://sv1:26500/mydb?connect_timeout=20&keepalives_idle=20&keepalives_interval=5&keepalives_count=2&keepalives=1 USER myuser/myuser01 END-EXEC.