Implicit database connection

An implicit database connection is made with the DATABASE instruction used before MAIN; use SCHEMA to avoid the implicit connection.

The DATABASE statement can be used in two distinct ways, depending on the context of the statement within its source module:

A default database is almost always used, because many programs contain DEFINE ... LIKE statements. A problem occurs when the production database name differs from the development database name, because the default database specification will result in an automatic connection (just after MAIN):
DATABASE stock_dev  -- Default database, used at compile time
DEFINE
   p_cust RECORD LIKE customer.*
MAIN -- Connection to default database occurs at MAIN
   DEFINE dbname CHAR(30)
   LET dbname = "stock1"
   DATABASE dbname -- Real database used in production
   ...
END MAIN
In order to avoid the implicit connection, you can use the SCHEMA instruction instead of DATABASE:
SCHEMA stock_dev -- Schema specification only
DEFINE
   p_cust RECORD LIKE customer.*
MAIN -- No default connection occurs...
   DEFINE dbname CHAR(30)
   LET dbname = "stock1"
   DATABASE dbname
END MAIN

This instruction will define the database schema for compilation only, and will not make an implicit connection at runtime.