ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / Managing databases / HFSQL / HFSQL functions
  • Syntax 1: Open a predefined connection: automatic connection management
  • Syntax 2: Using a character string for the OLE DB provider
  • Syntax 2 and 3: If a failure occurs, the connection description is not kept
  • Pseudo-connection to HFSQL Classic database
  • Differences between HOpenConnection and HDescribeConnection
  • UDL file (file for describing an OLE DB connection)
  • Oracle Native Connector: external authentication management
  • Limitations
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Opens a connection to a specific database. The connection remains opened until the call to HCloseConnection. HOpenConnection is used to:
  • open a preset connection.
  • define and open a connection. Then, this connection must be assigned to a data file with HChangeConnection.
  • define and open a connection by using a connection string. This syntax can be used with some OLE DB providers who have specific ADO connecting strings.
    PHP This option is not available.
  • open a connection defined by a Connection variable.
Caution: The order of use of functions for connecting to an HFSQL Client/Server database is important.. For more details, see Optimizing the connection times to the HFSQL Client/Server databases.
WindowsLinuxAjaxHFSQL ClassicHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)
MaConnexion is Connection
// Description de la connexion 
MaConnexion.Utilisateur = "USER" 
MaConnexion.MotDePasse = "PASSWORD" 
MaConnexion.Serveur = "MONSERVEUR" 
MaConnexion.BaseDeDonnées = "Base de données" 
MaConnexion.Provider = hAccessHFClientServer 
MaConnexion.Accès = hOReadWrite 
MaConnexion.InfosEtendues = "Infos étendues" 
MaConnexion.OptionsCurseur = hClientCursor 
HOpenConnection(MaConnexion)
Syntax

Opening a preset connection Hide the details

<Result> = HOpenConnection(<Connection>)
<Result>: Boolean
  • True if the operation was performed,
  • False if a problem occurred (during a connection described through programming, some parameters used in HDescribeConnection may be incorrect for example).
HErrorInfo is used to identify the error.
<Connection>: Character string or Connection variable
Connection to a database. This connection corresponds to:
  • the name of the connection defined in the data model editor,
  • the name of the connection defined by HDescribeConnection. The connection description must be known when running the function.
  • the name of a variable of type Connection.

Defining and opening a connection Hide the details

<Result> = HOpenConnection(<New connection> , <User> [, <Password>] , <Data source> [, <Database>] , <OLE DB provider or Native Connector> [, <Access> [, <Extended information> [, <Additional options>]]])
<Result>: Boolean
  • True if the operation was performed,
  • False if a problem occurs. HErrorInfo is used to identify the error. To assign this connection to a file, use HChangeConnection. The connection description will be deleted when closing the connection.
<New connection>: Character string or Connection variable
Name of new connection to define and to open. This name must not be used by another connection (defined in the analysis, or by HOpenConnection or HDescribeConnection).
This parameter corresponds to the Name property used on a variable of type Connection.
<User>: Character string
Username used for the database. This parameter can be modified and retrieved using the User property on a variable of type Connection.
<Password>: Optional character string
Connection password (if this password exists). If no password is required, use an empty string ("") or the NULL keyword. This parameter can be modified using the Password property on a variable of type Connection.
<Data source>: Character string
Full path of the data source. The connection will be created and opened for this data source.
This parameter can be retrieved and modified using the Source property (or Server) on a variable of type Connection.
HFSQL Client/Server This parameter corresponds to the server name. The port number used by the HFSQL server can be specified. The port 4900 will be used by default. If the port number of the HFSQL server is different, use the following notation:
<Nom du poste>: <Numéro de port>
Example: "ComputerName:4901".
For a use via Internet, the ports must be managed by Firewall. For more details, see Managing ports. You have the ability to specify an IPv6 address by writing the IPv6 address between square brackets. In this case, the port number must be specified after the closing square bracket. For example: [0154:2145:2155::5554]:4900.
<Database>: Optional character string
Name of database that will be used on the data source. If this parameter is not required, use an empty string ("").
This parameter can be retrieved and modified using the Database property on a variable of type Connection.
In the case of a database divided into schemas, the name of the schema in the database will be specified by HChangeName.
This database will be automatically created if it does not exist.
Native Connectors (Native Accesses) DB2: This parameter is not required.
<OLE DB provider or Native Connector>: Character string or constant
  • Name of OLE DB provider used. To easily retrieve the string to use, select "Connection" in the data model editor (see the Notes).
    or
  • one of the following constants:
    hAccessHF7Pseudo-connection to HFSQL Classic database.
    hAccessHFClientServerNative Connector to an HFSQL Client/Server database.
    hNativeAccessAS400Native AS/400 Connector (optional module of WINDEV/WEBDEV).
    hNativeAccessDB2Native DB2 Connector (optional module of WINDEV/WEBDEV).
    hNativeAccessInformixNative Informix Connector (optional module of WINDEV/WEBDEV).
    hNativeAccessMariaDBNative MariaDB Connector (optional module of WINDEV/WEBDEV).
    hNativeAccessMySQLNative MySQL Connector (optional module of WINDEV/WEBDEV).
    hNativeAccessOracleNative Oracle Connector (optional module of WINDEV/WEBDEV).
    hNativeAccessOracleLiteNative Oracle Connector (optional module of WINDEV Mobile).
    hNativeAccessPostgreSQLNative PostgreSQL Connector (optional module of WINDEV/WEBDEV).
    hNativeAccessProgressNative Progress Connector (optional module of WINDEV/WEBDEV).
    hNativeAccessSQLAzureNative SQL Azure Connector (optional module of WINDEV/WEBDEV, provided with the Native SQL Server Connector).
    hNativeAccessSQLiteNative SQLite Connector (provided with WINDEV/WEBDEV).
    hNativeAccessSQLServerNative SQL Server Connector (optional module of WINDEV/WEBDEV)
    The former Native Connector is used by default. To use the new Native SQL Server Connector, use the H.SQLServerMode variable.
    hNativeAccessSQLServerMobileNative SQL Server Mobile Connector (optional module of WINDEV Mobile).
    hNativeAccessSybaseNative Sybase Connector (optional module of WINDEV/WEBDEV).
    hNativeAccessXBaseNative xBase Connector (provided with WINDEV/WEBDEV).
    hNativeAccessXMLNative XML Connector (provided with WINDEV/WEBDEV).
    hODBCOLE DB provider for ODBC (used to access an ODBC data source declared in the ODBC data sources of Windows).
    hOledbAccess97OLE DB provider for Access 97.
    hOledbAccess2000OLE DB provider for Access 2000.
    hOledbAccess2007OLE DB provider for Access 2007.
    hOledbAccess2010OLE DB provider for Access 2010.
    hOledbDBase5OLE DB provider for dBase 5.
    hOledbExcel97OLE DB provider for Excel 97.
    hOledbExcel2000OLE DB provider for Excel 2000.
    hOledbExcel2007OLE DB provider for Excel 2007.
    hOledbLotus4OLE DB provider for Lotus 4.
    hOledbOracleOLE DB provider for Oracle.
    hOledbSQLServerOLE DB provider for SQL Server


OLE DB Caution: To use an OLE DB connection, you must:
  • install MDAC version 2.6 or later (setup performed by WINDEV/WEBDEV and when creating the client version).
  • install the OLE DB provider corresponding to the database used.
    This parameter is returned by the CtOLEDBProvider property.
PHP This parameter can correspond to one of the following constants:
hNativeAccessAS400Native AS/400 Connector (optional module of WEBDEV).
hNativeAccessMariaDBNative MariaDB Connector (optional module of WINDEV/WEBDEV).
hNativeAccessMySQLNative MySQL Connector (optional module of WEBDEV).
hNativeAccessOracleNative Oracle Connector (optional module of WEBDEV).
hNativeAccessPostgreSQLNative PostgreSQL Connector (optional module of WEBDEV).
This parameter can be retrieved and modified using the Provider property on a variable of type Connection.
<Access>: Optional constant
Configures the type of access to the database.
hOReadThe database can be accessed in read-only. It is only possible to read records. It is not possible to add or remove records.
HFSQL Client/Server This constant is ignored.
hOReadWrite
(default value)
The database can be accessed in read/write. It is possible to read and write new records.
This parameter can be retrieved and modified using the Access property on a variable of type Connection.
PHP This parameter is not available.
<Extended information>: Optional character string
Optional information inserted into the string for connecting to the database. If specific keywords are recognized, the corresponding information is extracted from the connection string. The rest of the connection string is sent to the database. Then, the extracted parameters are processed by the Native Connector or by the OLE DB connector used.
These keywords must be indicated as follows: "<Mot-clé> = <Valeur>;".
You can for example specify "Trusted_Connection=YES" in order to use a connection with authentication via the NT login.
OLE DBNative Connectors (Native Accesses) The keywords recognized by OLE DB and the Native Connectors are displayed on Optional connection information.
Example of string to use:
"WD Cache Size = 10000; Server Port=3306;"
HFSQL Client/Server Recognized keywords for the access via HFSQL Client/Server:
COMPRESSIONEnables or disables the compression of data exchanged between Client and Server. This keyword can correspond to:
  • TRUE to enable the data compression.
  • FALSE to disable the data compression.
DB_EXISTChecks the existence of the database. If the specified database does not exist, this database is not created and HOpenConnection returns False.
ENCRYPTIONEnables the encryption of data exchanged between Client and Server. This keyword can take one of these values:
  • FAST
  • RC5_16 to use 16-round RC5 encryption.
  • AES128 to use 128-bit AES encryption with the OFB mode of operation.
  • AES192 to use 192-bit AES encryption with the OFB mode of operation.
  • AES256 to use 256-bit AES encryption with the OFB mode of operation.

This parameter can be retrieved and modified using the ExtendedInfo property.
PHP This parameter is not available.
<Additional options>: Optional constant
If this parameter is not specified, the HFSQL engine automatically defines the best parameters to use according to the database accessed and to the OLE DB provider used.
By default, this parameter corresponds to the following combination of constants:
hServerCursor + hOpenKeysetCursor + hOptimisticCursor
However, these parameters can differ according to the information returned by the database.
To force some parameters, you have the ability to combine the following constants:
  • Cursor location
    hClientCursorCursor managed by MDAC. Generally, it offers more features than a server-side cursor. A client-side cursor is always static.
    hServerCursorCursor managed by the database. This cursor can easily reflect changes made to data by other users.
  • Cursor type
    hDynamicCursorThis cursor offers many features, but consumes a lot of memory. This cursor supports all types of scrolling. You can access all insert, update and delete operations made by other users.
    hForwardOnlyCursorThis cursor is fast and consumes little memory. The move is performed from the first record to the last one. Changes made by other users are not visible.
    hOpenKeysetCursorThis cursor handles a fixed set of records. Only the key of each record is stored and not the actual record (consumes less memory). Deleted records cannot be accessed. Changes made by other users are visible (but added records are not).
    hStaticCursorMakes a copy of all query records in memory (high memory consumption). All types of scrolling are supported.
  • Lock mode
    hOptimisticCursorThe record is locked when it is updated
    hPessimisticCursorThe record is locked as soon as it is edited.
    hReadOnlyCursorThe record set manipulated cannot be modified.
Please note: not all OLE DB providers support all cursor types.
This parameter can be retrieved and modified using the CursorOptions property.
PHP This parameter is not available.
WEBDEV - Server codeAjax

Defining and opening a connection by defining the connection string Hide the details

<Result> = HOpenConnection(<Connection> , <ADO connection string> [, <Access>])
<Result>: Boolean
  • True if the operation was performed,
  • False if a problem occurs. HErrorInfo is used to identify the error. The connection description will be deleted when closing the connection.
<Connection>: Character string
Name of new connection to define and to open. This name must not be used by another connection (defined in the analysis, or by HOpenConnection or HDescribeConnection).
<ADO connection string>: Character string
ADO connection string to use. For more details on the syntax of this connection string, see the documentation of the OLE DB provider used.
<Access>: Optional constant
Configures the type of access to the database.
hOReadThe database can be accessed in read-only. It is only possible to read records. It is not possible to add or remove records.
hOReadWrite
(default value)
The database can be accessed in read/write. It is possible to read and write new records.
Remarks
WEBDEV - Server codePHPAjaxHFSQL ClassicHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)

Syntax 1: Open a predefined connection: automatic connection management

  • The connection associated with a data file is automatically opened when the data file is opened. The connection is closed when the last data file that uses this connection is closed.
  • Any connection opened by HOpenConnection remains open even if no data file uses it.
  • If the application opens and closes data files many times in a row, the automatic management of connections will open/close connections many times, slowing down the application. In this case, it is recommended to use HOpenConnection to keep the connection open.
WEBDEV - Server codePHPAjaxHFSQL ClassicHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)

Syntax 2: Using a character string for the OLE DB provider

To easily find the character string that must be used to define the OLE DB provider, we recommend that you proceed as follows:
  1. In the data model editor, create an HFSQL Client/Server connection, for example.
  2. In the connection description screen, select the provider to be used (in "Connection by").
  3. The character string corresponding to the provider is displayed. This character string can be used in the syntax 2 instead of constants.
Using a character string for the OLE DB provider
WEBDEV - Server codePHPAjaxHFSQL ClassicHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)

Syntax 2 and 3: If a failure occurs, the connection description is not kept

If the connection fails to open, the description of this connection is not validated. This allows you to redefine a connection with the same name.
For example, if the attempt to connect with the default password fails, you have the ability to perform a new attempt with another password.
WEBDEV - Server codeAjaxHFSQL Classic

Pseudo-connection to HFSQL Classic database

OLE DB data files or native data files are described in the data model editor. To handle these descriptions with an HFSQL Classic database, simply specify the hAccessHF7 constant as provider name.
The data files in HFSQL Classic format corresponding to the description of the OLE DB or native files will be created (if necessary) in the directory defined by <Data source>.

Differences between HOpenConnection and HDescribeConnection

Method 1: To open a connection at the beginning of the application and close it at the end, use the HOpenConnection function.. To use this connection when handling data files or tables, simply change this connection with HChangeConnection.
HOpenConnection(MaConnexion, params) // Ouverture de la connexion 
HChangeConnection(UnFichier, MaConnexion)
Method 2: To programmatically describe a connection and open it automatically when the file is opened, simply:
  • describe the connection with HDescribeConnection
  • associate this connection with the desired data file description using HChangeConnection. The connection will only be opened the first time the data file is accessed.
This solution can be useful when an application handles both HFSQL data files and Oracle data files. For example, if the application uses a single Oracle file, in a specific process, the connection to the Oracle database will only be made if necessary.
If the first solution is chosen for the same type of application, the connection (that may take quite a long time) will be established whenever the application is started.
Example:
HDescribeConnection(MaConnexion, params) 
HChangeConnection(UnFichier, MaConnexion) 
... 
HReadFirst(unFichier) // Ouverture de la connexion 
... 
HClose(UnFichier) // Fermeture de la connexion
WEBDEV - Server codeAjaxOLE DB

UDL file (file for describing an OLE DB connection)

To create a UDL file:
  1. Create a text file whose extension is "UDL".
  2. Double-click this file. The window for the properties of the data links is opened.
  3. Configure the connection.
  4. Run the test of the connection.
  5. Confirm ("OK" button). The UDL file can now be used.
WEBDEV - Server codeNative Connectors (Native Accesses)

Oracle Native Connector: external authentication management

To connect via an external authentication, the following connection parameters must be used:
  • <Username> = / (slash)
  • <Password> = "" (empty string)
Note: External authentication relies on the Windows user name and password to connect to the database.. The external authentication requires configuring the server. See the Oracle documentation to learn more about how to authorize external authentications on the server.

Limitations

    Component: wd300hf.dll
    Minimum version required
    • Version 9
    This page is also available for…
    Comments
    //Exmplo de garantia de conexao e disponibilidade
    //Exmplo de garantia de conexao e disponibilidade

    If ping(“200.38.56.1”, 5s) = True

    //Deu certo log ok

    If Hopenconnection = True
    If Hchangeconnection = True

    Executa aqui teu código

    Else

    //log erro

    End

    Else

    // log erro

    End

    Else // Ping

    //Bug log
    Log.evento = “consumo de dados”
    Log.datahora = datesys()+Timesys()
    Log.descricao = herrorInfo() + cr + errorinfo()
    Hadd(log)

    End
    Boller
    11 May 2024
    Exemplo com porta diferente
    GLOBAL
    Banco is string = INIRead("Database","Banco","",fCurrentDir()+"\ConfigDB.ini")
    DNS_IP is string = INIRead("Database","DNS-IP","",fCurrentDir()+"\ConfigDB.ini")
    Porta is string = INIRead("Database","Porta","",fCurrentDir()+"\ConfigDB.ini")
    Usuario is string = INIRead("Database","Usuario","",fCurrentDir()+"\ConfigDB.ini")
    Senha is string = INIRead("Database","Senha","",fCurrentDir()+"\ConfigDB.ini")

    IF Usuario = "" AND Senha = "" THEN
    Open(WIN_ConfigDatabase)
    END

    MyHfsql01 is Connection
    MyHfsql01..Provider = hAccessHFClientServer
    MyHfsql01..Database = Banco
    MyHfsql01..Server = DNS_IP
    MyHfsql01..Source = DNS_IP +":"+ Porta
    MyHfsql01..User = Usuario
    MyHfsql01..Password = Senha


    HModifyStructure("*")
    HCreationIfNotFound("*")
    IF HOpenConnection(MyHfsql01) = True THEN

    IF HChangeConnection("*",MyHfsql01) = True THEN
    ToastDisplay("Conexao com sucesso!",toastLong,vaMiddle,haCenter)
    ELSE
    Error(HErrorInfo())
    END

    ELSE
    Error(HErrorInfo())
    END
    Boller
    25 Oct. 2022
    Conexao PostgreSQL com porta diferente da Padrão
    PROCEDURE ConexaoPostgreSQL()

    ok1, ok2 is boolean

    INIWrite("Config","HOST",EDT_Host,fCurrentDir()+"\Config.ini")
    INIWrite("Config","PORT",EDT_Porta,fCurrentDir()+"\Config.ini")
    INIWrite("Config","DBAS",EDT_DB,fCurrentDir()+"\Config.ini")
    INIWrite("Config","USER",EDT_User,fCurrentDir()+"\Config.ini")
    INIWrite("Config","PASS",EDT_Pass,fCurrentDir()+"\Config.ini")

    MyConnect is Connection
    MyConnect..Provider = hNativeAccessPostgreSQL
    MyConnect..Server = EDT_Host
    MyConnect..Source = EDT_Host//+";"+val(EDT_Porta)
    MyConnect..Database = EDT_DB
    MyConnect..User = EDT_User
    MyConnect..Password = EDT_Pass
    MyConnect..ExtendedInfo = "WD Cache Size = 10000; Server Port="+Val(EDT_Porta)+";"

    IF HOpenConnection(MyConnect) = True THEN
    ok1 = True
    END
    IF HChangeConnection("*",MyConnect) = True THEN
    ok2 = True
    END

    IF ok1 = True AND ok2 = True THEN
    ToastDisplay("Conectou com Sucesso no PostgreSQL!",toastLong,vaMiddle,haCenter,RGB(0,0,255))
    End
    Boller
    10 Jul. 2020
    HCS.Timeout & HCS.FrameSize
    A variável HCS.Timeout é usada para modificar o tempo limite da conexão:
    Para as conexões estabelecidas pelo HOpenConnection .
    Para as aberturas de conexão automática.
    Nota : A variável HCS.Timeout é ignorada para os acessos ao servidor que não seja a conexão. Um pedido cuja execução é maior do que o valor especificado na variável HCS.Timeout não seria interrompida, por exemplo. Esse tempo limite deve ser especificado no aplicativo cliente, antes que uma conexão seja aberta no servidor.
    Exemplo

    HCS.Timeout = INTRANET

    A variável HCS.FrameSize é usada para redimensionar o quadro de dados de saída. Em alguns casos, o redimensionamento dos quadros pode ser usado para adaptar o fluxo de dados de saída e de entrada aos desempenhos do hardware usado. Por exemplo, se a conexão entre os computadores clientes e o mecanismo HFSQL Client / Server for através de redes de configuração (placa de rede, switch, roteador, vpn, ...)

    HCS.FrameSize = hInternetFrame
    BOLLER
    28 Aug. 2017
    Exemplo de uso do driver nativo MS SQL SERVER
    //Conexao
    ok, ok1, ok2, ok3 is boolean

    myConn is Connection
    myConn..Provider = hNativeAccessSQLServer
    myConn..User = "adriano"
    myConn..Password = "adriano@2016"
    myConn..Source = "192.168.0.162\projeto01"
    myConn..Database = "projeto01"
    myConn..Access = hOReadWrite

    ok1 = HOpenConnection(myConn)
    IF ok1 = False THEN
    Info(ErrorOccurred() +" - "+ HErrorInfo())
    END


    IF gpwInitAnalysis() = False THEN
    Error(ErrorInfo())
    ok2 = False
    ELSE

    ok2 = True
    IF gpwOpen() = gpwOk
    ok3 = True
    ELSE
    Info(ErrorOccurred() +" - "+ HErrorInfo())
    ok3 = False
    END

    END

    NextTitle("Atenção")

    IF ok1 = True AND ok2 = True AND ok3 = True THEN //deve dar tudo ok

    Info("Conectou com sucesso no banco de dados!")

    ELSE

    Info("Falha ao tentar conectar no Servidor")

    END
    BOLLER
    28 Nov. 2016

    Last update: 09/24/2024

    Send a report | Local help