ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / Managing databases / HFSQL / HFSQL functions
  • Example 1: Describing a connection on SQL Server via OLE DB
  • Example 2: Describing a connection on SQL Server by ODBC via OLE DB
  • Example 3: Describing a connection on HFSQL Classic files
HChangeConnection (Example)
Example 1: Describing a connection on SQL Server via OLE DB
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)AjaxOLE DB In this example, the company database is on Oracle. The programmer wants to run the test of his program on an SQL Server database.
In the analysis, an OLEDB connection was associated with the "Salaries" OLE DB table on Oracle.
The properties of this connection are:
  • datasource: Server_Oracle
  • user: smith
  • password: toto
  • provider: OraOLEDB.Oracle
The new connection to the SQL Server database will have the following parameters:
  • datasource: "Server_SQLServer"
  • database: "dbo"
  • user: ""
  • password: ""
  • provider: "SQLOLEDB"
Note: On SQL Server, you can define a database internal to the data source that the server is.
// Describe the new connection
HDescribeConnection("MyConnection", "", "", ...
"Server_SQLServer", "dbo", hOledbSQLServer, hOReadWrite, "")
 
// Establish the new connection
HOpenConnection("MyConnection")
 
// Specify that "Salaries" uses the new connection
HChangeConnection("Salaries", "MyConnection")
 
// Start looping through the "Salaries" table on SQLServer
HReadFirst("Salaries")
...
// Close the connection
HCloseConnection("Salaries")
 
// Restore the use of connection on Oracle
HChangeConnection("Salaries", "")
 
// Open the "Salaries" table on Oracle
HOpen("Salaries")
Example 2: Describing a connection on SQL Server by ODBC via OLE DB
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)AjaxOLE DB The company database is on Oracle. The programmer wants to runt the test of his program on an SQL Server database by using the ODBC access via OLE DB.
Without modifying the analysis, you have the ability to change the connection used by the file.
Remark: "ODBCSQLServer" is an ODBC data source declared in the ODBC data sources of Windows
// Describe the new connection
HDescribeConnection("MyConnection", "", "", ...
"Server_SQLServer", "dbo", hOledbSQLServer, hOReadWrite, "")
// Establish the new connection
HOpenConnection("MyConnection")
// Specify that "Salaries" uses the new connection
HChangeConnection("Salaries", "MyConnection")
// Start looping through the "Salaries" table on SQLServer
HReadFirst("Salaries")
...
// Close the connection
HCloseConnection("Salaries")
// Restore the use of connection on Oracle
HChangeConnection("Salaries", "")
// Open the "Salaries" table on Oracle
HOpen("Salaries")
Example 3: Describing a connection on HFSQL Classic files
WINDEVWEBDEV - Server codeReports and QueriesUser code (UMC)AjaxHyper File 5.5OLE DB The company database is on Oracle. The developer wants to run the tests of his program on HFSQL Classic data files.
Without modifying the analysis, you have the ability to change the connection used by the file.
In the analysis, an OLEDB connection was associated with the "Salaries" OLE DB table on Oracle.
The properties of this connection are:
  • datasource: Server_Oracle
  • user: smith
  • password: toto
  • provider: OraOLEDB.Oracle
The new pseudo-connection (using an HFSQL Classic database) will have the following parameters:
  • datasource: "c:\tmp"
  • database: ""
  • user: ""
  • password: ""
  • provider: hAccessHF7
// Describe the new connection
HDescribeConnection ("MyConnection", "", "", "c:\tmp", "", ...
hAccessHF7, hOReadWrite, "")
// Specify that "Salaries" uses the new connection
HChangeConnection("Salaries", "MyConnection")
// Start looping through the "Salaries" table on SQLServer
HReadFirst("Salaries")
...
// Close the file
HClose("Salaries")
...
// Restore the use of connection on Oracle
HChangeConnection("Salaries", "")
// Open the "Salaries" table on Oracle
HOpen("Salaries")
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help