- Syntax 1: Opening a preset connection: automatic management of connections
- Syntax 2: Using a character string for the OLE DB provider
- Syntax 2 and 3: If a failure occurs, the connection description is not stored
- Pseudo-connection to HFSQL Classic database
- Differences between HOpenConnection and HDescribeConnection
- UDL file (file for describing an OLE DB connection)
- Native Oracle Connector: managing the external authentication
- Limitations
HOpenConnection (Function) In french: HOuvreConnexion
Not available with this kind of connection
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.
This option is not available.
- open a connection defined by a Connection variable.
Caution: The order in which the functions for connecting to an HFSQL Client/Server database are called is important. See Optimizing the connection times to the HFSQL Client/Server databases for more details. Remark: From version 19, HFSQL is the new name of HyperFileSQL. 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 by programming, some parameters used in HDescribeConnection may be incorrect for example).
<Connection>: Character string (with or without quotes) 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 Connection variable.
Defining and opening a connection Hide the details
<Result> = HOpenConnection(<New connection> , <User> [, <Password>] , <Data source> [, <Database>] , <OLE DB provider or Native Access> [, <Access> [, <Extended information> [, <Additional options>]]])
<Result>: Boolean - True if the operation was performed,
- False if a problem occurred. 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 (with quotes) 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 Connection variable. <User>: Character string (with quotes) User name that will be used for the database. This parameter can be modified and retrieved using the ..User property on a Connection variable. <Password>: Optional character string (with quotes) 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 Connection variable. <Data source>: Character string (with quotes) Full path of data source. The connection will be created and opened for this data source. <Database>: Optional character string (with quotes) 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 Connection variable. 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. <OLE DB provider or Native Access>: 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:
| | hAccessHF7 | Pseudo-connection to HFSQL Classic database. | hAccessHFClientServer | Native Connector to an HFSQL Client/Server database. | hNativeAccessAS400 | Native AS/400 Connector (optional module of WINDEV/WEBDEV). | hNativeAccessDB2 | Native DB2 Connector (optional module of WINDEV/WEBDEV). | hNativeAccessInformix | Native Informix Connector (optional module of WINDEV/WEBDEV). | Versions 20 and laterhNativeAccessMariaDB New in version 20hNativeAccessMariaDB hNativeAccessMariaDB | Native MariaDB Connector (optional module of WINDEV/WEBDEV). | hNativeAccessMySQL | Native MySQL Connector (optional module of WINDEV/WEBDEV). | hNativeAccessOracle | Native Oracle Connector (optional module of WINDEV/WEBDEV). | hNativeAccessOracleLite | Native Oracle Connector (optional module of WINDEV Mobile). | hNativeAccessPostgreSQL | Native PostgreSQL Connector (optional module of WINDEV/WEBDEV). | hNativeAccessProgress | Native Progress Connector (optional module of WINDEV/WEBDEV). | Versions 16 and laterhNativeAccessSQLAzure New in version 16hNativeAccessSQLAzure hNativeAccessSQLAzure | Native SQL Azure Connector (optional module of WINDEV/WEBDEV, supplied with Native SQL Server Connector). | Versions 16 and laterhNativeAccessSQLite New in version 16hNativeAccessSQLite hNativeAccessSQLite | Native SQLite Connector (supplied with WINDEV/WEBDEV). | hNativeAccessSQLServer | Native SQL Server Connector (optional module of WINDEV/WEBDEV) The former Native Connector is used by default. To force the use of new Native SQL Server Connector, use the H.SQLServerMode variable. | hNativeAccessSQLServerMobile | Native SQL Server Mobile Connector (optional module of WINDEV Mobile). | hNativeAccessSybase | Native Sybase Connector (optional module of WINDEV/WEBDEV). | hNativeAccessXBase | Native xBase Connector (supplied with WINDEV/WEBDEV). | hNativeAccessXML | Native XML Connector (supplied with WINDEV/WEBDEV). | hODBC | OLE DB provider for ODBC (used to access an ODBC data source declared in the ODBC data sources of Windows). | hOledbAccess97 | OLE DB provider for Access 97. | hOledbAccess2000 | OLE DB provider for Access 2000. | hOledbAccess2007 | OLE DB provider for Access 2007. | Versions 19 and laterhOledbAccess2010 New in version 19hOledbAccess2010 hOledbAccess2010 | OLE DB provider for Access 2010. | hOledbDBase5 | OLE DB provider for dBase 5. | hOledbExcel2007 | OLE DB provider for Excel 2007. | hOledbExcel2000 | OLE DB provider for Excel 2000. | hOledbExcel97 | OLE DB provider for Excel 97. | hOledbLotus4 | OLE DB provider for Lotus 4. | hOledbOracle | OLE DB provider for Oracle. | hOledbSQLServer | OLE DB provider for SQL Server |
This parameter can be retrieved and modified using the ..Provider property on a Connection variable.
<Access>: Optional constant Configures the type of access to the database. | | hOReadWrite (default value) | The database can be accessed in read/write. You have the ability to read the records and to write new records. | hORead | The database can be accessed in read-only. You only have the ability to read the records. No record can be added or deleted. | This parameter can be retrieved and modified using the ..Access property on a Connection variable. <Extended information>: Optional character string (with quotes) 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 access or by the OLE DB access used. These keywords must be indicated as follows: "<Keyword> = <Value>;".You can for example specify "Trusted_Connection=YES" in order to use a connection with authentication via the NT login.
<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: - Location of cursors
| | hClientCursor | Cursor managed by MDAC. Offers more features than a server cursor. A client cursor must necessarily be a static cursor. | hServerCursor | Cursor managed by the database. This cursor can easily apply the changes performed by the other users to the data. |
- Type of cursor
| | hDynamicCursor | Cursor offering a lot of features but consuming a lot of memory. This cursor allows all types of moves. It allows you to access all the modifications, additions and deletions performed by the other users. | hForwardOnlyCursor | Fast cursor consuming little memory. The move is performed from the first record to the last one. The data modified by the other users is not visible. | hOpenKeysetCursor | Cursor that handles a fixed set of records. Only the keys corresponding to the record are stored and not the records (consumes less memory). The deleted records can no longer be accessed. Modifications performed by other users are visible (but records added are not). | hStaticCursor | Makes a copy of all query records in memory (consumes a lot of memory). All types of moves are allowed. |
- Lock mode
| | hReadOnlyCursor | The set of records cannot be modified. | hOptimisticCursor | The record is locked when it is updated | hPessimisticCursor | The record is locked as soon as it goes into edit mode to be modified. |
Caution: some types of cursors may not be supported by all the OLE DB providers.This parameter can be retrieved and modified using the ..CursorOptions property.
Remarks Differences between HOpenConnection and HDescribeConnection Method 1: To open a connection at the start of the application and close it at the end, use HOpenConnection. To use this connection when handling files or tables, simply change this connection with HChangeConnection.
HOpenConnection(MyConnection, params) // Open the connection HChangeConnection(AFile, MyConnection)
Method 2: To describe a connection by programming and to automatically open it when the file is opened, you must: - describe the connection with HDescribeConnection
- associate this connection with the relevant file description with HChangeConnection. The connection will be opened the first time the file is accessed.
This solution can be useful when an application is using both HFSQL files and Oracle 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(MyConnection, params) HChangeConnection(AFile, MyConnection) ... HReadFirst(AFile) // Open the connection ... HClose(AFile) // Close the connection
Versions 18 and later New in version 18
This page is also available for…
|
|
|
| |
| 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
|
|
|
|
| |
| |
| |
|
| | https://forum.pcsoft.fr/fr-FR/pcsoft.br.windev/3252-informatica-novo-metodo-create-database-hfsql-client-server-3266/read.awp |
|
|
|
| |
| |
| |
|
| 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
|
|
|
|
| |
| |
| |
|
| In class, let's review the hyperfile connection. |
|
| Aula 1158 WinDev Curso ErpAmarildo 16 - Conexao Hyperfile
Nessa aula de hoje
Na aula de vamos , revisar a conexao hyperfile
In class, let's review the hyperfile connection.
En la clase de vamos, revisar la conexión hyperfile
http://windevdesenvolvimento.blogspot.com.br/2016/06/menu-blog.html
http://windevdesenvolvimento.blogspot.com.br/2015/04/windevwebdevmobile-hyperfile-instalar.html
https://doc.windev.com/en-US/?2028081&name=Hyper_File_CS_server
https://doc.windev.com/en-US/?3044107&name=HOpenConnection
https://doc.windev.com/en-US/?3044095&name=hcloseconnection_function
https://doc.windev.com/en-US/?3044150&name=HChangeConnection
http://windevdesenvolvimento.blogspot.com.br/2017/05/aula-1158-windev-curso-erpamarildo-16.html
https://www.youtube.com/watch?v=B87q726WBr4
|
|
|
|
| |
| |
| |
|
| 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
|
|
|
|
| |
| |
| |
|
| A more "real life" example |
|
| The example lacks the function that actually let´s you open any file in the database, this function is HchangeConnection, so for me the example should be:
MyConnection is Connection // Describe the connection MyConnection..User = "admin" MyConnection..Password = "" MyConnection..Server = "Diego-PC" MyConnection..Database = "Followup" MyConnection..Provider = hAccessHFClientServer MyConnection..Access = hOReadWrite MyConnection..ExtendedInfo = "Extended information" MyConnection..CursorOptions = hClientCursor // Establish the connection HOpenConnection(MyConnection) HChangeConnection("*",MyConnection) <- This line is a must in order to open the files |
|
|
|
| |
| |
| |
| |
| |
| |
| | |
|