Skip to content

05 Database

Gilles Querret edited this page Sep 11, 2024 · 3 revisions
  1. An OpenEdge project without a database connection is almost pointless! We'll configure a connection to a local sports2000 database. Open the project configuration file, and add this line:

    "dbConnections": [
      {
        "name": "sp2k",
        "connect": "-db target/db/sports2000 -ld sp2k -RO",
        "schemaFile": "dump/sports2000.df",
        "aliases": [
          "sports"
        ]
      }
    ]
  2. Restart the language server ; an error will be shown:

  3. Follow these instructions to diagnose the error:

    • Open the .builder/clientlog0.log file.
    • Review the log output to identify the specific error message.

    The log file will clearly state what the error is, allowing you to take the necessary steps to resolve it.

    P-005436 T-001420 1 4GL -- Logging level set to = 1
    P-005436 T-001420 1 4GL APPL           Connecting to DB 'sp2k': '-db target/db/sports2000 -ld sp2k -RO'
    P-005436 T-001420 1 4GL APPL           Unable to connect to 'sp2k'
    P-005436 T-001420 1 4GL APPL           ** Cannot find or open file C:\workshop\Chapter3\target\db\sports2000.db, errno = 2. (43)
    

    This message is expected because the local database has not been created yet.

  4. We can use the integrated Terminal to create the database. Follow these steps:

    • Switch to the Terminal tab in Visual Studio Code.
    • Click on the + button to open a new terminal.
    • Select Proenv from the dropdown menu.

    The proenv environment matching the version number of your project is automatically opened and set to the root directory of the project. An Ant buildfile is available, so you can execute the following command to create a sports2000 database: %DLC%\ant\bin\ant db

  5. Restart the language server, then modify src/test1.p to include a reference to the sports table. Save the file and ensure that it compiles successfully. Hover the cursor over the table name in a FIND or FOR EACH statement to see the full table name and the index used in the query. Code completion should also be active for table names and field names.

ℹ️ Note about the schemaFile attribute: compilation is performed by the AVM, which requires a database connection with the correct database name and aliases. In contrast, code completion is handled by the language server, written in Java, which does not connect to the database. The language server relies solely on dump files for schema information. Therefore, it is a good practice to always include the database schema in your code repository.


Next chapter

Clone this wiki locally