What is the connection String used to make the connection between Cobol and B. D. Oracle?

I cannot connect a Micro Focus Program Cobol to the database Oracle.

I'm using the command:

EXEC SQL
     CONNECT :USERNAME IDENTIFIED BY :PASSWD
END-EXEC

The error that returns me is:

Please specify Database name

I've tried other ways to connect, but I can't connect.

Author: LINQ, 2017-03-27

2 answers

According to the Micro Focus Developer manual, available by clicking here and searching for the term CONNECT, the CONNECT command you are using has the following syntax,

>>---EXEC SQL---CONNECT user--.------------------------.->
                              +-IDENTIFIED BY password-+
                              +-------'/'password------+ 

 >---.--------------.--------.--------------------.------->
     +--AT db_name--+        +--USING data_source-+

 >---.----------------------.----------------------------->
     +--WITH-.----.-PROMPT--+ 
             +-NO-+ 

 >---.-----------------------------.---END-EXEC---><
     +-RETURNING output_connection-+

Where data_source is an ODBC data source, which must be previously configured in Start Menu > Control Panel > Administrative Tools > ODBC data source; and db_name, in the case of SQL Server, is the database to which you want to connect (the case of SQL Server is not explicit in the manual Oracle).

If you want to make direct use of connection strings, use the following syntax,

>>----EXEC SQL---CONNECT USING input_connection---------->

 >-----.-------------.---.---------------------.---------->
       +--AS db_name-+   +--WITH-.----.-PROMPT-+
                                 +-NO-+

 >-----.------------------------------.------END-EXEC---->< 
       +--RETURNING output_connection-+

Where input_connection is Oracle's own connection string, stored in the working-Storage section, in a PIC x(n) field.

An example of conn string for Oracle, taken from here , follows below:

Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort))(CONNECT_DATA=(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;

You may need to include the reserved word DRIVER={nomedodriver}; in the conn string. As it says in the reference, below,

For the driver name, use the name that appears in the left-most column of the drivers tab in the ODBC control panel.

" for the name of the driver, use the name that appears in the leftmost column of the drivers tab in the ODBC control panel."

Reference: https://community.microfocus.com/microfocus/cobol/extend_and_acucobol/w/knowledge_base/3996/can-you-connect-using-the-odbc-interface-without-setting-up-a-datasource

 0
Author: Marcelo Shiniti Uchimura, 2018-06-30 18:48:30

Apologies for machine translation. I welcome the help of the editors (it has been some time since the last time).


COBOL has no strings, in the sense that there is no field with a terminal (such as a null or a new line) that COBOL would interpret as being the end of piece of data.

COBOL has fixed-length fields.

How does Oacle know how long has your user password and password? No.

You need to figure out how Oracle can understand the length of your data.

The first approach is to consult the pro * COBOL (Oracle COBOL) documentation. There you will see a data definition including VARYING for the UserId and password.

VARYING (in this particular context) belongs to Pro * COBOL. It would be considered a language extension for COBOL.

It is not clear which COBOL compiler you are using.

GnuCOBOL has ANYLENGTH, but is not (yet) available for working-STORAGE definitions. Micro Focus COBOL (if you're using one of them) might have ANYLENGTH or something equivalent: if you query the documentation / knowledgebase, I'd expect you can find something.

However, it can be done in any simple COBOL, although you need to calculate the length of the data yourself (it will not be automatic, unlike VARYING and ANYLENGTH).

First, you need to understand how Oracle expects data to get to it from the Pro * COBOL.

What VARYING actually does, can be defined as this:

01 Senha do usuário.
    05 UP-Length COMP-5 PIC 9 (4).
    05 UP-Username PIC X (30).

Oracle expects a "varchar" type. A binary of two bytes (integers) in length, immediatelt before the data.

You MOVE your required userid to UP-Username, then you would work out how many traying blanks there are in the field, subtract that from 30, and put the result in UP-Length. Depending on the COBOL compiler you have, there are more or less ways easy to do that.

You need to do this for all fields of type "varchar".

Without the length before the data, Oracle would have used the first two data characters as a binary integer.


English original:

COBOL does not have "strings", in the sense that there is no field with a terminal (like a null or a newline) which COBOL would interpret as being the end of piece of data.

COBOL has fixed-length fields.

How does Oacle know how long your userid and password are? It doesn't.

You need to find out how Oracle can understand the length of your data.

First approach is to consult the Pro*COBOL (Oracle's COBOL) documentation. There you will see a data-definition including VARYING for the userid and password.

VARYING (in that particular context) belongs to Pro*COBOL. It would be considered a Language Extension for COBOL.

It is not clear which COBOL compiler you are using.

GnuCOBOL does have ANYLENGTH, but it is not (yet) available for WORKING-STORAGE definitions. Micro Focus COBOL (if you happen to be using one of them) may have ANYLENGTH or something equivalent: if you consult their documentation/knowledgebase, I'd expect you may find something.

However, it can be done in any plain COBOL, although you need to work out the length of the data yourself (it will not be automatic, unlike the VARYING and the ANYLENGTH).

First, you need to understand how Oracle expects the data to arrive to it from Pro*COBOL.

What the VARYING actually does, can be defined like this:

01  User-Password.
    05  UP-Length              COMP-5 PIC 9(4).
    05  UP-Username                   PIC X(30).

Oracle expects a "varchar" - type. A two-byte binary (integer) length, immediatelt before the data.

You would MOVE your required userid to UP-Username, then you would work out how many traiing blanks there are in the field, subtract that from 30, and put the result into UP-Length. Depending on which COBOL compiler you have, there are more or less easy ways to do that.

You need to do that for all "varchar"-type fields.

Without the length before the data, Oracle would have used the first two characters of data as a binary integer.

 -1
Author: Bill Woodger, 2017-03-30 16:41:44