Accessing ODBC Databases from Micro Focus COBOL by using the Server Express OpenESQL Interface



OpenESQL transparently translates embedded SQL statements into ODBC API calls, making it easy to develop COBOL applications that access different database systems. On Unix platforms, OpenESQL is provided with Micro Focus Server Express.

This article describes how to use the Server Express OpenESQL Interface with an Easysoft ODBC driver. You can then access databases such as Microsoft SQL Server, Microsoft Access, Oracle, DB2, InterBase and Sybase ASE from your COBOL applications. For example, access SQL Server using its Windows ODBC driver from COBOL on Unix by using OpenESQL with the Easysoft ODBC-ODBC Bridge (OOB).

Use OpenESQL with our Oracle, DB2, InterBase, Sybase drivers to access those databases.

To access other databases for which an ODBC driver is available, use the OOB.

unixODBC Support in Server Express

To use ODBC with Server Express, you need an ODBC Driver Manager and ODBC driver. When you execute an SQL Connect statement in your COBOL application, Server Express loads the ODBC Driver Manager which then loads the appropriate ODBC driver based on the contents of your odbc.ini file. Server Express 4.0 is compatible the unixODBC Driver Manager. All Easysoft ODBC driver distributions include the unixODBC Driver Manager and we recommend you install that as part of the Easysoft ODBC driver installation.

Connecting to an ODBC Database from Micro Focus COBOL

Make sure that you choose the Open ESQL option when installing Server Express. For installation instructions, refer to the Server Express product documentation.

If you have not already done so, please register with us to download a fully functional free trial version of the Easysoft ODBC driver for the database you want to access. After you have registered, download the Easysoft driver for your database from the product page for that driver. For installation instructions, see the Easysoft product documentation. You should also to refer to the documentation for information on the necessary environment variables (LD_LIBRARY_PATH, ORACLE_HOME, for example) you need to set for your Easysoft ODBC driver.

The following instructions show how to connect to an ODBC database from your COBOL application.

  1. Create an Easysoft ODBC driver data source in the unixODBC /etc/odbc.ini file and test it with unixODBC’s isql command.

    For example, the following sample data source defines an OOB client data source called "testOOB":

    Driver = OOB
    ServerPort = mywindowsserver:8888
    LogonUser = mywindowsusername
    LogonAuth = mywindowspassword
    TargetDSN = sqlserversystemdsn
    TargetUser = sqlserverusername
    TargetAuth = sqlserverpassword

    The example data source points to an OOB Server on a host named mywindowsserver where there is a SQL Server System data source called sqlserversystemdsn. The LogonUser and LogonAuth values are a valid Windows username and password that can be used to log in to mywindowsserver. The TargetUser and TargetAuth values are a valid SQL Server database login.

    For information about adding a data source for a different Easysoft ODBC driver, see the documentation for your Easysoft ODBC driver.

  2. Use isql to test the new data source. For example:
    cd /usr/local/easysoft/unixODBC/bin
    ./isql -v testOOB

    At the prompt, type "help" to display a list of tables. To exit, press return in an empty prompt line.

  3. To access the database from COBOL, specify the Easysoft ODBC driver data source in a CONNECT statement. For example:
    CONNECT TO 'testOOB' USER 'sqlserverusername.sqlserverpassword'

    For more information about OpenESQL and using Embedded SQL in your COBOL applications with ODBC data sources, see the Server Express Data Access Manual.

  4. Compile the application containing the embedded SQL by specifying either:
    • $set sql(dbman=odbc) in a $SET statement at the start of the program.
    • cob -V program1.cbl -C"SQL(DBMAN==ODBC)" as part of your compile string.

Article Feedback

* Did this content help you?
* Please select one option based on your first choice:

(* Required Fields)