The class lists all predefined DB connections that are defined in the IDE in the “Connections” project folder. You must include the gb.desktop component in your project if you want to ensure that the password entered via the IDE for the defined DB connection is automatically retrieved. Otherwise, you must provide the password for MySQL and PostgreSQL yourself!
The Connections class has two properties:
Property | Data type | Description |
---|---|---|
Count | Integer | Delivers the number of DB connections defined in the project. |
Key | String | Delivers the key of the last enumerated predefined DB connection. |
Table 22.4.2.1.1 : Properties of the Connections class
A predefined DB connection is one that has been defined in the IDE via the context menu> Connections> New connection in the project browser. This creates a text file in the hidden.connection directory of the project that can be accessed by the runtime environment.
The Connections class has these two methods:
Method | Return type | Description |
---|---|---|
Create(Name As String) | Connection | Returns a DB connection object defined in the IDE and initialises it. `Name` is the name of the DB connection defined in the IDE. The database defined by the DB connection object is created if it does not exist. The database tables and database indices are created and initialised from the internal template description of the DB connection. |
Exist(Name As String) | Boolean | Returns TRUE if a specific predefined connection exists. `Name` is the name of the DB connection defined in the IDE. |
Table 22.4.2.2.1 : Methods of the Connections class
The following source code provides an enumeration of all predefined DB connection objects:
Dim hConnection As Connection For Each hConnection In Connections ... Next
This source code section provides a predefined DB connection by name:
Dim hOneConnection As Connection hOneConnection = Connections [ Name As String ]
This opens a predefined DB connection and closes it at the end of the programme:
Public Sub Form_Open() If Not Connections["Connection1"].Opened Then Try Connections["Connection1"].Open() If Error Then Message.Error("Unable to connect to the database") Me.Close() Endif End Public Sub Form_Close() Connections["Connection1"].Close() End