4D v16

Using a connection string

Home

 
4D v16
Using a connection string

Using a connection string    


 

 

When you use the ODBC API in PHP, Python script, Java, C, C++ or any programming language, you can connect without using a DSN by means of a connection string.

Example using Python:

import pyodbc
conn = pyodbc.connect(‘Driver={4D ODBC Driver 32-bit} ;Server=187.145.45.23 ;UID=Designer ;PWD=123456’)
curs = conn.cursor()
curs.execute('select (id,name) from table_1')
curs.fetchone()
curs.close()
conn.close()

This example uses the following keywords:

  • Driver: set to use the 32-bit 4D ODBC Driver
  • Server: set to use the 4D Server on the machine with the IP address= "187.145.45.23"; no port is specified so the default (19812) will be used.
  • UID and PWD: set to connect as "Designer" using "123456" as password.

Keywords are not case sensitive and can be used in any order, with the exception of "Driver", which must come first if it is used. Whenever you do not specify a keyword, its default value is used.

A connection string can also use a DSN. When you create a DSN using the 4D Configuration window, it saves the settings in the registry or in the odbc.ini file using the same keywords.

For example, if you use the connection string:

conn=pyodbc.connect('DSN=My_4D_DSN')

... it is the equivalent of a connection string using all the same values set in the 'My_4D_DSN' DSN.

A description of all the keywords used in a connection string, or when configuring a DSN, is shown below.

  • Driver
    Identifies the ODBC Driver used.
    For a connection string: Use the value "{4D ODBC Driver 32-bit}" or "{4D ODBC Driver 64-bit}"
    For DSN definition (OS X): Use "/Library/ODBC/4D ODBC x32.bundle/Contents/MacOS/4D ODBC x32" or "/Library/ODBC/4D ODBC x64.bundle/Contents/MacOS/4D ODBC x64" in the obdc.ini file or in the generic DSN configuration key/value pair.
  • DSN
    For a connection string: Indicates a DSN to be used.
    In this case, it is not necessary to use other keywords since they will already be defined in the DSN.
    For DSN definition: you assign a name directly and do not need a keyword.
  • Description
    For a connection string: this keyword is not used.
    For DSN definition: you can enter a short description (optional).
    Default value: ""
  • Server
    Indicates the IP address or the name of the 4D server to which you want to connect. Examples: "127.0.0.1", "localhost", "2001:0db8:0000:85a3:0000:0000:ac1f:8001".
    Default value: “localhost”.
  • Port
    Specifies the connection port.
    Default value: 19812
    This port must be the same as the one provided on the SQL/Configuration page of the Database Settings (on the server machine).
  • UID
    Identifies the user name under which you will be connected.
    Default value: ""
  • PWD
    Provides the password associated with the user name specified in the UID key.
    Default value: ""
  • SSL
    Enables a TLS connection.
    For a connection string: Can either be "True" or "False"
    For DSN definition: Appears as a checkbox
    Default value: "False"
  • PhysicalConnectionTimeout*
    An ODBC connection begins by connecting to the TCP/IP network.
    This value sets the timeout for this step.
    Default value: 0
  • LoginTimeout*
    Once the driver is connected to the TCP/IP network, it must then be recognized by the 4D server. It thus sends a frame containing the user, password and other information. This timeout sets the maximum time to wait for a reply.
    Default value: 0
  • QueryTimeout*
    Once an ODBC Driver is connected, it can also execute queries and handle data. This timeout, expressed in seconds, will be applied in this case.
    Default value: 0

    * Timeouts set the length of time to wait before aborting an action. Their values are expressed in seconds, with 0 being no timeout (unlimited wait time).
  • DefaultPageSize (advanced setting):
    Value expressed in rows.
  • NetworkCacheSize (advanced setting):
    Value expressed in KB.
  • FavouriteImageFormats (advanced setting):
    Contains a list of accepted image formats, separated by spaces, chosen from among the following: .tiff, .gif, .jpg, .png, .bmp.
    Default value: "" (accepts any image format)
  • CharsEncoding (advanced setting):
    For a connection string: Can be "UTF-8" or "System".
    For a DSN definition: Shown as a radio button
    Default value: UTF-8
  • OpenQuery (advanced setting):
    For a connection string: Use "True" or "False". If you use SQLServerManagementStudio and you experience difficulty connecting to 4D, it is preferable to execute the following script:
    EXEC sp_addlinkedserver
    @server = '<Your name>',
    @srvproduct = '<Anything>',
    @provider = 'MSDASQL',
    @provstr = 'OpenQuery=true;dsn=<a 4D-defined DSN>;UID=<your 4D User>;PWD=<Password>'

    For a DSN definition: Appears as a check box
    Default value: False (not checked)
  • MSAccess (advanced setting):
    For a connection string: Use "True" or "False". If you encounter problems with dates and times, you can try setting this option to "True".
    For a DSN definition: Appears as a check box
    Default value: False (not checked)
  • Windev (advanced setting):
    For a connection string: Use "True" or "False". If you encounter problems with Windev, you can try setting this option to "True".
    For a DSN definition: Appears as a check box
    Default value: False (not checked)

 
 

 
PROPERTIES 

Product: 4D
Theme: Using a connection string

 
HISTORY 

 
ARTICLE USAGE

4D ODBC Driver ( 4D v16)