ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / Managing databases / HFSQL / HFSQL functions
  • Configuring the connection
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Redefines one or more connection parameters via Native Connector (Access, SQL Server, MySQL or Oracle) or via an OLE DB access on a specific table or set of tables. Then, the tables are opened (or created if they do not exist). The specified test operation is run.
Remarks:
  • The new redefinition of the connection will be used until it is canceled by HConnect. It will be automatically canceled at the end of application.
  • By default, the connection characteristics are defined in the data model editor, for one or more tables.
Important
HConnect is used to easily define a connection to a database. It is recommended to use HDescribeConnection and HChangeConnection to:
  • manage the advanced parameters available for some databases (cursors, transactions, ...),
  • handle a named connection.
Reports and QueriesHFSQL ClassicHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)
HConnect("Salaries", "", "", ...
"C:\My Documents\MyDatabase.mdb", "Microsoft.JET.OLEDB.4.0", hOReadWrite)
Syntax
<Result> = HConnect(<Table name> [, <User> [, <Password> [, <Database> [, <OLE DB server or Native Connector> [, <Access> [, <Test operation> [, <Optional information>]]]]]]])
<Result>: Boolean
  • True if the operation was performed,
  • False if a problem occurs. HErrorInfo is used to identify the error.
<Table name>: Character string
Name of the table (data file) to opened, and for which the connection must be redefined. If no other parameter is specified, the data file is re-initialized with the default parameters defined in the analysis.
  • If this parameter is equal to "*", the change will apply to all tables handled by the Native Connector (also called Native Access). In this case, all connection parameters must be specified.
  • If this parameter is equal to "*" and no other parameters are specified, all data files of all Native Connectors defined in the analysis are reset to the default parameters.
<User>: Optional character string
Username that will be used to open the data file.
<Password>: Optional character string
Connection password (if this password exists).
<Database>: Optional character string
Full path of the data source.
<OLE DB server or Native Connector>: Optional character string or constant
Name of the OLE DB provider 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 (included with WINDEV/WEBDEV)
hNativeAccessSQLServerNative SQL Server Connector (optional module of WINDEV/WEBDEV)
hNativeAccessSQLServerMobileNative SQL Server Connector (optional module of WINDEV Mobile)
hNativeAccessSybaseNative Sybase Connector (optional module of WINDEV/WEBDEV)
hNativeAccessXBaseNative xBase Connector (included 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 setup program)
  • install the OLE DB provider corresponding to the database used.
    This parameter is returned by the CtOLEDBProvider property.
<Access>: Optional constant
Configures the type of access to the data file.
hOReadThe data file can be accessed in read-only mode. It is only possible to read records. It is not possible to add or remove records.
hOReadWrite
(default value)
The data file can be accessed in read/write mode. It is possible to read and write new records.
<Test operation>: Optional constant
Configure the type of operation that will be performed on the database to check the connection.
hHCreationIfNotFound
(Default value)
Checks the connection by opening or creating a data file (if the data file does not exist). This operation can be performed in hOReadWrite mode only.
hHOpenChecks the connection by opening a data file. This value is used by default when accessing to an hORead database.
<Optional information>: Optional character string
Information inserted in the database connection string.
For example, some data sources allow you to specify the database that will be used. With SQLServer, the "Master" database is the default database but other databases can be used, "dbo" for example. This information is specified in the <Optional information> parameter via the following syntax:
OLE DB "initial catalog = dbo"
ODBC "database = dbo"
Native Connectors (Native Accesses) MySQL: "initial catalog = dbo"
OLE DBNative Connectors (Native Accesses) The keywords recognized by OLE DB and the Native Connectors are presented in the Optional connection information page.
Remarks

Configuring the connection

  • The table description must be known during the call to HConnect (the table must have been described in the analysis, or by HDeclare or HDescribeFile).
  • HConnect opens the connection and the table. The table is created if it does not exist. For this specific point, HConnect is equivalent to HCreationIfNotFound.
  • When redefining the connection, only the specified parameters are taken into account. The value of parameters not specified by HConnect corresponds to the value defined in the data model editor.
  • If only the <Table name> is specified, HConnect cancels the connection redefinition for the specified tables. The parameters specified in the data model editor will be applied.
  • When the <Table name> parameter is equal to "*", the change applies to all the Native Connector tables defined in the analysis. In this case, only the <User>, <Password>, <Database> and <Access> parameters are taken into account.
  • To cancel a connection change performed on the tables, <Table name> must be equal to "*" and no other parameter must be specified.
  • If the data source is specified, HConnect ignores the possible HSubstDir/HChangeDir.
  • If a table is open when HConnect is called, the table is closed then reopened with the new connection parameters.
Business / UI classification: Business Logic
Component: wd300hf.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Example

Example
Nagyro.ini
======================
[Nagyro]
Server = 192.168.1.180
User = sa
Password = 777777777
BD = producao
======================


PROCEDURE DB_Inicialize(TrueFalse)

Server, User, Password, BD is string

IF TrueFalse = True THEN

PathFile is string = fCurrentDir(fCurrentDrive()) +"\Nagyro.ini"

IF fFileExist(PathFile) = True THEN

Server = INIRead("Nagyro", "Server", "", PathFile)
IF ErrorOccurred THEN
Error()
END

User = INIRead("Nagyro", "User", "", PathFile)
IF ErrorOccurred THEN
Error()
END

Password = INIRead("Nagyro","Password", "", PathFile)
IF ErrorOccurred THEN
Error()
END

BD = INIRead("Nagyro", "BD", "", PathFile)
IF ErrorOccurred THEN
Error()
END

HCloseConnection(ConnNativa)

ConnNativa..Server = Server
ConnNativa..User = User
ConnNativa..Password = Password
ConnNativa..Database = BD
ConnNativa..Provider = hNativeAccessSQLServer
ConnNativa..Access = hOReadWrite
ConnNativa..ExtendedInfo = "Extended information"
ConnNativa..CursorOptions = hClientCursor

ok is boolean = HOpenConnection(ConnNativa)

IF ok = False
Info(ErrorInfo())
Close()
END

END

END
adrianoboller
09 Feb. 2015

Last update: 06/14/2024

Send a report | Local help