PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Example 1: Describing a connection on SQL Server via Native Access
  • Example 2: Describing a connection on SQL Server via OLE DB
  • Example 3: Describing a connection on SQL Server via OLE DB
  • Example 4: Describing an Access connection
HOpenConnection (Example)
Example 1: Describing a connection on SQL Server via Native Access
WINDEVWEBDEV - Server codeReports and QueriesAjaxUser code (UMC)HFSQLHFSQL Client/ServerOLE DBNative Connectors (Native Accesses)
// Open a SQL Server connection
HOpenConnection("MyConnection", "User", "Password", ...
"Server_SQLServer", "dbo", hNativeAccessSQLServer, hOReadWrite)

// Open a SQL Server connection with Windows authentication
HOpenConnection("MyConnection", Null, Null, "Server_SQLServer", "dbo", ...
hNativeAccessSQLServer, hOReadWrite, "Trusted_Connection=YES")
Example 2: Describing a connection on SQL Server via OLE DB
WINDEVWEBDEV - Server codeReports and QueriesAjaxUser code (UMC)OLE DB
In this example, the company database is on Oracle. The programmer wants to run the test of his program on a 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" is using the new connection
HChangeConnection("Salaries", "MyConnection")
// Start browsing the "Salaries" table on SQL Server
HReadFirst("Salaries")
...
// Closes the file: the connection used by the "Salaries" file
// was opened by HOpenConnection. It will not be closed
// when closing the Salaries file.
HClose("Salaries")
...
// Fast re-opening because the connection is still opened
HOpen("Salaries")

// Close the connection
HCloseConnection("MyConnection")

// Restore the use of connection on Oracle
HChangeConnection("Salaries", "")

// Open the "Salaries" table on Oracle
HOpen("Salaries")
Example 3: Describing a connection on SQL Server via OLE DB
WINDEVWEBDEV - Server codeReports and QueriesWindowsAjaxUser code (UMC)OLE DB
The company database is on Oracle. The programmer wants to run the test of his program on a SQL Server database by using the ODBC access
Without modifying the analysis, you have the ability to change the connection used by the file.
Note: "ODBCSQLServer" is an ODBC data source declared in the ODBC data sources of Windows
// Describe and open the new connection
HDescribeConnection("MyConnection", "", "", "Server_SQLServer", ...
"dbo", hODBC, hOReadWrite, "")
HOpenConnection("MyConnection")

// Specify that "Salaries" is using the new connection
HChangeConnection("Salaries", "MyConnection")

// Start browsing the "Salaries" table on SQLServer
HReadFirst("Salaries")
...

// Close the connection
HCloseConnection("MyConnection")

// Restore the use of connection on Oracle
HChangeConnection("Salaries", "")
// Open the "Salaries" table on Oracle
HOpen("Salaries")
Example 4: Describing an Access connection
WINDEVWEBDEV - Server codeReports and QueriesWindowsAjaxUser code (UMC)OLE DB
This example is used to establish a connection to the database of signatures by using the OLE DB Access 2000 access.
Signatures is Data Source


// Establish the connection to the database of signatures
IF NOT HDescribeConnection("ConnectionSignatures", "", "", "Signatures.mdb", "", ...
hOledbAccess2000, hOReadWrite) THEN
Error(HErrorInfo())
RESULT False
ELSE
IF NOT HOpenConnection("ConnectionSignatures") THEN
Error(HErrorInfo())
RESULT False
ELSE
...

END
END
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment