Accessing ODBC data sources from Micro Focus COBOL by using the Server Express OpenESQL Interface
Contents
- Introduction
- unixODBC support in Server Express
- Connecting to an ODBC data source from Micro Focus COBOL
Introduction
OpenESQL 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.
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 with 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 data source 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.
- 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 ODBC-ODBC Bridge 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 ODBC-ODBC Bridge server on a host named mywindowsserver where there is a SQL Server system data source called sqlserversystemdsn. The
LogonUser
andLogonAuth
values are a valid Windows user name and password that can be used to log in to mywindowsserver. TheTargetUser
andTargetAuth
values are a valid SQL Server database login.For information about adding a data source for a different Easysoft ODBC driver, refer to the documentation for your Easysoft ODBC driver.
- Use isql to test the new data source. For example:
cd /usr/local/easysoft/unixODBC/bin ./isql -v testOOB
At the prompt, enter
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'
For more information about OpenESQL and using Embedded SQL in your COBOL applications with ODBC data sources, refer to the Server Express Data Access Manual.
- 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.