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

1

I can not make a connection between a Micro Focus program Cobol and the Oracle database.

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 forms of connection, but I can not connect.

    
asked by anonymous 27.03.2017 / 17:04

2 answers

0

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 preconfigured in Start Menu > Control Panel > Administrative Tools > ODBC Data Source; and db_name , in the case of SQL Server, is the database that you want to connect to (the Oracle case is not explicit in the manual).

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 , follows below:

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

It may be necessary to include the reserved word DRIVER={nomedodriver}; in 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 driver name, use the name that appears in the leftmost column of the drivers tab in the ODBC Control Panel."

Reference: link

    
30.06.2018 / 14:14
-1

Apologies for machine translation. I welcome the editors' help (it's 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 newline) that COBOL would interpret as being the end of piece of data.

COBOL has fixed-length fields.

How does Oacle know how long your user password and password have? 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 settings. Micro Focus COBOL (if you are using one of them) can have ANYLENGTH or something equivalent: if you query the documentation / knowledgebase, I would hope 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 come to it from 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 traiing 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 easy ways to do this.

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

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

Original English:

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 does not.

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 not have ANYLENGTH, but it is (yet) available for WORKING-STORAGE definitions. Micro Focus COBOL (if you happen to be using one of theirs) may have ANYLENGTH or something equivalent: if you consult their documentation / knowledgebase, I'd expect you to 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 date to arrive to it from * COBOL.

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

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

Oracle expects to "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 date, Oracle would have used the first two characters of data as a binary integer.

    
30.03.2017 / 18:41