Accessing ODBC Databases from Micro Focus COBOL by using the Server Express OpenESQL Interface
- unixODBC Support in Server Express
- Connecting to an ODBC Database from Micro Focus COBOL
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).
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.
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.
- 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":
[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.
- 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.
- 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'
- 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.