A NEW TODAY IS DAWNING!

Tutorial: Connecting to Databases in 8.03


Introduction

There is new functionality to handle rdbms logins that are more consistent across different databases and provide greater programmatic control.

The external name of the Database defintion is used to connect to the database. The ideal solution is to use a environment variable so that the database to be used is configurable prior to and at runtime.


Required Changes

In the BuildProfessional Database component definition related to the table, change the external database name to:

*ENV("DBConnect")

This variable needs to be populated prior to accessing the database. It should contain the complete connect string (for Oracle "user/password[@database]").


ORACLE

In the case of fbuild (i.e. running from the command line) setup DBConnect in the environment:

DBConnect=scott/tiger
export DBConnect
fbuild –uguest –aappn -ffile –m3

In the case of runtime, you can either setup the connect string in the environment or preferably at runtime in code:

L-user = "scott"
L-password = "tiger"
L-oracleserver = "MYDATA"
*ENV("DBConnect") = *TRIM(L-user) "/" *TRIM(L-password)
IF L-oracleserver <> "" THEN
*ENV("DBConnect") = *ENV("DBConnect") "@" L-oracleserver
ENDIF
SQL login database

This method allows you to read the user, password and server from configuration files.

Note 1. The connect string is the same as used in sqlplus. This should work:

$ sqlplus $DBConnect

Note 2. Examples of connect strings are:

scott/tiger
scott/tiger@MYDATA
scott/tiger@mydata.hostname.domain
ops$steven/mypassword


SQL Server

Same as for Oracle, except the connect string has the following syntax:

hostname/database/user/password

or

odbcsource

where odbcsource is an ODBC source defined on the local machine.

Example:

*ENV("DBConnect") = "myodbc"
SQL login database

Note. DBConnect is used in the above examples. It can be any environment variable name.