Connection to the 4D SQL engine via the ODBC Driver

4D - Documentation   Français   English   German   Japanese   4D SQL Reference, Table of Contents   4D SQL Reference, Index   Back   Previous   Next

version 11


You can connect to the 4D SQL Engine from any external database via the ODBC Driver for 4D v11.

Note: Beginning with version 11.3 of 4D, it is also possible for a 4D application to connect directly to a 4D Server database via SQL. For more information, please refer to the description of the SQL LOGIN command.

Here is a small example demonstrating how to connect a 4D database to another 4D database via the ODBC driver:

1. Duplicate the example database that comes with this tutorial

2. Rename the two folders containing the databases to "Client" and "Server"

3. Launch the example database inside the Server folder and enable the launching of the SQL Server at startup by checking the "Launch SQL Server at Startup" check-box in the application Preferences, on the SQL/Configuration page:

Quit and restart the example database from the Server folder to activate the SQL Server.

4. Install the 4D ODBC Driver for 4D v11, then check whether it appears in the ODBC Data Source Administrator:

5. Create a new data source named "Test_ODBC_Driver_v11"

and test it by pressing the Connection test button:

6. Launch the example database inside the Client folder, go to the main window and press the "Connect to 4D" button. The code behind this button is the following:

As you can see, in the first part of the method we make a query on the local database. Then, in the second part, we connect to the other 4D database via the ODBC driver and make the same query. The result should be the same of course.


4D - Documentation   Français   English   German   Japanese   4D SQL Reference, Table of Contents   4D SQL Reference, Index   Back   Previous   Next