WinDev Tutorial 55: Programmatic HFSQL Classic / Client-Server Connection

Introduction

Hello everyone, and welcome to a new lesson in our WinDev tutorial series! Based on your frequent requests and questions, we are delighted to offer you a practical solution to a common challenge faced by many developers: managing HFSQL database connections, whether in classic or client-server mode, within your WinDev applications. Many struggle to connect their program to a single database across multiple computers within a local network, or to dynamically switch between a local and a server connection. This tutorial is designed to answer all these questions and provide clear programmatic solutions.

What you will learn in this tutorial:

  • Understand the differences between HFSQL Classic and Client-Server connections.
  • How to establish a Classic HFSQL connection programmatically.
  • How to establish an HFSQL Client-Server connection programmatically.
  • Dynamically switch between different connection modes within your WinDev application.
  • Apply these concepts in a local area network environment.

Watch the full tutorial in the video below for a practical demonstration and in-depth explanations.

HFSQL Classic (Local) Connection

The Classic (or local) connection is suitable for single-user applications or when the database is located locally on the same machine as the application. It can also be used in very small local networks where database files are shared directly. Here is the WLangage code to establish a Classic connection:

gcnxConx..Provider = hAccèsHF7
gcnxConx..Source = fRepExe()
HOuvreConnexion(gcnxConx)
HChangeConnexion("*",gcnxConx)

TableAffiche(TABLE_Client)

In this code:

  • gcnxConx is a variable of type Connection.
  • hAccèsHF7 specifies the access provider for HFSQL Classic.
  • fRepExe() returns the path of the execution directory, indicating that the database is located in the same directory or a subdirectory.
  • HOuvreConnexion(gcnxConx) opens the defined connection.
  • HChangeConnexion("*",gcnxConx) changes the default connection for all data files to the new connection.
  • TableAffiche(TABLE_Client) refreshes the display of the TABLE_Client table using the new connection.

HFSQL Client-Server Connection

The Client-Server connection is the preferred method for multi-user applications in a network environment. It offers better performance, enhanced security, and centralized data management. Here is the WLangage code to establish a Client-Server connection:

gcnxConx..Provider = hAccèsHFClientServeur
gcnxConx..Cryptage = hCryptageNon
gcnxConx..BaseDeDonnées = "base_test"
gcnxConx..Serveur = "localhost"
gcnxConx..MotDePasse = ""
gcnxConx..Utilisateur = "admin"
HOuvreConnexion(gcnxConx)
HChangeConnexion("*",gcnxConx)

TableAffiche(TABLE_Client)

In this code:

  • hAccèsHFClientServeur specifies the access provider for HFSQL Client/Server.
  • hCryptageNon indicates no encryption (can be changed based on your security needs).
  • BaseDeDonnées defines the name of the database on the server (e.g., base_test).
  • Serveur specifies the server address (can be localhost for testing, or the server’s IP address / hostname).
  • Utilisateur and MotDePasse are the server login credentials.

Conclusion

Mastering the different methods of connecting to HFSQL databases, whether classic or client-server, is crucial for any WinDev developer. These approaches provide the necessary flexibility to build robust and reliable applications adapted to various deployment environments. We hope this tutorial has provided you with clear insights and practical solutions. Feel free to apply these codes and adapt them to your own projects.

To watch the full explanation of this tutorial, you can follow the video below:

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *